Class: Holivia::Commands::Item

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

Constant Summary collapse

BASE_PATH =
"/api/v1/backoffice/slide_items"
MIME_TYPES =
{
  ".mp3" => "audio/mpeg",
  ".mp4" => "audio/mp4",
  ".wav" => "audio/wav",
  ".ogg" => "audio/ogg",
  ".flac" => "audio/flac",
  ".aac" => "audio/aac",
  ".m4a" => "audio/mp4",
  ".webm" => "audio/webm"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.route(args) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/holivia/commands/item.rb', line 20

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 item command: #{subcommand}"
       exit 1
  end
end

Instance Method Details

#create(args = []) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/holivia/commands/item.rb', line 30

def create(args = []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare item create [options]"
    opts.on("--slide-id ID", Integer) { |v| options[:slide_id] = v }
    opts.on("--item-type TYPE") { |v| options[:item_type] = v }
    # RichTextItem
    opts.on("--content CONTENT") { |v| options[:content] = v }
    # VideoItem
    opts.on("--url URL") { |v| options[:url] = v }
    # WistiaItem
    opts.on("--code CODE") { |v| options[:code] = v }
    # QuizItem
    opts.on("--form-url URL") { |v| options[:form_url] = v }
    opts.on("--score-threshold N", Integer) { |v| options[:score_threshold] = v }
    opts.on("--total-score N", Integer) { |v| options[:total_score] = v }
    # MeditationItem / BreathingItem
    opts.on("--title TITLE") { |v| options[:title] = v }
    opts.on("--duration DURATION", Integer) { |v| options[:duration] = v }
    opts.on("--subtitle SUBTITLE") { |v| options[:subtitle] = v }
    # BreathingItem
    opts.on("--cycles N", Integer) { |v| options[:cycles] = v }
    opts.on("--start-delay N", Integer) { |v| options[:start_delay] = v }
    opts.on("--sequence SEQUENCE") { |v| options[:sequence] = JSON.parse(v) }
    # Audio file upload
    opts.on("--audio FILE") { |v| options[:audio] = 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: build_body(options)))
end

#update(args = []) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/holivia/commands/item.rb', line 63

def update(args = []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  id = args.shift
  abort "Usage: holivia selfcare item update <id> [options]" unless id

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare item update <id> [options]"
    opts.on("--item-type TYPE") { |v| options[:item_type] = v }
    opts.on("--content CONTENT") { |v| options[:content] = v }
    opts.on("--url URL") { |v| options[:url] = v }
    opts.on("--code CODE") { |v| options[:code] = v }
    opts.on("--form-url URL") { |v| options[:form_url] = v }
    opts.on("--score-threshold N", Integer) { |v| options[:score_threshold] = v }
    opts.on("--total-score N", Integer) { |v| options[:total_score] = v }
    opts.on("--title TITLE") { |v| options[:title] = v }
    opts.on("--duration DURATION", Integer) { |v| options[:duration] = v }
    opts.on("--subtitle SUBTITLE") { |v| options[:subtitle] = v }
    opts.on("--cycles N", Integer) { |v| options[:cycles] = v }
    opts.on("--start-delay N", Integer) { |v| options[:start_delay] = v }
    opts.on("--sequence SEQUENCE") { |v| options[:sequence] = JSON.parse(v) }
    opts.on("--audio FILE") { |v| options[:audio] = 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: build_body(options)))
end