Class: Holivia::Commands::SelfcareObjective

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

Constant Summary collapse

BASE_PATH =
"/api/v1/backoffice/selfcare_content_objectives"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.route(args) ⇒ Object



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

def self.route(args)
  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 "delete" then new.delete(args)
  else warn "Unknown selfcare objective command: #{subcommand}"
       exit 1
  end
end

Instance Method Details

#create(args = []) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/holivia/commands/selfcare_objective.rb', line 43

def create(args = [])
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare objective create [options]"
    opts.on("--selfcare-content-id ID", Integer) { |v| options[:selfcare_content_id] = v }
    opts.on("--objective-id ID", Integer) { |v| options[:objective_id] = v }
    opts.on("--tier TIER") { |v| options[:tier] = 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

#delete(args = []) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/holivia/commands/selfcare_objective.rb', line 72

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

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

#index(args = []) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/holivia/commands/selfcare_objective.rb', line 23

def index(args = [])
  params = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare objective index [options]"
    opts.on("--page N", Integer) { |v| params[:page] = v }
    opts.on("--per-page N", Integer) { |v| params[:per_page] = v }
    opts.on("--selfcare-content-id ID", Integer) { |v| params[:selfcare_content_id] = v }
    opts.on("--objective-id ID", Integer) { |v| params[:objective_id] = v }
  end.parse!(args)

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

#show(args = []) ⇒ Object



36
37
38
39
40
41
# File 'lib/holivia/commands/selfcare_objective.rb', line 36

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

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

#update(args = []) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/holivia/commands/selfcare_objective.rb', line 57

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

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia selfcare objective update <id> [options]"
    opts.on("--tier TIER") { |v| options[:tier] = 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