uptimerobot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +5 -0
- data/lib/uptimerobot/client.rb +81 -0
- data/lib/uptimerobot/constants.rb +63 -0
- data/lib/uptimerobot/error.rb +8 -0
- data/lib/uptimerobot/version.rb +3 -0
- data/lib/uptimerobot.rb +11 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/uptimerobot_spec.rb +323 -0
- data/uptimerobot.gemspec +27 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5088ae822042249d75f565444c690f3b78004708
|
4
|
+
data.tar.gz: c5010ef79778af6526571a622f55ed82720afed6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bb3f5238287aa6e8dba3080c97c23940ecd70332b590b5d93e8d1703d123cc2d311d32477ff49ef3a03fc8a65e4f3abea7fd644dd498b653d33d606e0c08e45
|
7
|
+
data.tar.gz: 97ec87f9ec004dd86d02e13d7b6ccbeb9d018f4edf914c00240427efeb573a0bd521226f82a2eb3d32204df852897039b28278394b39987212ee5a0997d6b3cf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Genki Sugawara
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# UptimeRobot
|
2
|
+
|
3
|
+
[Uptime Robot](https://uptimerobot.com/) API client for Ruby.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/uptimerobot.svg)](http://badge.fury.io/rb/uptimerobot)
|
6
|
+
[![Build Status](https://travis-ci.org/winebarrel/uptimerobot.svg?branch=master)](https://travis-ci.org/winebarrel/uptimerobot)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'uptimerobot'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install uptimerobot
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'uptimerobot'
|
28
|
+
|
29
|
+
client = UptimeRobot::Client.new(api_key: 'u956-afus321g565fghr519')
|
30
|
+
|
31
|
+
client.getMonitors
|
32
|
+
# => {"stat"=>"ok",
|
33
|
+
# "offset"=>"0",
|
34
|
+
# "limit"=>"50",
|
35
|
+
# "total"=>"2",
|
36
|
+
# "monitors"=>
|
37
|
+
# {"monitor"=>
|
38
|
+
# [{"id"=>"128795",
|
39
|
+
# "friendlyname"=>"Yahoo",
|
40
|
+
# "url"=>"http://www.yahoo.com/",
|
41
|
+
# "type"=>"1",
|
42
|
+
# "subtype"=>"",
|
43
|
+
# ...
|
44
|
+
|
45
|
+
client.newMonitor(
|
46
|
+
:monitorFriendlyName => 'Google',
|
47
|
+
:monitorURL => 'http://www.google.com',
|
48
|
+
:monitorType => UptimeRobot::Monitor::Type::HTTP,
|
49
|
+
:monitorAlertContacts => '448-716'
|
50
|
+
)
|
51
|
+
```
|
52
|
+
|
53
|
+
## Test
|
54
|
+
|
55
|
+
$ bundle exec rake
|
56
|
+
|
57
|
+
## Uptime Robot API reference
|
58
|
+
|
59
|
+
* https://uptimerobot.com/api
|
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
class UptimeRobot::Client
|
2
|
+
ENDPOINT = 'http://api.uptimerobot.com'
|
3
|
+
USER_AGENT = "Ruby UptimeRobot Client #{UptimeRobot::VERSION}"
|
4
|
+
|
5
|
+
METHODS = [
|
6
|
+
:getAccountDetails,
|
7
|
+
:getMonitors,
|
8
|
+
:newMonitor,
|
9
|
+
:editMonitor,
|
10
|
+
:deleteMonitor,
|
11
|
+
:getAlertContacts,
|
12
|
+
:newAlertContact,
|
13
|
+
:deleteAlertContact
|
14
|
+
]
|
15
|
+
|
16
|
+
DEFAULT_ADAPTERS = [
|
17
|
+
Faraday::Adapter::NetHttp,
|
18
|
+
Faraday::Adapter::Test
|
19
|
+
]
|
20
|
+
|
21
|
+
def initialize(options)
|
22
|
+
@api_key = options.delete(:api_key)
|
23
|
+
|
24
|
+
raise ':api_key is required' unless @api_key
|
25
|
+
|
26
|
+
options[:url] ||= ENDPOINT
|
27
|
+
|
28
|
+
@conn = Faraday.new(options) do |faraday|
|
29
|
+
faraday.request :url_encoded
|
30
|
+
faraday.response :json, :content_type => /\bjson$/
|
31
|
+
faraday.response :raise_error
|
32
|
+
|
33
|
+
yield(faraday) if block_given?
|
34
|
+
|
35
|
+
unless DEFAULT_ADAPTERS.any? {|i| faraday.builder.handlers.include?(i) }
|
36
|
+
faraday.adapter Faraday.default_adapter
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@conn.headers[:user_agent] = USER_AGENT
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def method_missing(method_name, *args, &block)
|
46
|
+
unless METHODS.include?(method_name)
|
47
|
+
raise NoMethodError, "undefined method: #{method_name}"
|
48
|
+
end
|
49
|
+
|
50
|
+
len = args.length
|
51
|
+
params = args.first
|
52
|
+
|
53
|
+
unless len.zero? or (len == 1 and params.kind_of?(Hash))
|
54
|
+
raise ArgumentError, "invalid argument: #{args}"
|
55
|
+
end
|
56
|
+
|
57
|
+
request(method_name, params || {}, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def request(method_name, params = {})
|
61
|
+
params.update(
|
62
|
+
:apiKey => @api_key,
|
63
|
+
:format => 'json',
|
64
|
+
:noJsonCallback => 1
|
65
|
+
)
|
66
|
+
|
67
|
+
response = @conn.get do |req|
|
68
|
+
req.url "/#{method_name}"
|
69
|
+
req.params = params
|
70
|
+
yield(req) if block_given?
|
71
|
+
end
|
72
|
+
|
73
|
+
json = response.body
|
74
|
+
|
75
|
+
if json['stat'] != 'ok'
|
76
|
+
raise UptimeRobot::Error.new(json)
|
77
|
+
end
|
78
|
+
|
79
|
+
json
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module UptimeRobot
|
2
|
+
module Monitor
|
3
|
+
module Type
|
4
|
+
HTTP = 1
|
5
|
+
Keyword = 2
|
6
|
+
Ping = 3
|
7
|
+
Port = 4
|
8
|
+
end
|
9
|
+
|
10
|
+
module SubType
|
11
|
+
HTTP = 1
|
12
|
+
HTTPS = 2
|
13
|
+
FTP = 3
|
14
|
+
SMTP = 4
|
15
|
+
POP3 = 5
|
16
|
+
IMAP = 6
|
17
|
+
Custom = 99
|
18
|
+
end
|
19
|
+
|
20
|
+
module KeywordType
|
21
|
+
KeywordExists = 1
|
22
|
+
KeywordNotExists = 2
|
23
|
+
end
|
24
|
+
|
25
|
+
module Status
|
26
|
+
Paused = 0
|
27
|
+
NotCheckedYet = 1
|
28
|
+
Up = 2
|
29
|
+
SeemsDown = 8
|
30
|
+
Down = 9
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Log
|
35
|
+
module Type
|
36
|
+
Down = 1
|
37
|
+
Up = 2
|
38
|
+
Paused = 99
|
39
|
+
Started = 98
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module AlertContact
|
44
|
+
module Type
|
45
|
+
SMS = 1
|
46
|
+
Email = 2
|
47
|
+
TwitterDM = 3
|
48
|
+
Boxcar = 4
|
49
|
+
WebHook = 5
|
50
|
+
Pushbullet = 6
|
51
|
+
Zapier = 7
|
52
|
+
Pushover = 9
|
53
|
+
HipChat = 10
|
54
|
+
Slack = 11
|
55
|
+
end
|
56
|
+
|
57
|
+
module Status
|
58
|
+
NotSctivated = 0
|
59
|
+
Paused = 1
|
60
|
+
Active = 2
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/uptimerobot.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'uptimerobot'
|
2
|
+
|
3
|
+
DEFAULT_PARAMS = {
|
4
|
+
'apiKey' => 'ZAPZAPZAP',
|
5
|
+
'format' => 'json',
|
6
|
+
'noJsonCallback' => '1'
|
7
|
+
}
|
8
|
+
|
9
|
+
def uptime_robot
|
10
|
+
stubs = Faraday::Adapter::Test::Stubs.new
|
11
|
+
|
12
|
+
described_class.new(api_key: 'ZAPZAPZAP') do |faraday|
|
13
|
+
faraday.adapter :test, stubs do |stub|
|
14
|
+
yield(stub)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def stringify_hash(hash)
|
20
|
+
Hash[*hash.map {|k, v| [k.to_s, v.to_s] }.flatten(1)]
|
21
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
describe UptimeRobot::Client do
|
2
|
+
describe '#getAccountDetails' do
|
3
|
+
let(:response) do
|
4
|
+
{"stat"=>"ok",
|
5
|
+
"account"=>
|
6
|
+
{"monitorLimit"=>"100",
|
7
|
+
"upMonitors"=>"35",
|
8
|
+
"downMonitors"=>"9",
|
9
|
+
"pausedMonitors"=>"11"}}
|
10
|
+
end
|
11
|
+
|
12
|
+
it do
|
13
|
+
client = uptime_robot do |stub|
|
14
|
+
stub.get('getAccountDetails') do |env|
|
15
|
+
expect(env.params).to eq DEFAULT_PARAMS
|
16
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(client.getAccountDetails).to eq response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#getMonitors' do
|
25
|
+
let(:params) do
|
26
|
+
{
|
27
|
+
:logs => 1,
|
28
|
+
:alertContacts => 1,
|
29
|
+
:responseTimes => 1,
|
30
|
+
:responseTimesAverage => 180,
|
31
|
+
:monitors => '15830-32696'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:response) do
|
36
|
+
{"stat"=>"ok",
|
37
|
+
"offset"=>"0",
|
38
|
+
"limit"=>"50",
|
39
|
+
"total"=>"2",
|
40
|
+
"monitors"=>
|
41
|
+
{"monitor"=>
|
42
|
+
[{"id"=>"128795",
|
43
|
+
"friendlyname"=>"Yahoo",
|
44
|
+
"url"=>"http://www.yahoo.com/",
|
45
|
+
"type"=>"1",
|
46
|
+
"subtype"=>"",
|
47
|
+
"keywordtype"=>"0",
|
48
|
+
"keywordvalue"=>"",
|
49
|
+
"httpusername"=>"",
|
50
|
+
"httppassword"=>"",
|
51
|
+
"port"=>"",
|
52
|
+
"interval"=>"300",
|
53
|
+
"status"=>"2",
|
54
|
+
"alltimeuptimeratio"=>"99.98",
|
55
|
+
"customuptimeratio"=>"100.00",
|
56
|
+
"alertcontact"=>
|
57
|
+
[{"id"=>"4631", "type"=>"2", "value"=>"uptime@webresourcesdepot.com"},
|
58
|
+
{"id"=>"2420", "type"=>"3", "value"=>"umutm"}],
|
59
|
+
"log"=>
|
60
|
+
[{"type"=>"2",
|
61
|
+
"datetime"=>"09/25/2011 16:12:44",
|
62
|
+
"alertcontact"=>
|
63
|
+
[{"type"=>"0", "value"=>"uptime@webresourcesdepot.com"},
|
64
|
+
{"type"=>"3", "value"=>"umutm"}]},
|
65
|
+
{"type"=>"1",
|
66
|
+
"datetime"=>"09/25/2011 16:11:44",
|
67
|
+
"alertcontact"=>
|
68
|
+
[{"type"=>"0", "value"=>"uptime@webresourcesdepot.com"},
|
69
|
+
{"type"=>"3", "value"=>"umutm"}]}],
|
70
|
+
"responsetime"=>
|
71
|
+
[{"datetime"=>"02/04/2014 11:30:41", "value"=>"405"},
|
72
|
+
{"datetime"=>"02/04/2014 12:00:41", "value"=>"516"},
|
73
|
+
{"datetime"=>"02/04/2014 12:30:41", "value"=>"780"}]},
|
74
|
+
{"id"=>"128796",
|
75
|
+
"friendlyname"=>"WebResourcesDepot",
|
76
|
+
"url"=>"http://www.webresourcesdepot.com/",
|
77
|
+
"type"=>"1",
|
78
|
+
"subtype"=>"",
|
79
|
+
"keywordtype"=>"0",
|
80
|
+
"keywordvalue"=>"",
|
81
|
+
"httpusername"=>"",
|
82
|
+
"httppassword"=>"",
|
83
|
+
"port"=>"",
|
84
|
+
"interval"=>"300",
|
85
|
+
"status"=>"2",
|
86
|
+
"alltimeuptimeratio"=>"99.94",
|
87
|
+
"customtimeuptimeratio"=>"89.51",
|
88
|
+
"alertcontact"=>[{"id"=>"2420", "type"=>"3", "value"=>"umutm"}],
|
89
|
+
"log"=>
|
90
|
+
[{"type"=>"2",
|
91
|
+
"datetime"=>"08/30/2011 16:11:15",
|
92
|
+
"alertcontact"=>
|
93
|
+
[{"type"=>"0", "value"=>"uptime@webresourcesdepot.com"},
|
94
|
+
{"type"=>"3", "value"=>"umutm"}]},
|
95
|
+
{"type"=>"1",
|
96
|
+
"datetime"=>"08/30/2011 16:09:30",
|
97
|
+
"alertcontact"=>
|
98
|
+
[{"type"=>"0", "value"=>"uptime@webresourcesdepot.com"},
|
99
|
+
{"type"=>"3", "value"=>"umutm"}]}],
|
100
|
+
"responsetime"=>
|
101
|
+
[{"datetime"=>"02/04/2014 11:48:41", "value"=>"405"},
|
102
|
+
{"datetime"=>"02/04/2014 12:18:41", "value"=>"516"},
|
103
|
+
{"datetime"=>"02/04/2014 12:48:41", "value"=>"780"}]}]}}
|
104
|
+
end
|
105
|
+
|
106
|
+
it do
|
107
|
+
client = uptime_robot do |stub|
|
108
|
+
stub.get('getMonitors') do |env|
|
109
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
110
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
expect(client.getMonitors(params)).to eq response
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#newMonitor' do
|
119
|
+
let(:params) do
|
120
|
+
{
|
121
|
+
:monitorFriendlyName => 'Google',
|
122
|
+
:monitorURL => 'http://www.google.com',
|
123
|
+
:monitorType => UptimeRobot::Monitor::Type::HTTP,
|
124
|
+
:monitorAlertContacts => '448-716'
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:response) do
|
129
|
+
{"stat"=>"ok", "monitor"=>{"id"=>"128798"}}
|
130
|
+
end
|
131
|
+
|
132
|
+
it do
|
133
|
+
client = uptime_robot do |stub|
|
134
|
+
stub.get('newMonitor') do |env|
|
135
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
136
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
expect(client.newMonitor(params)).to eq response
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#editMonitor' do
|
145
|
+
let(:params) do
|
146
|
+
{
|
147
|
+
:monitorID => 128798,
|
148
|
+
:monitorFriendlyName => 'GoogleHomepage'
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
let(:response) do
|
153
|
+
{"stat"=>"ok", "monitor"=>{"id"=>"128798"}}
|
154
|
+
end
|
155
|
+
|
156
|
+
it do
|
157
|
+
client = uptime_robot do |stub|
|
158
|
+
stub.get('editMonitor') do |env|
|
159
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
160
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
expect(client.editMonitor(params)).to eq response
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#deleteMonitor' do
|
169
|
+
let(:params) do
|
170
|
+
{
|
171
|
+
:monitorID => 128798
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
let(:response) do
|
176
|
+
{"stat"=>"ok", "monitor"=>{"id"=>"128798"}}
|
177
|
+
end
|
178
|
+
|
179
|
+
it do
|
180
|
+
client = uptime_robot do |stub|
|
181
|
+
stub.get('deleteMonitor') do |env|
|
182
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
183
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
expect(client.deleteMonitor(params)).to eq response
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '#getAlertContacts' do
|
192
|
+
let(:params) do
|
193
|
+
{
|
194
|
+
:alertcontacts => 236
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
let(:response) do
|
199
|
+
{"stat"=>"ok",
|
200
|
+
"offset"=>"0",
|
201
|
+
"limit"=>"50",
|
202
|
+
"total"=>"1",
|
203
|
+
"alertcontacts"=>
|
204
|
+
{"alertcontact"=>
|
205
|
+
[{"id"=>"236",
|
206
|
+
"value"=>"uptime@webresourcesdepot.com",
|
207
|
+
"type"=>"2",
|
208
|
+
"status"=>"2"}]}}
|
209
|
+
end
|
210
|
+
|
211
|
+
it do
|
212
|
+
client = uptime_robot do |stub|
|
213
|
+
stub.get('getAlertContacts') do |env|
|
214
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
215
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
expect(client.getAlertContacts(params)).to eq response
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe '#newAlertContact' do
|
224
|
+
let(:params) do
|
225
|
+
{
|
226
|
+
:alertContactType => UptimeRobot::AlertContact::Type::Email,
|
227
|
+
:alertContactValue => 'uptime@webresourcesdepot.com'
|
228
|
+
}
|
229
|
+
end
|
230
|
+
|
231
|
+
let(:response) do
|
232
|
+
{"stat"=>"ok", "alertcontact"=>{"id"=>"4561", "status"=>"0"}}
|
233
|
+
end
|
234
|
+
|
235
|
+
it do
|
236
|
+
client = uptime_robot do |stub|
|
237
|
+
stub.get('newAlertContact') do |env|
|
238
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
239
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
expect(client.newAlertContact(params)).to eq response
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '#deleteAlertContact' do
|
248
|
+
let(:params) do
|
249
|
+
{
|
250
|
+
:alertContactID => 236
|
251
|
+
}
|
252
|
+
end
|
253
|
+
|
254
|
+
let(:response) do
|
255
|
+
{"stat"=>"ok", "alertcontact"=>{"id"=>"236"}}
|
256
|
+
end
|
257
|
+
|
258
|
+
it do
|
259
|
+
client = uptime_robot do |stub|
|
260
|
+
stub.get('deleteAlertContact') do |env|
|
261
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
262
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
expect(client.deleteAlertContact(params)).to eq response
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'when stat is fail' do
|
271
|
+
let(:response) do
|
272
|
+
{"stat"=>"fail", "id"=>"101", "message"=>"apiKey is wrong"}
|
273
|
+
end
|
274
|
+
|
275
|
+
it do
|
276
|
+
client = uptime_robot do |stub|
|
277
|
+
stub.get('getAccountDetails') do |env|
|
278
|
+
expect(env.params).to eq DEFAULT_PARAMS
|
279
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response)]
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
expect {
|
284
|
+
client.getAccountDetails
|
285
|
+
}.to raise_error(UptimeRobot::Error, response.inspect)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
context 'when status is not 200' do
|
290
|
+
it do
|
291
|
+
client = uptime_robot do |stub|
|
292
|
+
stub.get('getAccountDetails') do |env|
|
293
|
+
expect(env.params).to eq DEFAULT_PARAMS
|
294
|
+
[500, {}, 'An error occurred on the server when processing the URL']
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
expect {
|
299
|
+
client.getAccountDetails
|
300
|
+
}.to raise_error
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context 'when undefined method is called' do
|
305
|
+
it do
|
306
|
+
client = uptime_robot
|
307
|
+
|
308
|
+
expect {
|
309
|
+
client.get_account_details
|
310
|
+
}.to raise_error(NoMethodError, 'undefined method: get_account_details')
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context 'when invalid params is passed' do
|
315
|
+
it do
|
316
|
+
client = uptime_robot
|
317
|
+
|
318
|
+
expect {
|
319
|
+
client.getAccountDetails(0)
|
320
|
+
}.to raise_error(ArgumentError, 'invalid argument: [0]')
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
data/uptimerobot.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'uptimerobot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'uptimerobot'
|
8
|
+
spec.version = UptimeRobot::VERSION
|
9
|
+
spec.authors = ['Genki Sugawara']
|
10
|
+
spec.email = ['sgwr_dts@yahoo.co.jp']
|
11
|
+
spec.summary = %q{Uptime Robot API client for Ruby.}
|
12
|
+
spec.description = %q{Uptime Robot API client for Ruby.}
|
13
|
+
spec.homepage = 'https://github.com/winebarrel/uptimerobot'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday', '>= 0.8'
|
22
|
+
spec.add_dependency 'faraday_middleware'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uptimerobot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Genki Sugawara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0
|
83
|
+
description: Uptime Robot API client for Ruby.
|
84
|
+
email:
|
85
|
+
- sgwr_dts@yahoo.co.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/uptimerobot.rb
|
98
|
+
- lib/uptimerobot/client.rb
|
99
|
+
- lib/uptimerobot/constants.rb
|
100
|
+
- lib/uptimerobot/error.rb
|
101
|
+
- lib/uptimerobot/version.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/uptimerobot_spec.rb
|
104
|
+
- uptimerobot.gemspec
|
105
|
+
homepage: https://github.com/winebarrel/uptimerobot
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.0.14
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Uptime Robot API client for Ruby.
|
129
|
+
test_files:
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/uptimerobot_spec.rb
|