Class: Holivia::Commands::CollectiveIntervention

Inherits:
Base
  • Object
show all
Defined in:
lib/holivia/commands/collective_intervention.rb

Constant Summary collapse

BASE_PATH =
"/api/v1/backoffice/collective_interventions"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.route(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/holivia/commands/collective_intervention.rb', line 10

def self.route(args)
  subcommand = args.shift
  case subcommand
  when "index" then new.index(args)
  when "show" then new.show(args)
  when "create" then new.create(args)
  when "update" then new.update(args)
  when "delete" then new.delete(args)
  else warn "Unknown collective intervention command: #{subcommand}"
       exit 1
  end
end

Instance Method Details

#create(args = []) ⇒ Object



43
44
45
46
47
48
# File 'lib/holivia/commands/collective_intervention.rb', line 43

def create(args = [])
  options = parse_write_options(args, "Usage: holivia collective-intervention create [options]")
  abort "No options provided. Use --help for usage." if options.empty?

  output(client.post(BASE_PATH, body: options))
end

#delete(args = []) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/holivia/commands/collective_intervention.rb', line 60

def delete(args = [])
  id = args.shift
  abort "Usage: holivia collective-intervention delete <id>" unless id

  client.delete("#{BASE_PATH}/#{id}")
  output(deleted: true, id: id.to_i)
end

#index(args = []) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/holivia/commands/collective_intervention.rb', line 23

def index(args = [])
  params = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia collective-intervention index [options]"
    opts.on("--enterprise-id ID", Integer) { |v| params[:enterprise_id] = v }
    opts.on("--status STATUS") { |v| params[:status] = v }
    opts.on("--page N", Integer) { |v| params[:page] = v }
    opts.on("--per-page N", Integer) { |v| params[:per_page] = v }
  end.parse!(args)

  output(client.get(BASE_PATH, params: params))
end

#show(args = []) ⇒ Object



36
37
38
39
40
41
# File 'lib/holivia/commands/collective_intervention.rb', line 36

def show(args = [])
  id = args.shift
  abort "Usage: holivia collective-intervention show <id>" unless id

  output(client.get("#{BASE_PATH}/#{id}"))
end

#update(args = []) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/holivia/commands/collective_intervention.rb', line 50

def update(args = [])
  id = args.shift
  abort "Usage: holivia collective-intervention update <id> [options]" unless id

  options = parse_write_options(args, "Usage: holivia collective-intervention update <id> [options]")
  abort "No options provided. Use --help for usage." if options.empty?

  output(client.patch("#{BASE_PATH}/#{id}", body: options))
end