Class: Holivia::Commands::Selfcare
- Defined in:
- lib/holivia/commands/selfcare.rb
Constant Summary collapse
- BASE_PATH =
"/api/v1/backoffice/selfcare_contents"- COMPOSE_EXAMPLE_PATH =
Holivia.root.join("examples", "compose.json").to_s
- IMAGE_MIME_TYPES =
{ ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".webp" => "image/webp", ".gif" => "image/gif" }.freeze
Class Method Summary collapse
-
.route(args) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/AbcSize.
Instance Method Summary collapse
-
#compose(args = []) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#create(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #index(_args = []) ⇒ Object
- #schema(_args = []) ⇒ Object
- #show(args = []) ⇒ Object
-
#update(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
Class Method Details
.route(args) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/holivia/commands/selfcare.rb', line 19 def self.route(args) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/AbcSize 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 "compose" then new.compose(args) when "schema" then new.schema(args) when "format" then Format.route(args) when "slide" then Slide.route(args) when "item" then Item.route(args) when "objective" then SelfcareObjective.route(args) else warn "Unknown selfcare command: #{subcommand}" exit 1 end end |
Instance Method Details
#compose(args = []) ⇒ Object
rubocop:disable Metrics/MethodLength
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/holivia/commands/selfcare.rb', line 87 def compose(args = []) # rubocop:disable Metrics/MethodLength show_example = false = {} OptionParser.new do |opts| opts. = "Usage: holivia selfcare compose --file <path>" opts.on("--file FILE") { |v| = JSON.parse(File.read(v), symbolize_names: true) } opts.on("--example", "Print a valid compose JSON template") { show_example = true } end.parse!(args) if show_example puts File.read(COMPOSE_EXAMPLE_PATH) return end = .merge(piped_json) abort "Usage: holivia selfcare compose --file <path>" if .empty? output(client.post("#{BASE_PATH}/compose", body: )) end |
#create(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/holivia/commands/selfcare.rb', line 48 def create(args = []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength = {} OptionParser.new do |opts| opts. = "Usage: holivia selfcare create [options]" opts.on("--title TITLE") { |v| [:title] = v } opts.on("--locale LOCALE") { |v| [:locale] = v } opts.on("--content-type TYPE") { |v| [:content_type] = v } opts.on("--duration DURATION", Integer) { |v| [:duration] = v } opts.on("--description DESC") { |v| [:description] = v } opts.on("--image FILE") { |v| [:image] = v } opts.on("--state STATE") { |v| [:state] = v } 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 |
#index(_args = []) ⇒ Object
37 38 39 |
# File 'lib/holivia/commands/selfcare.rb', line 37 def index(_args = []) output(client.get(BASE_PATH)) end |
#schema(_args = []) ⇒ Object
106 107 108 |
# File 'lib/holivia/commands/selfcare.rb', line 106 def schema(_args = []) output(client.get("#{BASE_PATH}/schema")) end |
#show(args = []) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/holivia/commands/selfcare.rb', line 41 def show(args = []) id = args.shift abort "Usage: holivia selfcare show <id>" unless id output(client.get("#{BASE_PATH}/#{id}")) end |
#update(args = []) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/holivia/commands/selfcare.rb', line 66 def update(args = []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength id = args.shift abort "Usage: holivia selfcare update <id> [options]" unless id = {} OptionParser.new do |opts| opts. = "Usage: holivia selfcare update <id> [options]" opts.on("--title TITLE") { |v| [:title] = v } opts.on("--locale LOCALE") { |v| [:locale] = v } opts.on("--content-type TYPE") { |v| [:content_type] = v } opts.on("--duration DURATION", Integer) { |v| [:duration] = v } opts.on("--description DESC") { |v| [:description] = v } opts.on("--image FILE") { |v| [:image] = v } opts.on("--state STATE") { |v| [:state] = v } 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 |