Class: Holivia::Commands::HrHomeHighlight
- Defined in:
- lib/holivia/commands/hr_home_highlight.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- BASE_PATH =
"/api/v1/backoffice/hr_home_highlights"- 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/hr_home_highlight.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 highlight command: #{subcommand}" exit 1 end end |
Instance Method Details
#create(args = []) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 62 def create(args = []) = {} OptionParser.new do |opts| opts. = "Usage: holivia highlight 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
97 98 99 100 101 102 103 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 97 def delete(args = []) id = args.shift abort "Usage: holivia highlight 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 53 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 40 def index(args = []) # rubocop:disable Metrics/AbcSize params = {} OptionParser.new do |opts| opts. = "Usage: holivia highlight 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("--highlight-type TYPE") { |v| params[:highlight_type] = v } opts.on("--state STATE") { |v| params[:state] = v } end.parse!(args) output(client.get(BASE_PATH, params: params)) end |
#publish(args = []) ⇒ Object
89 90 91 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 89 def publish(args = []) transition(args, "publish") end |
#schema(_args = []) ⇒ Object
105 106 107 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 105 def schema(_args = []) output(client.get("#{BASE_PATH}/schema")) end |
#show(args = []) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 55 def show(args = []) id = args.shift abort "Usage: holivia highlight show <id>" unless id output(client.get("#{BASE_PATH}/#{id}")) end |
#unpublish(args = []) ⇒ Object
93 94 95 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 93 def unpublish(args = []) transition(args, "unpublish") end |
#update(args = []) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/holivia/commands/hr_home_highlight.rb', line 74 def update(args = []) id = args.shift abort "Usage: holivia highlight update <id> [options]" unless id = {} OptionParser.new do |opts| opts. = "Usage: holivia highlight 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 |