Class: Holivia::Commands::CommunicationItem
- Defined in:
- lib/holivia/commands/communication_item.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- BASE_PATH =
"/api/v1/backoffice/communication_items"- CONTENT_TYPE_BY_EXTENSION =
{ ".gif" => "image/gif", ".jpeg" => "image/jpeg", ".jpg" => "image/jpeg", ".mov" => "video/quicktime", ".mp4" => "video/mp4", ".pdf" => "application/pdf", ".png" => "image/png", ".ppt" => "application/vnd.ms-powerpoint", ".pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", ".webm" => "video/webm", ".webp" => "image/webp", ".zip" => "application/zip" }.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.
- #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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/holivia/commands/communication_item.rb', line 24 def self.route(args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength 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 "publish" then new.publish(args) when "unpublish" then new.unpublish(args) when "delete" then new.delete(args) when "schema" then new.schema(args) else warn "Unknown communication 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/communication_item.rb', line 61 def create(args = []) = {} OptionParser.new do |opts| opts. = "Usage: holivia communication 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/communication_item.rb', line 96 def delete(args = []) id = args.shift abort "Usage: holivia communication delete <id>" unless id client.delete("#{BASE_PATH}/#{id}") output(deleted: true, id: id.to_i) end |
#index(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/holivia/commands/communication_item.rb', line 40 def index(args = []) # rubocop:disable Metrics/AbcSize params = {} OptionParser.new do |opts| opts. = "Usage: holivia communication 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("--document-type TYPE") { |v| params[:document_type] = v } end.parse!(args) output(client.get(BASE_PATH, params: params)) end |
#publish(args = []) ⇒ Object
88 89 90 |
# File 'lib/holivia/commands/communication_item.rb', line 88 def publish(args = []) transition(args, "publish") end |
#schema(_args = []) ⇒ Object
104 105 106 |
# File 'lib/holivia/commands/communication_item.rb', line 104 def schema(_args = []) output(client.get("#{BASE_PATH}/schema")) end |
#show(args = []) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/holivia/commands/communication_item.rb', line 54 def show(args = []) id = args.shift abort "Usage: holivia communication show <id>" unless id output(client.get("#{BASE_PATH}/#{id}")) end |
#unpublish(args = []) ⇒ Object
92 93 94 |
# File 'lib/holivia/commands/communication_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/communication_item.rb', line 73 def update(args = []) id = args.shift abort "Usage: holivia communication update <id> [options]" unless id = {} OptionParser.new do |opts| opts. = "Usage: holivia communication 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 |