Class: Meroku::CLI::Domains

Inherits:
Thor
  • Object
show all
Includes:
Util
Defined in:
lib/meroku/cli/domains.rb

Instance Method Summary collapse

Instance Method Details

#add(domain) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/meroku/cli/domains.rb', line 47

def add(domain)
  require 'rest-client'
  require 'active_support/all'
  require 'rack'
  require 'action_view'

  resp = RestClient.post 'https://www.meroku.com/meroku/domains.json', { domain: domain, authentication: { token: cli_token, app_name: app_name } }
  puts "Added #{truncate(JSON.parse(resp)["data"]["domain"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
rescue RestClient::ServerBrokeConnection
  raise
rescue RestClient::Exception => e
  abort e.to_s if e == RestClient::ServerBrokeConnection
  out_str = "ERROR"
  if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
    out_str += " "
    out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
  end
  out_str += " (#{e.to_s}) "
  puts out_str
end

#listObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/meroku/cli/domains.rb', line 29

def list
  require 'rest-client'
  require 'active_support/all'
  require 'rack'
  require 'action_view'
  resp = RestClient.get "https://www.meroku.com/meroku/domains.json?authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
  puts "#{JSON.parse(resp)["data"]}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
rescue RestClient::Exception => e
  out_str = "ERROR"
  if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
    out_str += " "
    out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
  end
  out_str += " (#{e.to_s}) "
  puts out_str
end

#remove(domain) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/meroku/cli/domains.rb', line 10

def remove(domain)
  require 'rest-client'
  require 'active_support/all'
  require 'rack'
  require 'action_view'
  resp = RestClient.delete "https://www.meroku.com/meroku/domains/0.json?domain=#{domain}&authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
  puts "Removed #{truncate(JSON.parse(resp)["data"]["domain"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
rescue RestClient::Exception => e
  abort e.to_s if e.response.code != 200
  out_str = "ERROR"
  if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
    out_str += " "
    out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
  end
  out_str += " (#{e.to_s}) "
  puts out_str      
end