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