Class: Holivia::Commands::Slide

Inherits:
Base
  • Object
show all
Defined in:
lib/holivia/commands/slide.rb

Constant Summary collapse

BASE_PATH =
"/api/v1/backoffice/slides"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.route(args) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/holivia/commands/slide.rb', line 10

def self.route(args)
  subcommand = args.shift
  case subcommand
  when "create" then new.create(args)
  when "update" then new.update(args)
  else warn "Unknown selfcare slide command: #{subcommand}"
       exit 1
  end
end

Instance Method Details

#create(args = []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/holivia/commands/slide.rb', line 20

def create(args = [])
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare slide create [options]"
    opts.on("--content-format-id ID", Integer) { |v| options[:content_format_id] = v }
    opts.on("--title TITLE") { |v| options[:title] = v }
    opts.on("--duration DURATION", Integer) { |v| options[:duration] = v }
  end.parse!(args)
  options = options.merge(piped_json)

  abort "No options provided. Use --help for usage." if options.empty?
  output(client.post(BASE_PATH, body: options))
end

#update(args = []) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/holivia/commands/slide.rb', line 34

def update(args = [])
  id = args.shift
  abort "Usage: holivia selfcare slide update <id> [options]" unless id

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare slide update <id> [options]"
    opts.on("--title TITLE") { |v| options[:title] = v }
    opts.on("--duration DURATION", Integer) { |v| options[:duration] = v }
  end.parse!(args)
  options = options.merge(piped_json)

  abort "No options provided. Use --help for usage." if options.empty?
  output(client.patch("#{BASE_PATH}/#{id}", body: options))
end