Class: Holivia::Commands::Crisis
- Defined in:
- lib/holivia/commands/crisis.rb
Constant Summary collapse
- BASE_PATH =
"/api/v1/backoffice/crises"
Class Method Summary collapse
Instance Method Summary collapse
- #create(args = []) ⇒ Object
- #delete(args = []) ⇒ Object
- #index(args = []) ⇒ Object
- #show(args = []) ⇒ Object
- #update(args = []) ⇒ Object
Class Method Details
.route(args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/holivia/commands/crisis.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 crisis command: #{subcommand}" exit 1 end end |
Instance Method Details
#create(args = []) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/holivia/commands/crisis.rb', line 43 def create(args = []) = (args, "Usage: holivia crisis create [options]") abort "No options provided. Use --help for usage." if .empty? output(client.post(BASE_PATH, body: )) end |
#delete(args = []) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/holivia/commands/crisis.rb', line 60 def delete(args = []) id = args.shift abort "Usage: holivia crisis 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/crisis.rb', line 23 def index(args = []) params = {} OptionParser.new do |opts| opts. = "Usage: holivia crisis 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/crisis.rb', line 36 def show(args = []) id = args.shift abort "Usage: holivia crisis 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/crisis.rb', line 50 def update(args = []) id = args.shift abort "Usage: holivia crisis update <id> [options]" unless id = (args, "Usage: holivia crisis update <id> [options]") abort "No options provided. Use --help for usage." if .empty? output(client.patch("#{BASE_PATH}/#{id}", body: )) end |