pingdom-cli 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ffa63ace83f83dd9b97e1dd159ba7a753f70d41
4
- data.tar.gz: 0b16ddc7d7e923543e228472541122220b76f24c
3
+ metadata.gz: d26b9daf54a57d95ad034c06430f3bc6dce57358
4
+ data.tar.gz: 58256c3143d356b4f68eb8acd21844f4c195c5de
5
5
  SHA512:
6
- metadata.gz: 07d58bfd20ee1718ca48e8d9b4816beb6ba7293a350333e48dc22dcc007519c933b55c29f331f592487494f9938485472ad0b590c88c77bb1d56337731b6d9bc
7
- data.tar.gz: 0823efdca46119122eebfe6f2a4863f9d251b16af724cfe2033f9eb49634e29e2fc1423685b60684bfe31915eabaebe4317fdcbcea70126877714ed32315f350
6
+ metadata.gz: 9fdbc50dbe9338006c0e409791e0a3b66ef27fcd210b1562d52e50c1a47c745a462f74f8dac947f40e486b4e52112ed3bb3c52be1f71d940afd2b8f979018d2b
7
+ data.tar.gz: 996b2788483c515e6335073705361d66f671beca3538a725d944610fb2b9f3f41daf346cf80b3f51098e81e020d49928f95fad9125f8fa8b4fa731c6e7d016ee
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
2
  require 'pingdom/cli'
5
3
 
6
4
  Pingdom::Cli::CLI.start
@@ -19,42 +19,47 @@ module Pingdom
19
19
 
20
20
  desc "config", "config"
21
21
  def config
22
- puts @config.to_json
22
+ puts_json @config
23
23
  end
24
24
 
25
25
  desc "checks", "checks"
26
26
  def checks
27
- puts @core.checks.to_json
27
+ puts_json @core.checks
28
28
  end
29
29
 
30
30
  desc "actions", "actions"
31
31
  def actions
32
- puts @core.actions.to_json
32
+ puts_json @core.actions
33
33
  end
34
34
 
35
35
  desc "contacts", "contacts"
36
36
  def contacts
37
- puts @core.contacts.to_json
37
+ puts_json @core.contacts
38
38
  end
39
39
 
40
40
  desc "probes", "probes"
41
41
  def probes
42
- puts @core.probes.to_json
42
+ puts_json @core.probes
43
43
  end
44
44
 
45
45
  desc "reference", "reference"
46
46
  def reference
47
- puts @core.reference.to_json
47
+ puts_json @core.reference
48
48
  end
49
49
 
50
50
  desc "reports_public", "reports_public"
51
51
  def reports_public
52
- puts @core.reports_public.to_json
52
+ puts_json @core.reports_public
53
53
  end
54
54
 
55
55
  desc "settings", "settings"
56
56
  def settings
57
- puts @core.settings.to_json
57
+ puts_json @core.settings
58
+ end
59
+
60
+ desc "credits", "credits"
61
+ def credits
62
+ puts_json @core.credits
58
63
  end
59
64
 
60
65
  desc "pause", "pause"
@@ -72,6 +77,12 @@ module Pingdom
72
77
  def update
73
78
  puts @core.update(options['params'])
74
79
  end
80
+
81
+ private
82
+
83
+ def puts_json(object)
84
+ puts JSON.pretty_generate(object)
85
+ end
75
86
  end
76
87
  end
77
88
  end
@@ -7,59 +7,70 @@ module Pingdom
7
7
 
8
8
  def initialize(config)
9
9
  @config = config
10
- @url_base = "https://#{CGI::escape @config['user']}:#{CGI::escape @config['password']}@api.pingdom.com/api/2.0/"
11
- @header = {"App-Key" => @config['app_key']}
10
+ @url_base = "https://api.pingdom.com/api/2.0/"
11
+ @header = { "App-Key" => @config['app_key'] }
12
12
  end
13
13
 
14
14
  def checks
15
- response = RestClient.get(get_url('checks'), @header)
15
+ response = get_resource('checks').get
16
16
  results = JSON.parse(response.body, :symbolize_names => true)
17
- results[:checks].each do |result|
17
+ results[__method__].each do |result|
18
18
  result[:lasttesttime] = Time.at(result[:lasttesttime]) unless result[:lasttesttime].nil?
19
19
  result[:lasterrortime] = Time.at(result[:lasterrortime]) unless result[:lasterrortime].nil?
20
20
  result[:created] = Time.at(result[:created]) unless result[:created].nil?
21
21
  end
22
- results
22
+ results[__method__]
23
23
  end
24
24
 
25
25
  def actions
26
- response = RestClient.get(get_url('actions'), @header)
27
- JSON.parse(response.body, :symbolize_names => true)
26
+ response = get_resource('actions').get
27
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
28
28
  end
29
29
 
30
30
  def contacts
31
- response = RestClient.get(get_url('contacts'), @header)
32
- JSON.parse(response.body, :symbolize_names => true)
31
+ response = get_resource('contacts').get
32
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
33
33
  end
34
34
 
35
35
  def probes
36
- response = RestClient.get(get_url('probes'), @header)
37
- JSON.parse(response.body, :symbolize_names => true)
36
+ response = get_resource('probes').get
37
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
38
38
  end
39
39
 
40
40
  def reference
41
- response = RestClient.get(get_url('reference'), @header)
42
- JSON.parse(response.body, :symbolize_names => true)
41
+ response = get_resource('reference').get
42
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
43
43
  end
44
44
 
45
45
  def reports_public
46
- response = RestClient.get(get_url('reports.public'), @header)
47
- JSON.parse(response.body, :symbolize_names => true)
46
+ response = get_resource('reports.public').get
47
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
48
48
  end
49
49
 
50
50
  def settings
51
- response = RestClient.get(get_url('settings'), @header)
52
- JSON.parse(response.body, :symbolize_names => true)
51
+ response = get_resource('settings').get
52
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
53
+ end
54
+
55
+ def credits
56
+ response = get_resource('credits').get
57
+ JSON.parse(response.body, :symbolize_names => true)[__method__]
53
58
  end
54
59
 
55
60
  def update(params)
56
- response = RestClient.put(get_url('checks'), params, @header)
61
+ response = get_resource('checks').put(params)
57
62
  response.body
58
63
  end
59
64
 
60
65
  private
61
- def get_url(action)
62
- @url_base + action
66
+ def get_resource(action)
67
+ resource = RestClient::Resource.new(
68
+ @url_base + action,
69
+ :user => @config['user'],
70
+ :password => @config['password'],
71
+ :headers => { 'App-Key' => @config['app_key'] },
72
+ :verify_ssl => false
73
+ )
63
74
  end
64
75
  end
65
76
  end
@@ -1,6 +1,6 @@
1
1
  module Pingdom
2
2
  module Cli
3
3
  # pingdom-cli version
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingdom-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Toyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-11 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.4.2
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: pingdom simple command line interface