Class: Holivia::Commands::InterventionItem

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

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

BASE_PATH =
"/api/v1/backoffice/intervention_items"
IMAGE_MIME_TYPES =
{
  ".gif" => "image/gif",
  ".jpeg" => "image/jpeg",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".webp" => "image/webp"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.route(args) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/holivia/commands/intervention_item.rb', line 17

def self.route(args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
  subcommand = args.shift
  case subcommand
  when "index" then new.index(args)
  when "schema" then new.schema(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)
  else warn "Unknown intervention 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/intervention_item.rb', line 62

def create(args = [])
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia intervention create [options]"
    add_write_options(opts, options)
  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

#delete(args = []) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/holivia/commands/intervention_item.rb', line 97

def delete(args = [])
  id = args.shift
  abort "Usage: holivia intervention delete <id>" unless id

  client.delete("#{BASE_PATH}/#{id}")
  output(deleted: true, id: id.to_i)
end

#index(args = []) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



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

def index(args = []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  params = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia intervention 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("--provider PROVIDER") { |v| params[:provider] = v }
    opts.on("--state STATE") { |v| params[:state] = v }
    opts.on("--category CATEGORY") { |v| params[:category] = v }
    opts.on("--translation-group-id UUID") { |v| params[:translation_group_id] = v }
    opts.on("--intervention-type TYPE") { |v| params[:intervention_type] = v }
  end.parse!(args)

  output(client.get(BASE_PATH, params: params))
end

#publish(args = []) ⇒ Object



89
90
91
# File 'lib/holivia/commands/intervention_item.rb', line 89

def publish(args = [])
  transition(args, "publish")
end

#schema(_args = []) ⇒ Object



51
52
53
# File 'lib/holivia/commands/intervention_item.rb', line 51

def schema(_args = [])
  output(client.get("#{BASE_PATH}/schema"))
end

#show(args = []) ⇒ Object



55
56
57
58
59
60
# File 'lib/holivia/commands/intervention_item.rb', line 55

def show(args = [])
  id = args.shift
  abort "Usage: holivia intervention show <id>" unless id

  output(client.get("#{BASE_PATH}/#{id}"))
end

#unpublish(args = []) ⇒ Object



93
94
95
# File 'lib/holivia/commands/intervention_item.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/intervention_item.rb', line 74

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

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia intervention update <id> [options]"
    add_write_options(opts, options)
  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