Class: Inventarium::CLI::Push

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/inventarium/cli/push.rb

Constant Summary collapse

DEFAULT_BASE_URL =
'https://app.inventarium.io'

Instance Method Summary collapse

Instance Method Details

#call(args: []) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/inventarium/cli/push.rb', line 19

def call(args: [], **)
  path = args.first || './service.yml'

  bar = TTY::ProgressBar.new("Puishing #{path} to inventarium.io [:bar]", total: 30)
  bar.advance(10)

  config = parse_config(path)

  bar.advance(10)

  response = push_config(config)

  bar.advance(10)

  pastel = Pastel.new

  case response.code
  when '200'
    puts "[#{pastel.green('DONE')}]"

    exit(0) # success exist
  when '401' #  Unauthorized
    puts "[#{pastel.red('FAIL')}] #{response.body}"
  when '403' #  Forbidden
    puts "[#{pastel.red('FAIL')}] #{response.body}"
  when '422' # invalid data
    puts "[#{pastel.red('FAIL')}]"
    pp JSON.parse(response.body)
  when '500'
    puts "[#{pastel.red('FAIL')}] Service error, please try later or create an issue in https://github.com/inventarium-org/core"
  end

  exit(1)
end