statuscake 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cadfeb6208f65420ba21cd45206682877393efa9
4
+ data.tar.gz: 583b53dff5bff3175836ea7da8888f55702ebf1b
5
+ SHA512:
6
+ metadata.gz: 7e5a1614546a72e8bf9ccc477082b0dfdc7128eda085afa7f142427e792d8730cc2fb81bea10742455abee0e0254874e895813a656f128a6144da61524855fb9
7
+ data.tar.gz: d6c21211447748539f2fd1d54ad50bc9731fd983336611ebcfb6cd9175e1c24eefa7d80d9d23512ecd0440aa1379caee4bf94abbf9ec7957a978b8d223a63cb0
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script:
5
+ - bundle install
6
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statuscake.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 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.
@@ -0,0 +1,97 @@
1
+ # StatusCake
2
+
3
+ It is a [Status Cake](https://www.statuscake.com/) API client library.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/statuscake.svg)](http://badge.fury.io/rb/statuscake)
6
+ [![Build Status](https://travis-ci.org/winebarrel/statuscake.svg?branch=master)](https://travis-ci.org/winebarrel/statuscake)
7
+
8
+ It is a thin library, and methods are [dynamically generated](https://github.com/winebarrel/statuscake/blob/a5f692fa8bf02a16f7a98e1c7d05f2110e51dbd1/lib/statuscake/client.rb#L56).
9
+
10
+ ```ruby
11
+ path.sub(%r|\A/API/|, '').gsub('/', '_').downcase
12
+ # "/API/Tests/Details" => "def tests_details"
13
+ ```
14
+
15
+ It supports the following API:
16
+
17
+ * /API/Alerts
18
+ * /API/ContactGroups/Update
19
+ * /API/ContactGroups
20
+ * /API/Tests/Checks
21
+ * /API/Tests/Periods
22
+ * /API/Tests
23
+ * /API/Tests/Details
24
+ * /API/Tests/Update
25
+ * /API/Locations/json
26
+ * /API/Locations/txt
27
+ * /API/Locations/xml
28
+ * /API/Auth
29
+
30
+ see [StatusCake::Client::APIs](https://github.com/winebarrel/statuscake/blob/a5f692fa8bf02a16f7a98e1c7d05f2110e51dbd1/lib/statuscake/client.rb#L15).
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'statuscake'
38
+ ```
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Or install it yourself as:
45
+
46
+ $ gem install statuscake
47
+
48
+ ## Usage
49
+
50
+ ```ruby
51
+ require 'statuscake'
52
+
53
+ client = StatusCake::Client.new(API: 'l6OxVJilcD2cETMoNRvn', Username: 'StatusCake')
54
+
55
+ client.tests_details(TestID: 241)
56
+ #=> {"TestID"=>241,
57
+ # "TestType"=>"HTTP",
58
+ # "Paused"=>false,
59
+ # "Affected"=>1,
60
+ # ...
61
+
62
+ client.tests_update(
63
+ WebsiteName: 'Example Domain',
64
+ WebsiteURL: 'http://example.com',
65
+ CheckRate: 300,
66
+ TestType: :HTTP)
67
+ #=> {"Success"=>true,
68
+ # "Message"=>"Test Inserted",
69
+ # "Issues"=>nil,
70
+ # "Data"=>
71
+ # {"WebsiteName"=>"Example Domain",
72
+ # ...
73
+ ```
74
+
75
+ ### Deleting a Test
76
+
77
+ ```ruby
78
+ client.tests_details(
79
+ method: :delete,
80
+ TestID: 241)
81
+ #=> {"TestID"=>6735,
82
+ # "Affected"=>1,
83
+ # "Success"=>true,
84
+ # "Message"=>"This Check Has Been Deleted. It can not be recovered."}
85
+
86
+ ```
87
+
88
+ I think this method call is strange.
89
+
90
+ This is because [the original API](https://www.statuscake.com/api/Tests/Deleting%20a%20Test.md) is strange.
91
+
92
+ ## Test
93
+
94
+ ```ruby
95
+ bundle install
96
+ bundle exec rake
97
+ ```
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module StatusCake; end
5
+
6
+ require 'statuscake/client'
7
+ require 'statuscake/error'
8
+ require 'statuscake/version'
@@ -0,0 +1,101 @@
1
+ class StatusCake::Client
2
+ ENDPOINT = 'https://www.statuscake.com'
3
+ USER_AGENT = "Ruby StatusCake Client #{StatusCake::VERSION}"
4
+
5
+ DEFAULT_ADAPTERS = [
6
+ Faraday::Adapter::NetHttp,
7
+ Faraday::Adapter::Test
8
+ ]
9
+
10
+ OPTIONS = [
11
+ :API,
12
+ :Username,
13
+ ]
14
+
15
+ APIs = {
16
+ '/API/Alerts' => {:method => :get},
17
+ '/API/ContactGroups/Update' => {:method => :put},
18
+ '/API/ContactGroups' => {:method => :get},
19
+ '/API/Tests/Checks' => {:method => :get},
20
+ '/API/Tests/Periods' => {:method => :get},
21
+ '/API/Tests' => {:method => :get},
22
+ '/API/Tests/Details' => {:method => :get},
23
+ # Delete test when HTTP method is "DELETE"
24
+ # see https://www.statuscake.com/api/Tests/Deleting%20a%20Test.md
25
+ '/API/Tests/Update' => {:method => :put},
26
+ '/API/Locations/json' => {:method => :get, :alias => :locations},
27
+ '/API/Locations/txt' => {:method => :get},
28
+ '/API/Locations/xml' => {:method => :get},
29
+ '/API/Auth' => {:method => :get},
30
+ }
31
+
32
+ def initialize(options)
33
+ @options = {}
34
+
35
+ OPTIONS.each do |key|
36
+ @options[key] = options.delete(key)
37
+ end
38
+
39
+ options[:url] ||= ENDPOINT
40
+
41
+ @conn = Faraday.new(options) do |faraday|
42
+ faraday.request :url_encoded
43
+ faraday.response :json, :content_type => /\bjson$/
44
+ faraday.response :raise_error
45
+
46
+ yield(faraday) if block_given?
47
+
48
+ unless DEFAULT_ADAPTERS.any? {|i| faraday.builder.handlers.include?(i) }
49
+ faraday.adapter Faraday.default_adapter
50
+ end
51
+ end
52
+
53
+ @conn.headers[:user_agent] = USER_AGENT
54
+ end
55
+
56
+ APIs.each do |path, attrs|
57
+ names = [path.sub(%r|\A/API/|, '').gsub('/', '_').downcase]
58
+ names << attrs[:alias] if attrs.has_key?(:alias)
59
+ method = attrs[:method]
60
+
61
+ names.each do |name|
62
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
63
+ def #{name}(params = {})
64
+ method = params.delete(:method) || #{method.inspect}
65
+ request(#{path.inspect}, method, params)
66
+ end
67
+ EOS
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def request(path, method, params = {})
74
+ response = @conn.send(method) do |req|
75
+ req.url path
76
+
77
+ case method
78
+ when :get, :delete
79
+ req.params = params
80
+ when :post, :put
81
+ req.body = params
82
+ else
83
+ raise 'must not happen'
84
+ end
85
+
86
+ req.headers[:API] = @options[:API]
87
+ req.headers[:Username] = @options[:Username]
88
+ yield(req) if block_given?
89
+ end
90
+
91
+ json = response.body
92
+ validate_response(json)
93
+ json
94
+ end
95
+
96
+ def validate_response(json)
97
+ if json.kind_of?(Hash) and json.has_key?('ErrNo')
98
+ raise StatusCake::Error.new(json)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,12 @@
1
+ class StatusCake::Error < StandardError
2
+ attr_reader :json
3
+
4
+ def initialize(json)
5
+ @json = json
6
+ super(json['Error'])
7
+ end
8
+
9
+ def err_no
10
+ json['ErrNo'].to_i
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module StatusCake
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'statuscake'
2
+ require 'uri'
3
+
4
+ TEST_API_KEY = 'l6OxVJilcD2cETMoNRvn'
5
+ TEST_USERNAME = 'StatusCake'
6
+
7
+ def status_cake(options = {})
8
+ options = {
9
+ API: TEST_API_KEY,
10
+ Username: TEST_USERNAME,
11
+ }.merge(options)
12
+
13
+ stubs = Faraday::Adapter::Test::Stubs.new
14
+
15
+ described_class.new(options) do |faraday|
16
+ faraday.adapter :test, stubs do |stub|
17
+ yield(stub)
18
+ end
19
+ end
20
+ end
21
+
22
+ def stringify_hash(hash)
23
+ Hash[*hash.map {|k, v| [k.to_s, v.to_s] }.flatten(1)]
24
+ end
@@ -0,0 +1,393 @@
1
+ describe StatusCake::Client do
2
+ let(:request_headers) do
3
+ {
4
+ 'User-Agent' => StatusCake::Client::USER_AGENT,
5
+ 'Api' => TEST_API_KEY,
6
+ 'Username' => TEST_USERNAME,
7
+ }
8
+ end
9
+
10
+ let(:form_request_headers) do
11
+ request_headers.merge(
12
+ 'Content-Type' => 'application/x-www-form-urlencoded'
13
+ )
14
+ end
15
+
16
+ describe '/API/Alerts' do
17
+ let(:params) do
18
+ {TestID: 241}
19
+ end
20
+
21
+ let(:response) do
22
+ [{"Triggered"=>"2013-02-25 14:42:41",
23
+ "StatusCode"=>0,
24
+ "Unix"=>1361803361,
25
+ "Status"=>"Down",
26
+ "TestID"=>26324}]
27
+ end
28
+
29
+ it do
30
+ client = status_cake do |stub|
31
+ stub.get('/API/Alerts') do |env|
32
+ expect(env.request_headers).to eq request_headers
33
+ expect(env.params).to eq stringify_hash(params)
34
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
35
+ end
36
+ end
37
+
38
+ expect(client.alerts(params)).to eq response
39
+ end
40
+ end
41
+
42
+ describe '/API/ContactGroups/Update' do
43
+ let(:params) do
44
+ {GroupName: 'my group', Email: 'alice@example.com'}
45
+ end
46
+
47
+ let(:response) do
48
+ {"Success"=>true,
49
+ "Message"=>"Test Inserted",
50
+ "Issues"=>[],
51
+ "Data"=>
52
+ {"Email"=>"alice@example.com", "GroupName"=>"my group", "Client"=>"54321"},
53
+ "InsertID"=>12345}
54
+ end
55
+
56
+ it do
57
+ client = status_cake do |stub|
58
+ stub.put('/API/ContactGroups/Update') do |env|
59
+ expect(env.request_headers).to eq form_request_headers
60
+ expect(env.body).to eq URI.encode_www_form(params.sort)
61
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
62
+ end
63
+ end
64
+
65
+ expect(client.contactgroups_update(params)).to eq response
66
+ end
67
+ end
68
+
69
+ describe '/API/ContactGroups' do
70
+ let(:response) do
71
+ [{"GroupName"=>"Pushover Test",
72
+ "Emails"=>["team@trafficcake.com"],
73
+ "Mobiles"=>[],
74
+ "Boxcar"=>"",
75
+ "Pushover"=>"gZh7mBkRIH4CsxWDwvkLBwlEZpxfpZ",
76
+ "ContactID"=>5,
77
+ "PingURL"=>"",
78
+ "DesktopAlert"=>1}]
79
+ end
80
+
81
+ it do
82
+ client = status_cake do |stub|
83
+ stub.get('/API/ContactGroups') do |env|
84
+ expect(env.request_headers).to eq request_headers
85
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
86
+ end
87
+ end
88
+
89
+ expect(client.contactgroups).to eq response
90
+ end
91
+ end
92
+
93
+ describe '/API/Tests/Checks' do
94
+ let(:params) do
95
+ {TestID: 241}
96
+ end
97
+
98
+ let(:response) do
99
+ {"3986660001"=>{"Location"=>"WADA3", "Time"=>1413285656, "Status"=>200},
100
+ "3027990001"=>{"Location"=>"DOUK2", "Time"=>1413285239, "Status"=>200},
101
+ "3322390001"=>{"Location"=>"UK50", "Time"=>1413285124, "Status"=>200}}
102
+ end
103
+
104
+ it do
105
+ client = status_cake do |stub|
106
+ stub.get('/API/Tests/Checks') do |env|
107
+ expect(env.request_headers).to eq request_headers
108
+ expect(env.params).to eq stringify_hash(params)
109
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
110
+ end
111
+ end
112
+
113
+ expect(client.tests_checks(params)).to eq response
114
+ end
115
+ end
116
+
117
+ describe '/API/Tests/Periods' do
118
+ let(:params) do
119
+ {TestID: 241}
120
+ end
121
+
122
+ let(:response) do
123
+ {"Start"=>"2013-02-24 16:01:46", "End"=>"0000-00-00 00:00:00", "Type"=>"Up"}
124
+ end
125
+
126
+ it do
127
+ client = status_cake do |stub|
128
+ stub.get('/API/Tests/Periods') do |env|
129
+ expect(env.request_headers).to eq request_headers
130
+ expect(env.params).to eq stringify_hash(params)
131
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
132
+ end
133
+ end
134
+
135
+ expect(client.tests_periods(params)).to eq response
136
+ end
137
+ end
138
+
139
+ describe '/API/Tests' do
140
+ let(:response) do
141
+ [{"TestID"=>28110,
142
+ "Paused"=>false,
143
+ "TestType"=>"HTTP",
144
+ "WebsiteName"=>"Test Period Data",
145
+ "ContactGroup"=>nil,
146
+ "ContactID"=>0,
147
+ "Status"=>"Up",
148
+ "Uptime"=>100}]
149
+ end
150
+
151
+ it do
152
+ client = status_cake do |stub|
153
+ stub.get('/API/Tests') do |env|
154
+ expect(env.request_headers).to eq request_headers
155
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
156
+ end
157
+ end
158
+
159
+ expect(client.tests).to eq response
160
+ end
161
+ end
162
+
163
+ describe '/API/Tests/Details' do
164
+ let(:params) do
165
+ {TestID: 241}
166
+ end
167
+
168
+ let(:response) do
169
+ {"TestID"=>6735,
170
+ "TestType"=>"HTTP",
171
+ "Paused"=>false,
172
+ "WebsiteName"=>"NL",
173
+ "ContactGroup"=>"StatusCake Alerts",
174
+ "ContactID"=>536,
175
+ "Status"=>"Up",
176
+ "Uptime"=>0,
177
+ "CheckRate"=>1,
178
+ "Timeout"=>40,
179
+ "LogoImage"=>"",
180
+ "WebsiteHost"=>"Various",
181
+ "NodeLocations"=>["UK", "JP", "SG1", "SLC"],
182
+ "FindString"=>"",
183
+ "DoNotFind"=>false,
184
+ "LastTested"=>"2013-01-20 14:38:18",
185
+ "NextLocation"=>"USNY",
186
+ "Processing"=>false,
187
+ "ProcessingState"=>"Pretest",
188
+ "ProcessingOn"=>"dalas.localdomain",
189
+ "DownTimes"=>"0"}
190
+ end
191
+
192
+ it do
193
+ client = status_cake do |stub|
194
+ stub.get('/API/Tests/Details') do |env|
195
+ expect(env.request_headers).to eq request_headers
196
+ expect(env.params).to eq stringify_hash(params)
197
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
198
+ end
199
+ end
200
+
201
+ expect(client.tests_details(params)).to eq response
202
+ end
203
+ end
204
+
205
+ describe '/API/Tests/Details (delete)' do
206
+ let(:params) do
207
+ {TestID: 241}
208
+ end
209
+
210
+ let(:response) do
211
+ {"TestID"=>6735,
212
+ "Affected"=>1,
213
+ "Success"=>true,
214
+ "Message"=>"This Check Has Been Deleted. It can not be recovered."}
215
+ end
216
+
217
+ it do
218
+ client = status_cake do |stub|
219
+ stub.delete('/API/Tests/Details') do |env|
220
+ expect(env.request_headers).to eq request_headers
221
+ expect(env.params).to eq stringify_hash(params)
222
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
223
+ end
224
+ end
225
+
226
+ expect(client.tests_details(params.merge(method: :delete))).to eq response
227
+ end
228
+ end
229
+
230
+ describe '/API/Tests/Update' do
231
+ let(:params) do
232
+ {
233
+ WebsiteName: 'Example Domain',
234
+ WebsiteURL: 'http://example.com',
235
+ CheckRate: 300,
236
+ TestType: :HTTP,
237
+ }
238
+ end
239
+
240
+ let(:response) do
241
+ {"Success"=>true,
242
+ "Message"=>"Test Inserted",
243
+ "Issues"=>nil,
244
+ "Data"=>
245
+ {"WebsiteName"=>"Example Domain",
246
+ "WebsiteURL"=>"http://example.com",
247
+ "CheckRate"=>"300",
248
+ "TestType"=>"HTTP",
249
+ "Client"=>"12345"},
250
+ "InsertID"=>7555}
251
+ end
252
+
253
+ it do
254
+ client = status_cake do |stub|
255
+ stub.put('/API/Tests/Update') do |env|
256
+ expect(env.request_headers).to eq form_request_headers
257
+ expect(env.body).to eq URI.encode_www_form(params.sort)
258
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
259
+ end
260
+ end
261
+
262
+ expect(client.tests_update(params)).to eq response
263
+ end
264
+ end
265
+
266
+ describe '/API/Locations/json' do
267
+ describe '#locations_json' do
268
+ let(:response) do
269
+ {"1"=>{"guid"=>"8", "servercode"=>"UK", "title"=>"England, London", "ip"=>"37.122.208.79", "countryiso"=>"GB", "status"=>"Up"}, "2"=>{"guid"=>"3", "servercode"=>"JP", "title"=>"Japan, Tyoko", "ip"=>"50.31.240.172", "countryiso"=>"JP", "status"=>"Up"}, "3"=>{"guid"=>"4", "servercode"=>"SG1", "title"=>"Singapore", "ip"=>"199.195.193.112", "countryiso"=>"SG", "status"=>"Up"}, "4"=>{"guid"=>"5", "servercode"=>"US", "title"=>"United States, San Jose", "ip"=>"199.195.192.240", "countryiso"=>"US", "status"=>"Up"}, "5"=>{"guid"=>"12", "servercode"=>"USNY", "title"=>"United States, New York", "ip"=>"216.155.131.57", "countryiso"=>"US", "status"=>"Up"}, "6"=>{"guid"=>"7", "servercode"=>"NE1", "title"=>"Netherlands, Amsterdam", "ip"=>"31.131.20.205", "countryiso"=>"NL", "status"=>"Up"}, "7"=>{"guid"=>"11", "servercode"=>"UK1", "title"=>"England, Manchester", "ip"=>"37.157.246.146", "countryiso"=>"GB", "status"=>"Up"}, "8"=>{"guid"=>"13", "servercode"=>"AUS", "title"=>"Australia, Sydney", "ip"=>"119.252.188.216", "countryiso"=>"AU", "status"=>"Up"}, "9"=>{"guid"=>"14", "servercode"=>"USDA", "title"=>"United States, Dallas", "ip"=>"173.255.139.226", "countryiso"=>"US", "status"=>"Up"}, "10"=>{"guid"=>"15", "servercode"=>"SLC", "title"=>"United States, Salt Lake City", "ip"=>"68.169.44.43", "countryiso"=>"US", "status"=>"Up"}, "11"=>{"guid"=>"16", "servercode"=>"UKCon", "title"=>"UK Robin", "ip"=>"109.123.82.244", "countryiso"=>"GB", "status"=>"Up"}, "12"=>{"guid"=>"17", "servercode"=>"SA", "title"=>"South Africa, Johannesburg", "ip"=>"41.86.108.228", "countryiso"=>"SA", "status"=>"Up"}, "13"=>{"guid"=>"18", "servercode"=>"DE", "title"=>"Germany, Berlin", "ip"=>"5.45.179.103", "countryiso"=>"DE", "status"=>"Up"}, "14"=>{"guid"=>"19", "servercode"=>"CA", "title"=>"Canada, Montreal", "ip"=>"199.167.128.80", "countryiso"=>"CA", "status"=>"Up"}, "15"=>{"guid"=>"20", "servercode"=>"FR", "title"=>"France, Roubaix", "ip"=>"37.59.151.154", "countryiso"=>"FR", "status"=>"Up"}, "16"=>{"guid"=>"21", "servercode"=>"NY2", "title"=>"United States, New York #2", "ip"=>"199.167.198.78", "countryiso"=>"US", "status"=>"Up"}, "17"=>{"guid"=>"22", "servercode"=>"NL2", "title"=>"Netherlands, Amsterdam #2", "ip"=>"176.56.230.59", "countryiso"=>"NL", "status"=>"Up"}, "18"=>{"guid"=>"23", "servercode"=>"NL3", "title"=>"Netherlands, Amsterdam #3", "ip"=>"198.144.121.195", "countryiso"=>"NL", "status"=>"Up"}, "19"=>{"guid"=>"24", "servercode"=>"SE", "title"=>"Sweden, Stockholm", "ip"=>"46.246.93.131", "countryiso"=>"SE", "status"=>"Up"}}
270
+ end
271
+
272
+ it do
273
+ client = status_cake do |stub|
274
+ stub.get('/API/Locations/json') do |env|
275
+ expect(env.request_headers).to eq request_headers
276
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
277
+ end
278
+ end
279
+
280
+ expect(client.locations_json).to eq response
281
+ end
282
+ end
283
+
284
+ describe '#locations' do
285
+ let(:response) do
286
+ {"1"=>{"guid"=>"8", "servercode"=>"UK", "title"=>"England, London", "ip"=>"37.122.208.79", "countryiso"=>"GB", "status"=>"Up"}, "2"=>{"guid"=>"3", "servercode"=>"JP", "title"=>"Japan, Tyoko", "ip"=>"50.31.240.172", "countryiso"=>"JP", "status"=>"Up"}, "3"=>{"guid"=>"4", "servercode"=>"SG1", "title"=>"Singapore", "ip"=>"199.195.193.112", "countryiso"=>"SG", "status"=>"Up"}, "4"=>{"guid"=>"5", "servercode"=>"US", "title"=>"United States, San Jose", "ip"=>"199.195.192.240", "countryiso"=>"US", "status"=>"Up"}, "5"=>{"guid"=>"12", "servercode"=>"USNY", "title"=>"United States, New York", "ip"=>"216.155.131.57", "countryiso"=>"US", "status"=>"Up"}, "6"=>{"guid"=>"7", "servercode"=>"NE1", "title"=>"Netherlands, Amsterdam", "ip"=>"31.131.20.205", "countryiso"=>"NL", "status"=>"Up"}, "7"=>{"guid"=>"11", "servercode"=>"UK1", "title"=>"England, Manchester", "ip"=>"37.157.246.146", "countryiso"=>"GB", "status"=>"Up"}, "8"=>{"guid"=>"13", "servercode"=>"AUS", "title"=>"Australia, Sydney", "ip"=>"119.252.188.216", "countryiso"=>"AU", "status"=>"Up"}, "9"=>{"guid"=>"14", "servercode"=>"USDA", "title"=>"United States, Dallas", "ip"=>"173.255.139.226", "countryiso"=>"US", "status"=>"Up"}, "10"=>{"guid"=>"15", "servercode"=>"SLC", "title"=>"United States, Salt Lake City", "ip"=>"68.169.44.43", "countryiso"=>"US", "status"=>"Up"}, "11"=>{"guid"=>"16", "servercode"=>"UKCon", "title"=>"UK Robin", "ip"=>"109.123.82.244", "countryiso"=>"GB", "status"=>"Up"}, "12"=>{"guid"=>"17", "servercode"=>"SA", "title"=>"South Africa, Johannesburg", "ip"=>"41.86.108.228", "countryiso"=>"SA", "status"=>"Up"}, "13"=>{"guid"=>"18", "servercode"=>"DE", "title"=>"Germany, Berlin", "ip"=>"5.45.179.103", "countryiso"=>"DE", "status"=>"Up"}, "14"=>{"guid"=>"19", "servercode"=>"CA", "title"=>"Canada, Montreal", "ip"=>"199.167.128.80", "countryiso"=>"CA", "status"=>"Up"}, "15"=>{"guid"=>"20", "servercode"=>"FR", "title"=>"France, Roubaix", "ip"=>"37.59.151.154", "countryiso"=>"FR", "status"=>"Up"}, "16"=>{"guid"=>"21", "servercode"=>"NY2", "title"=>"United States, New York #2", "ip"=>"199.167.198.78", "countryiso"=>"US", "status"=>"Up"}, "17"=>{"guid"=>"22", "servercode"=>"NL2", "title"=>"Netherlands, Amsterdam #2", "ip"=>"176.56.230.59", "countryiso"=>"NL", "status"=>"Up"}, "18"=>{"guid"=>"23", "servercode"=>"NL3", "title"=>"Netherlands, Amsterdam #3", "ip"=>"198.144.121.195", "countryiso"=>"NL", "status"=>"Up"}, "19"=>{"guid"=>"24", "servercode"=>"SE", "title"=>"Sweden, Stockholm", "ip"=>"46.246.93.131", "countryiso"=>"SE", "status"=>"Up"}}
287
+ end
288
+
289
+ it do
290
+ client = status_cake do |stub|
291
+ stub.get('/API/Locations/json') do |env|
292
+ expect(env.request_headers).to eq request_headers
293
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
294
+ end
295
+ end
296
+
297
+ expect(client.locations).to eq response
298
+ end
299
+ end
300
+ end
301
+
302
+ describe '/API/Locations/txt' do
303
+ let(:response) do
304
+ "37.122.208.79\n50.31.240.172\n199.195.193.112\n199.195.192.240\n216.155.131.57\n31.131.20.205\n37.157.246.146\n119.252.188.216\n173.255.139.226\n68.169.44.43\n109.123.82.244\n41.86.108.228\n5.45.179.103\n199.167.128.80\n37.59.151.154\n199.167.198.78\n176.56.230.59\n198.144.121.195\n46.246.93.131"
305
+ end
306
+
307
+ it do
308
+ client = status_cake do |stub|
309
+ stub.get('/API/Locations/txt') do |env|
310
+ expect(env.request_headers).to eq request_headers
311
+ [200, {'Content-Type' => 'text/plain'}, response]
312
+ end
313
+ end
314
+
315
+ expect(client.locations_txt).to eq response
316
+ end
317
+ end
318
+
319
+ describe '/API/Locations/xml' do
320
+ let(:response) do
321
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"2.0\"\nxmlns:atom=\"https://www.w3.org/2005/Atom\">\n<channel>\n <title>Test Locations</title>\n <link>https://www.statuscake.com</link>\n <description>These are the test locations and IPs. You can use the IP numbers in your firewall rules</description>\n <language>en</language><item>\n <guid isPermaLink=\"false\">Location_8</guid>\n <title>England, London</title>\n <ip>37.122.208.79</ip>\n <countryiso>GB</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_3</guid>\n <title>Japan, Tyoko</title>\n <ip>50.31.240.172</ip>\n <countryiso>JP</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_4</guid>\n <title>Singapore</title>\n <ip>199.195.193.112</ip>\n <countryiso>SG</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_5</guid>\n <title>United States, San Jose</title>\n <ip>199.195.192.240</ip>\n <countryiso>US</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_12</guid>\n <title>United States, New York</title>\n <ip>216.155.131.57</ip>\n <countryiso>US</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_7</guid>\n <title>Netherlands, Amsterdam</title>\n <ip>31.131.20.205</ip>\n <countryiso>NL</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_11</guid>\n <title>England, Manchester</title>\n <ip>37.157.246.146</ip>\n <countryiso>GB</countryiso>\n <status>Up</status>\n</item><item <guid isPermaLink=\"false\">Location_13</guid>\n <title>Australia, Sydney</title>\n <ip>119.252.188.216</ip>\n <countryiso>AU</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_14</guid>\n <title>United States, Dallas</title>\n <ip>173.255.139.226</ip>\n <countryiso>US</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_15</guid>\n <title>United States, Salt Lake City</title>\n <ip>68.169.44.43</ip>\n <countryiso>US</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_16</guid>\n <title>UK Robin</title>\n <ip>109.123.82.244</ip>\n <countryiso>GB</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\"n_17</guid>\n <title>South Africa, Johannesburg</title>\n <ip>41.86.108.228</ip>\n <countryiso>SA</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_18</guid>\n <title>Germany, Berlin</title>\n <ip>5.45.179.103</ip>\n <countryiso>DE</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_19</guid>\n <title>Canada, Montreal</title>\n <ip>199.167.128.80</ip>\n <countryiso>CA</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_20</guid>\n <title>France, Roubaix</title>\n <ip>37.59.151.154</ip>\n <countryiso>FR</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_21</guid>\n <title>United States <ip>199.167.198.78</ip>\n <countryiso>US</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_22</guid>\n <title>Netherlands, Amsterdam #2</title>\n <ip>176.56.230.59</ip>\n <countryiso>NL</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_23</guid>\n <title>Netherlands, Amsterdam #3</title>\n <ip>198.144.121.195</ip>\n <countryiso>NL</countryiso>\n <status>Up</status>\n</item><item>\n <guid isPermaLink=\"false\">Location_24</guid>\n <title>Sweden, Stockholm</title>\n <ip>46.246.93.131</ip>\n <countryiso>SE</countryiso>\n <status>Up</status>\n</item></channel>\n </rss>"
322
+ end
323
+
324
+ it do
325
+ client = status_cake do |stub|
326
+ stub.get('/API/Locations/xml') do |env|
327
+ expect(env.request_headers).to eq request_headers
328
+ [200, {'Content-Type' => 'text/xml'}, response]
329
+ end
330
+ end
331
+
332
+ expect(client.locations_xml).to eq response
333
+ end
334
+ end
335
+
336
+ describe '/API/Auth' do
337
+ let(:response) do
338
+ {"Success"=>true,
339
+ "Details"=>
340
+ {"Username"=>"StatusCake",
341
+ "FirstName"=>"Matthew",
342
+ "LastName"=>"Awesomeo",
343
+ "Plan"=>"BUSINESS",
344
+ "Timezone"=>"Europe/London",
345
+ "CountryCode"=>"GB"}}
346
+ end
347
+
348
+ it do
349
+ client = status_cake do |stub|
350
+ stub.get('/API/Auth') do |env|
351
+ expect(env.request_headers).to eq request_headers
352
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
353
+ end
354
+ end
355
+
356
+ expect(client.auth).to eq response
357
+ end
358
+ end
359
+
360
+ context 'when error happen' do
361
+ let(:response) do
362
+ {"ErrNo"=>1, "Error"=>"REQUEST[TestID] provided not linked to this account"}
363
+ end
364
+
365
+ it do
366
+ client = status_cake do |stub|
367
+ stub.get('/API/Alerts') do |env|
368
+ expect(env.request_headers).to eq request_headers
369
+ [200, {'Content-Type' => 'application/json'}, JSON.dump(response)]
370
+ end
371
+ end
372
+
373
+ expect {
374
+ client.alerts
375
+ }.to raise_error(StatusCake::Error, 'REQUEST[TestID] provided not linked to this account')
376
+ end
377
+ end
378
+
379
+ context 'when status is not 200' do
380
+ it do
381
+ client = status_cake do |stub|
382
+ stub.get('/API/Alerts') do |env|
383
+ expect(env.request_headers).to eq request_headers
384
+ [500, {}, 'Internal Server Error']
385
+ end
386
+ end
387
+
388
+ expect {
389
+ client.alerts
390
+ }.to raise_error
391
+ end
392
+ end
393
+ end
@@ -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 'statuscake/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'statuscake'
8
+ spec.version = StatusCake::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sugawara@cookpad.com']
11
+ spec.summary = %q{It is a StatusCake API client library.}
12
+ spec.description = %q{It is a StatusCake API client library.}
13
+ spec.homepage = 'https://github.com/winebarrel/statuscake'
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,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statuscake
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: 2015-01-02 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: It is a StatusCake API client library.
84
+ email:
85
+ - sugawara@cookpad.com
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/statuscake.rb
98
+ - lib/statuscake/client.rb
99
+ - lib/statuscake/error.rb
100
+ - lib/statuscake/version.rb
101
+ - spec/spec_helper.rb
102
+ - spec/statuscake_spec.rb
103
+ - statuscake.gemspec
104
+ homepage: https://github.com/winebarrel/statuscake
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.14
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: It is a StatusCake API client library.
128
+ test_files:
129
+ - spec/spec_helper.rb
130
+ - spec/statuscake_spec.rb