Class: Holivia::Commands::InterventionItem
- Defined in:
- lib/holivia/commands/intervention_item.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- BASE_PATH =
"/api/v1/backoffice/intervention_items"- IMAGE_MIME_TYPES =
{ ".gif" => "image/gif", ".jpeg" => "image/jpeg", ".jpg" => "image/jpeg", ".png" => "image/png", ".webp" => "image/webp" }.freeze
Class Method Summary collapse
-
.route(args) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength.
Instance Method Summary collapse
- #create(args = []) ⇒ Object
- #delete(args = []) ⇒ Object
-
#index(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #publish(args = []) ⇒ Object
- #schema(_args = []) ⇒ Object
- #show(args = []) ⇒ Object
- #unpublish(args = []) ⇒ Object
- #update(args = []) ⇒ Object
Class Method Details
.route(args) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/holivia/commands/intervention_item.rb', line 17 def self.route(args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength subcommand = args.shift case subcommand when "index" then new.index(args) when "schema" then new.schema(args) when "show" then new.show(args) when "create" then new.create(args) when "update" then new.update(args) when "publish" then new.publish(args) when "unpublish" then new.unpublish(args) when "delete" then new.delete(args) else warn "Unknown intervention command: #{subcommand}" exit 1 end end |
Instance Method Details
#create(args = []) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/holivia/commands/intervention_item.rb', line 61 def create(args = []) = {} OptionParser.new do |opts| opts. = "Usage: holivia intervention create [options]" (opts, ) end.parse!(args) = .merge(piped_json) abort "No options provided. Use --help for usage." if .empty? output(client.post(BASE_PATH, body: build_body())) end |
#delete(args = []) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/holivia/commands/intervention_item.rb', line 96 def delete(args = []) id = args.shift abort "Usage: holivia intervention delete <id>" unless id client.delete("#{BASE_PATH}/#{id}") output(deleted: true, id: id.to_i) end |
#index(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/holivia/commands/intervention_item.rb', line 33 def index(args = []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength params = {} OptionParser.new do |opts| opts. = "Usage: holivia intervention index [options]" opts.on("--page N", Integer) { |v| params[:page] = v } opts.on("--per-page N", Integer) { |v| params[:per_page] = v } opts.on("--query TEXT") { |v| params[:query] = v } opts.on("--locale LOCALE") { |v| params[:locale] = v } opts.on("--state STATE") { |v| params[:state] = v } opts.on("--category CATEGORY") { |v| params[:category] = v } opts.on("--translation-group-id UUID") { |v| params[:translation_group_id] = v } opts.on("--intervention-type TYPE") { |v| params[:intervention_type] = v } end.parse!(args) output(client.get(BASE_PATH, params: params)) end |
#publish(args = []) ⇒ Object
88 89 90 |
# File 'lib/holivia/commands/intervention_item.rb', line 88 def publish(args = []) transition(args, "publish") end |
#schema(_args = []) ⇒ Object
50 51 52 |
# File 'lib/holivia/commands/intervention_item.rb', line 50 def schema(_args = []) output(client.get("#{BASE_PATH}/schema")) end |
#show(args = []) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/holivia/commands/intervention_item.rb', line 54 def show(args = []) id = args.shift abort "Usage: holivia intervention show <id>" unless id output(client.get("#{BASE_PATH}/#{id}")) end |
#unpublish(args = []) ⇒ Object
92 93 94 |
# File 'lib/holivia/commands/intervention_item.rb', line 92 def unpublish(args = []) transition(args, "unpublish") end |
#update(args = []) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/holivia/commands/intervention_item.rb', line 73 def update(args = []) id = args.shift abort "Usage: holivia intervention update <id> [options]" unless id = {} OptionParser.new do |opts| opts. = "Usage: holivia intervention update <id> [options]" (opts, ) end.parse!(args) = .merge(piped_json) abort "No options provided. Use --help for usage." if .empty? output(client.patch("#{BASE_PATH}/#{id}", body: build_body())) end |