beeper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/beeper/client.rb +21 -12
- data/lib/beeper/version.rb +1 -1
- data/spec/beeper/client_spec.rb +51 -37
- data/spec/cassettes/Beeper_Client.yml +50 -9
- metadata +4 -4
data/lib/beeper/client.rb
CHANGED
@@ -3,28 +3,30 @@ require 'faraday_middleware'
|
|
3
3
|
|
4
4
|
module Beeper
|
5
5
|
class Client
|
6
|
+
COLLECTIONS = [:incidents, :services, :maintenance_windows].freeze
|
7
|
+
|
6
8
|
attr_accessor :api_key, :subdomain, :requester_id
|
7
9
|
|
8
10
|
def configured?
|
9
11
|
!@api_key.nil? && !@subdomain.nil?
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def maintenance_windows(options={})
|
21
|
-
get(:maintenance_windows, options)
|
14
|
+
COLLECTIONS.each do |collection|
|
15
|
+
class_eval <<-RB
|
16
|
+
def #{collection}(options={})
|
17
|
+
get(:#{collection}, options)
|
18
|
+
end
|
19
|
+
RB
|
22
20
|
end
|
23
21
|
|
24
22
|
def create_maintenance_window(maintenance_window)
|
25
23
|
post(:maintenance_windows, maintenance_window)
|
26
24
|
end
|
27
25
|
|
26
|
+
def delete_maintenance_window(id)
|
27
|
+
delete(:maintenance_windows, { :id => id })
|
28
|
+
end
|
29
|
+
|
28
30
|
private
|
29
31
|
|
30
32
|
def get(collection, options={})
|
@@ -33,10 +35,17 @@ module Beeper
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def post(collection, options={})
|
36
|
-
|
38
|
+
single_collection = collection.to_s[0..-2]
|
39
|
+
options = authenticated_post_options.merge(single_collection.to_sym => options)
|
37
40
|
|
38
41
|
results = connection.post(collection.to_s, options)
|
39
|
-
results.body
|
42
|
+
results.body.send(single_collection.to_sym)
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete(collection, options={})
|
46
|
+
id = options.delete(:id)
|
47
|
+
results = connection.delete("#{collection}/#{id}", options)
|
48
|
+
results.success?
|
40
49
|
end
|
41
50
|
|
42
51
|
def authenticated_post_options
|
data/lib/beeper/version.rb
CHANGED
data/spec/beeper/client_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
3
|
describe Beeper::Client do
|
4
|
-
use_vcr_cassette
|
4
|
+
use_vcr_cassette :record => :new_episodes
|
5
5
|
|
6
6
|
let(:client) do
|
7
7
|
Beeper.configure do |c|
|
@@ -40,47 +40,61 @@ describe Beeper::Client do
|
|
40
40
|
:service_ids => ["POM55DP"]
|
41
41
|
).should == new_maintenance_window
|
42
42
|
end
|
43
|
+
|
44
|
+
it "should be able to delete" do
|
45
|
+
client = Beeper.configure do |c|
|
46
|
+
c.api_key = Beeper::Test::API_KEY
|
47
|
+
c.subdomain = "outright"
|
48
|
+
c.requester_id = Beeper::Test::REQUESTER_ID
|
49
|
+
end
|
50
|
+
|
51
|
+
window = client.create_maintenance_window(
|
52
|
+
:start_time => Time.now,
|
53
|
+
:end_time => Time.now + 3600,
|
54
|
+
:service_ids => ["POM55DP"]
|
55
|
+
)
|
56
|
+
|
57
|
+
client.delete_maintenance_window(window.id).should == true
|
58
|
+
end
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
46
62
|
def new_maintenance_window
|
47
63
|
{
|
48
|
-
"
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
"
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
]
|
83
|
-
}
|
64
|
+
"id"=>"PO7EV8B",
|
65
|
+
"sequence_number"=>2,
|
66
|
+
"start_time"=>"2012-12-18T15:53:55-08:00",
|
67
|
+
"end_time"=>"2012-12-18T16:53:54-08:00",
|
68
|
+
"description"=>nil,
|
69
|
+
"created_by"=>{
|
70
|
+
"id"=>"#{Beeper::Test::REQUESTER_ID}",
|
71
|
+
"name"=>"Bob Smith",
|
72
|
+
"email"=>"bob@example.com",
|
73
|
+
"time_zone"=>"Pacific Time (US & Canada)",
|
74
|
+
"color"=>"green",
|
75
|
+
"role"=>"admin",
|
76
|
+
"avatar_url"=>"https://secure.gravatar.com/avatar/71c3bbda60a46a241bf9a2d68e41cbec.png?d=mm&r=PG",
|
77
|
+
"user_url"=>"/users/#{Beeper::Test::REQUESTER_ID}",
|
78
|
+
"invitation_sent"=>false,
|
79
|
+
"marketing_opt_out"=>false
|
80
|
+
},
|
81
|
+
"services"=>[
|
82
|
+
{
|
83
|
+
"id"=>"POM55DP",
|
84
|
+
"name"=>"Application",
|
85
|
+
"service_url"=>"/services/POM55DP",
|
86
|
+
"service_key"=>"application@outright.pagerduty.com",
|
87
|
+
"auto_resolve_timeout"=>14400,
|
88
|
+
"acknowledgement_timeout"=>600,
|
89
|
+
"created_at"=>"2012-12-01T13:59:54-08:00",
|
90
|
+
"status"=>"maintenance",
|
91
|
+
"last_incident_timestamp"=>nil,
|
92
|
+
"email_incident_creation"=>"on_new_email_subject",
|
93
|
+
"incident_counts"=>{"triggered"=>0, "acknowledged"=>0, "resolved"=>0, "total"=>0},
|
94
|
+
"email_filter_mode"=>"all-email",
|
95
|
+
"type"=>"pingdom"
|
96
|
+
}
|
97
|
+
]
|
84
98
|
}
|
85
99
|
end
|
86
100
|
|
@@ -200,7 +200,7 @@ http_interactions:
|
|
200
200
|
body:
|
201
201
|
encoding: UTF-8
|
202
202
|
string: ! '{"requester_id":"REQUESTER_ID","maintenance_window":{"start_time":"2012-12-18
|
203
|
-
|
203
|
+
15:53:54 -0800","end_time":"2012-12-18 16:53:54 -0800","service_ids":["POM55DP"]}}'
|
204
204
|
headers:
|
205
205
|
Authorization:
|
206
206
|
- Token token="API_KEY"
|
@@ -214,7 +214,7 @@ http_interactions:
|
|
214
214
|
server:
|
215
215
|
- nginx/1.0.14
|
216
216
|
date:
|
217
|
-
- Tue, 18 Dec 2012
|
217
|
+
- Tue, 18 Dec 2012 23:53:55 GMT
|
218
218
|
content-type:
|
219
219
|
- application/json; charset=utf-8
|
220
220
|
transfer-encoding:
|
@@ -226,24 +226,65 @@ http_interactions:
|
|
226
226
|
x-ua-compatible:
|
227
227
|
- IE=Edge,chrome=1
|
228
228
|
etag:
|
229
|
-
- ! '"
|
229
|
+
- ! '"85f0ed1364f971210f88f800c05731b5"'
|
230
230
|
cache-control:
|
231
231
|
- max-age=0, private, must-revalidate
|
232
232
|
set-cookie:
|
233
|
-
- _pagerduty_session=
|
234
|
-
path=/; HttpOnly, uid=
|
233
|
+
- _pagerduty_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTgwNGMxMzA5YTg5NzRhZTFlMTNjY2ViMzQ4YmFkZDhjBjsAVEkiHHdhcmRlbi51c2VyLmFwaV9rZXkua2V5BjsAVFsISSILQXBpS2V5BjsARlsGaQKUATA%3D--bfb27f246317ea47199d087d8cd2d7435fb3a2e6;
|
234
|
+
path=/; HttpOnly, uid=CvgRmlDRAhPBtCi9Wd+bAg==; expires=Thu, 31-Dec-37 23:55:55
|
235
235
|
GMT; domain=pagerduty.com; path=/
|
236
236
|
x-request-id:
|
237
|
-
-
|
237
|
+
- a05701e5a910ce5848a5b45a9b5943eb
|
238
238
|
x-runtime:
|
239
|
-
- '0.
|
239
|
+
- '0.204289'
|
240
240
|
x-rack-cache:
|
241
241
|
- invalidate, pass
|
242
242
|
body:
|
243
243
|
encoding: US-ASCII
|
244
|
-
string: ! '{"maintenance_window":{"id":"
|
244
|
+
string: ! '{"maintenance_window":{"id":"PO7EV8B","sequence_number":2,"start_time":"2012-12-18T15:53:55-08:00","end_time":"2012-12-18T16:53:54-08:00","description":null,"created_by":{"id":"REQUESTER_ID","name":"Bob
|
245
245
|
Smith","email":"bob@example.com","time_zone":"Pacific Time (US & Canada)","color":"green","role":"admin","avatar_url":"https://secure.gravatar.com/avatar/71c3bbda60a46a241bf9a2d68e41cbec.png?d=mm&r=PG","user_url":"/users/REQUESTER_ID","invitation_sent":false,"marketing_opt_out":false},"services":[{"id":"POM55DP","name":"Application",
|
246
246
|
"service_url":"/services/POM55DP","service_key":"application@outright.pagerduty.com","auto_resolve_timeout":14400,"acknowledgement_timeout":600,"created_at":"2012-12-01T13:59:54-08:00","status":"maintenance","last_incident_timestamp":null,"email_incident_creation":"on_new_email_subject","incident_counts":{"triggered":0,"acknowledged":0,"resolved":0,"total":0},"email_filter_mode":"all-email","type":"pingdom"}]}}'
|
247
247
|
http_version:
|
248
|
-
recorded_at: Tue, 18 Dec 2012
|
248
|
+
recorded_at: Tue, 18 Dec 2012 23:53:55 GMT
|
249
|
+
- request:
|
250
|
+
method: delete
|
251
|
+
uri: https://outright.pagerduty.com/api/v1/maintenance_windows/PO7EV8B
|
252
|
+
body:
|
253
|
+
encoding: US-ASCII
|
254
|
+
string: ''
|
255
|
+
headers:
|
256
|
+
Authorization:
|
257
|
+
- Token token="API_KEY"
|
258
|
+
response:
|
259
|
+
status:
|
260
|
+
code: 204
|
261
|
+
message:
|
262
|
+
headers:
|
263
|
+
server:
|
264
|
+
- nginx/1.0.14
|
265
|
+
date:
|
266
|
+
- Tue, 18 Dec 2012 23:53:55 GMT
|
267
|
+
connection:
|
268
|
+
- keep-alive
|
269
|
+
status:
|
270
|
+
- 204 No Content
|
271
|
+
x-ua-compatible:
|
272
|
+
- IE=Edge,chrome=1
|
273
|
+
cache-control:
|
274
|
+
- no-cache
|
275
|
+
set-cookie:
|
276
|
+
- _pagerduty_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTdhYjU0ZjAxODlhOWQ1NmU0NDQ3MGMwMzJlNDc5YWU5BjsAVEkiHHdhcmRlbi51c2VyLmFwaV9rZXkua2V5BjsAVFsISSILQXBpS2V5BjsARlsGaQKUATA%3D--8a7a1fbad07f05003f61ec0a930004dbedda4203;
|
277
|
+
path=/; HttpOnly, uid=CvgRmlDRAhPBtCi9Wd+iAg==; expires=Thu, 31-Dec-37 23:55:55
|
278
|
+
GMT; domain=pagerduty.com; path=/
|
279
|
+
x-request-id:
|
280
|
+
- dd3377e85640482f418d70dca8b3aed4
|
281
|
+
x-runtime:
|
282
|
+
- '0.140999'
|
283
|
+
x-rack-cache:
|
284
|
+
- invalidate, pass
|
285
|
+
body:
|
286
|
+
encoding: US-ASCII
|
287
|
+
string: ''
|
288
|
+
http_version:
|
289
|
+
recorded_at: Tue, 18 Dec 2012 23:53:55 GMT
|
249
290
|
recorded_with: VCR 2.3.0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -191,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
segments:
|
193
193
|
- 0
|
194
|
-
hash: -
|
194
|
+
hash: -2152703981749921555
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
none: false
|
197
197
|
requirements:
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
segments:
|
202
202
|
- 0
|
203
|
-
hash: -
|
203
|
+
hash: -2152703981749921555
|
204
204
|
requirements: []
|
205
205
|
rubyforge_project:
|
206
206
|
rubygems_version: 1.8.24
|