Class: Holivia::Commands::SupportPhoneNumber

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

Constant Summary collapse

BASE_PATH =
"/api/v1/backoffice/support_phone_numbers"

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/support_phone_number.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 support phone numbers command: #{subcommand}"
       exit 1
  end
end

Instance Method Details

#create(args = []) ⇒ Object



42
43
44
45
46
47
# File 'lib/holivia/commands/support_phone_number.rb', line 42

def create(args = [])
  options = parse_write_options(args, "Usage: holivia support-phone-numbers create [options]")
  abort "No options provided. Use --help for usage." if options.empty?

  output(client.post(BASE_PATH, body: options))
end

#delete(args = []) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/holivia/commands/support_phone_number.rb', line 59

def delete(args = [])
  id = args.shift
  abort "Usage: holivia support-phone-numbers 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
# File 'lib/holivia/commands/support_phone_number.rb', line 23

def index(args = [])
  params = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: holivia support-phone-numbers index [options]"
    opts.on("--country CODE") { |v| params[:country_code] = v }
    opts.on("--provider PROVIDER") { |v| params[:provider] = v }
    opts.on("--support-type TYPE") { |v| params[:support_type] = v }
  end.parse!(args)

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

#show(args = []) ⇒ Object



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

def show(args = [])
  id = args.shift
  abort "Usage: holivia support-phone-numbers show <id>" unless id

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

#update(args = []) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/holivia/commands/support_phone_number.rb', line 49

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

  options = parse_write_options(args, "Usage: holivia support-phone-numbers update <id> [options]")
  abort "No options provided. Use --help for usage." if options.empty?

  output(client.patch("#{BASE_PATH}/#{id}", body: options))
end