pagerduty 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +16 -0
- data/lib/pagerduty/http_transport.rb +1 -1
- data/lib/pagerduty/version.rb +1 -1
- data/lib/pagerduty.rb +1 -1
- data/pagerduty.gemspec +2 -1
- data/spec/pagerduty/http_transport_spec.rb +9 -9
- data/spec/pagerduty_spec.rb +34 -35
- data/spec/spec_helper.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79dcf1ccf6b3223a64d07a152f55b8a0b6a99f26
|
4
|
+
data.tar.gz: bd86c131d6b99b475ffe82082a307defff905ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d66e8ea5d2d101c6d5c484c51b5bbc0d9f7b462f2ef2a449344f7e8dd8b0b0b411fb336f978f2e28bf1d42b0ef46d1801f7ff04b2b953e0e9b046a8d71891c
|
7
|
+
data.tar.gz: 0d6614d6104796bda5868fc529da1ac8b75de6688c67df41fda5aae39e3a386654ad49178304a375483465c9585935a41b33327ac2c6b48b92db15f378e30400
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# pagerduty
|
2
2
|
|
3
|
+
|
4
|
+
[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/envato/pagerduty/blob/master/LICENSE.txt)
|
3
5
|
[![Gem Version](https://badge.fury.io/rb/pagerduty.svg)](http://badge.fury.io/rb/pagerduty)
|
4
6
|
[![Build Status](https://travis-ci.org/envato/pagerduty.svg?branch=master)](https://travis-ci.org/envato/pagerduty)
|
5
7
|
|
@@ -54,6 +56,20 @@ pagerduty.trigger(
|
|
54
56
|
)
|
55
57
|
```
|
56
58
|
|
59
|
+
### Debugging Error Responses
|
60
|
+
|
61
|
+
The gem doesn't encapsulate HTTP error responses from PagerDuty. Here's how to go about debugging these unhappy cases:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
begin
|
65
|
+
pagerduty.trigger("incident description")
|
66
|
+
rescue Net::HTTPServerException => error
|
67
|
+
error.response.code #=> "400"
|
68
|
+
error.response.message #=> "Bad Request"
|
69
|
+
error.response.body #=> "{\"status\":\"invalid event\",\"message\":\"Event object is invalid\",\"errors\":[\"Service key is the wrong length (should be 32 characters)\"]}"
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
57
73
|
### Upgrading to Version 2.0.0
|
58
74
|
|
59
75
|
The API has changed in three ways that you need to be aware of:
|
@@ -11,7 +11,7 @@ module Pagerduty::HttpTransport
|
|
11
11
|
PORT = 443
|
12
12
|
PATH = "/generic/2010-04-15/create_event.json"
|
13
13
|
|
14
|
-
def
|
14
|
+
def send_payload(payload = {})
|
15
15
|
response = post payload.to_json
|
16
16
|
response.error! unless transported?(response)
|
17
17
|
JSON.parse(response.body)
|
data/lib/pagerduty/version.rb
CHANGED
data/lib/pagerduty.rb
CHANGED
data/pagerduty.gemspec
CHANGED
@@ -24,7 +24,8 @@ https://github.com/envato/pagerduty#upgrading-to-version-200
|
|
24
24
|
gem.require_paths = ["lib"]
|
25
25
|
|
26
26
|
gem.add_runtime_dependency "json", ">= 1.7.7"
|
27
|
-
gem.add_development_dependency "bundler", "~> 1.
|
27
|
+
gem.add_development_dependency "bundler", "~> 1.7"
|
28
28
|
gem.add_development_dependency "rake"
|
29
|
+
gem.add_development_dependency "rspec"
|
29
30
|
gem.add_development_dependency "rspec-given"
|
30
31
|
end
|
@@ -5,12 +5,12 @@ describe Pagerduty::HttpTransport do
|
|
5
5
|
Given(:http_transport) { Pagerduty::HttpTransport }
|
6
6
|
|
7
7
|
Given(:http) { double.as_null_object }
|
8
|
-
Given { http.
|
9
|
-
Given { Net::HTTP.
|
8
|
+
Given { allow(http).to receive(:request).and_return(standard_response) }
|
9
|
+
Given { allow(Net::HTTP).to receive(:new).and_return(http) }
|
10
10
|
Given(:post) { double.as_null_object }
|
11
|
-
Given { Net::HTTP::Post.
|
11
|
+
Given { allow(Net::HTTP::Post).to receive(:new).and_return(post) }
|
12
12
|
|
13
|
-
describe "::
|
13
|
+
describe "::send_payload" do
|
14
14
|
Given(:payload) { {
|
15
15
|
event_type: "trigger",
|
16
16
|
service_key: "test-srvc-key",
|
@@ -18,7 +18,7 @@ describe Pagerduty::HttpTransport do
|
|
18
18
|
details: { key: "value" },
|
19
19
|
} }
|
20
20
|
|
21
|
-
When(:response) { http_transport.
|
21
|
+
When(:response) { http_transport.send_payload(payload) }
|
22
22
|
|
23
23
|
describe "provides the correct request" do
|
24
24
|
Then {
|
@@ -31,7 +31,7 @@ describe Pagerduty::HttpTransport do
|
|
31
31
|
describe "handles all responses" do
|
32
32
|
|
33
33
|
context "PagerDuty successfully creates the incident" do
|
34
|
-
Given { http.
|
34
|
+
Given { allow(http).to receive(:request).and_return(response_with_body(<<-JSON)) }
|
35
35
|
{
|
36
36
|
"status": "success",
|
37
37
|
"incident_key": "My Incident Key",
|
@@ -43,7 +43,7 @@ describe Pagerduty::HttpTransport do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context "PagerDuty fails to create the incident" do
|
46
|
-
Given { http.
|
46
|
+
Given { allow(http).to receive(:request).and_return(response_with_body(<<-JSON)) }
|
47
47
|
{
|
48
48
|
"status": "failure",
|
49
49
|
"message": "Event not processed"
|
@@ -54,7 +54,7 @@ describe Pagerduty::HttpTransport do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context "PagerDuty responds with HTTP bad request" do
|
57
|
-
Given { http.
|
57
|
+
Given { allow(http).to receive(:request).and_return(bad_request) }
|
58
58
|
Then { expect(response).to have_raised Net::HTTPServerException }
|
59
59
|
end
|
60
60
|
end
|
@@ -78,7 +78,7 @@ describe Pagerduty::HttpTransport do
|
|
78
78
|
|
79
79
|
def response_with_body(body)
|
80
80
|
response = Net::HTTPSuccess.new 1.1, "200", "OK"
|
81
|
-
response.
|
81
|
+
allow(response).to receive(:body).and_return(body)
|
82
82
|
response
|
83
83
|
end
|
84
84
|
|
data/spec/pagerduty_spec.rb
CHANGED
@@ -6,17 +6,17 @@ describe Pagerduty do
|
|
6
6
|
Given(:service_key) { "a-test-service-key" }
|
7
7
|
|
8
8
|
Given(:transport) { double.as_null_object }
|
9
|
-
Given { Pagerduty.
|
9
|
+
Given { allow(Pagerduty).to receive(:transport).and_return(transport) }
|
10
10
|
|
11
11
|
describe "#trigger" do
|
12
12
|
|
13
13
|
describe "provides the correct request" do
|
14
|
-
Given { transport.
|
14
|
+
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
|
15
15
|
|
16
16
|
context "no options" do
|
17
17
|
When(:incident) { pagerduty.trigger("a-test-description") }
|
18
18
|
Then {
|
19
|
-
expect(transport).to have_received(:
|
19
|
+
expect(transport).to have_received(:send_payload).with(
|
20
20
|
service_key: "a-test-service-key",
|
21
21
|
event_type: "trigger",
|
22
22
|
description: "a-test-description",
|
@@ -35,7 +35,7 @@ describe Pagerduty do
|
|
35
35
|
)
|
36
36
|
}
|
37
37
|
Then {
|
38
|
-
expect(transport).to have_received(:
|
38
|
+
expect(transport).to have_received(:send_payload).with(
|
39
39
|
service_key: "a-test-service-key",
|
40
40
|
event_type: "trigger",
|
41
41
|
description: "a-test-description",
|
@@ -51,12 +51,11 @@ describe Pagerduty do
|
|
51
51
|
describe "handles all responses" do
|
52
52
|
|
53
53
|
context "PagerDuty successfully creates the incident" do
|
54
|
-
Given {
|
55
|
-
transport.stub(:send => {
|
54
|
+
Given { allow(transport).to receive(:send_payload).and_return(
|
56
55
|
"status" => "success",
|
57
56
|
"incident_key" => "My Incident Key",
|
58
57
|
"message" => "Event processed",
|
59
|
-
|
58
|
+
)
|
60
59
|
}
|
61
60
|
When(:incident) { pagerduty.trigger("description") }
|
62
61
|
Then { expect(incident).to be_a PagerdutyIncident }
|
@@ -66,17 +65,17 @@ describe Pagerduty do
|
|
66
65
|
|
67
66
|
context "PagerDuty fails to create the incident" do
|
68
67
|
Given {
|
69
|
-
transport.
|
68
|
+
allow(transport).to receive(:send_payload).and_return(
|
70
69
|
"status" => "failure",
|
71
|
-
"message" => "Event not processed"
|
72
|
-
|
70
|
+
"message" => "Event not processed"
|
71
|
+
)
|
73
72
|
}
|
74
73
|
When(:incident) { pagerduty.trigger("description") }
|
75
74
|
Then { expect(incident).to have_raised PagerdutyException }
|
76
75
|
end
|
77
76
|
|
78
77
|
context "PagerDuty responds with HTTP bad request" do
|
79
|
-
Given { transport.
|
78
|
+
Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
|
80
79
|
When(:incident) { pagerduty.trigger("description") }
|
81
80
|
Then { expect(incident).to have_raised Net::HTTPServerException }
|
82
81
|
end
|
@@ -98,12 +97,12 @@ describe Pagerduty do
|
|
98
97
|
describe "#acknowledge" do
|
99
98
|
|
100
99
|
describe "provides the correct request" do
|
101
|
-
Given { transport.
|
100
|
+
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
|
102
101
|
|
103
102
|
context "no args" do
|
104
103
|
When(:acknowledge) { incident.acknowledge }
|
105
104
|
Then {
|
106
|
-
expect(transport).to have_received(:
|
105
|
+
expect(transport).to have_received(:send_payload).with(
|
107
106
|
event_type: "acknowledge",
|
108
107
|
service_key: "a-test-service-key",
|
109
108
|
incident_key: "a-test-incident-key",
|
@@ -114,7 +113,7 @@ describe Pagerduty do
|
|
114
113
|
context "a description" do
|
115
114
|
When(:acknowledge) { incident.acknowledge("test-description") }
|
116
115
|
Then {
|
117
|
-
expect(transport).to have_received(:
|
116
|
+
expect(transport).to have_received(:send_payload).with(
|
118
117
|
event_type: "acknowledge",
|
119
118
|
service_key: "a-test-service-key",
|
120
119
|
incident_key: "a-test-incident-key",
|
@@ -126,7 +125,7 @@ describe Pagerduty do
|
|
126
125
|
context "a description and details" do
|
127
126
|
When(:acknowledge) { incident.acknowledge("test-description", { my: "detail" }) }
|
128
127
|
Then {
|
129
|
-
expect(transport).to have_received(:
|
128
|
+
expect(transport).to have_received(:send_payload).with(
|
130
129
|
event_type: "acknowledge",
|
131
130
|
service_key: "a-test-service-key",
|
132
131
|
incident_key: "a-test-incident-key",
|
@@ -141,11 +140,11 @@ describe Pagerduty do
|
|
141
140
|
|
142
141
|
context "PagerDuty successfully acknowledges the incident" do
|
143
142
|
Given {
|
144
|
-
transport.
|
143
|
+
allow(transport).to receive(:send_payload).and_return(
|
145
144
|
"status" => "success",
|
146
145
|
"incident_key" => "a-test-incident-key",
|
147
|
-
"message" => "Event acknowledged"
|
148
|
-
|
146
|
+
"message" => "Event acknowledged"
|
147
|
+
)
|
149
148
|
}
|
150
149
|
When(:acknowledge) { incident.acknowledge }
|
151
150
|
Then { expect(acknowledge).to be incident}
|
@@ -153,18 +152,18 @@ describe Pagerduty do
|
|
153
152
|
|
154
153
|
context "PagerDuty fails to acknowledge the incident" do
|
155
154
|
Given {
|
156
|
-
transport.
|
155
|
+
allow(transport).to receive(:send_payload).and_return(
|
157
156
|
"status" => "failure",
|
158
157
|
"incident_key" => "a-test-incident-key",
|
159
158
|
"message" => "Event not acknowledged",
|
160
|
-
|
159
|
+
)
|
161
160
|
}
|
162
161
|
When(:acknowledge) { incident.acknowledge }
|
163
162
|
Then { expect(acknowledge).to have_failed PagerdutyException }
|
164
163
|
end
|
165
164
|
|
166
165
|
context "PagerDuty responds with HTTP bad request" do
|
167
|
-
Given { transport.
|
166
|
+
Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
|
168
167
|
When(:acknowledge) { incident.acknowledge }
|
169
168
|
Then { expect(acknowledge).to have_failed Net::HTTPServerException }
|
170
169
|
end
|
@@ -174,12 +173,12 @@ describe Pagerduty do
|
|
174
173
|
describe "#resolve" do
|
175
174
|
|
176
175
|
describe "provides the correct request" do
|
177
|
-
Given { transport.
|
176
|
+
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
|
178
177
|
|
179
178
|
context "no args" do
|
180
179
|
When(:resolve) { incident.resolve }
|
181
180
|
Then {
|
182
|
-
expect(transport).to have_received(:
|
181
|
+
expect(transport).to have_received(:send_payload).with(
|
183
182
|
event_type: "resolve",
|
184
183
|
service_key: "a-test-service-key",
|
185
184
|
incident_key: "a-test-incident-key",
|
@@ -190,7 +189,7 @@ describe Pagerduty do
|
|
190
189
|
context "a description" do
|
191
190
|
When(:resolve) { incident.resolve("test-description") }
|
192
191
|
Then {
|
193
|
-
expect(transport).to have_received(:
|
192
|
+
expect(transport).to have_received(:send_payload).with(
|
194
193
|
event_type: "resolve",
|
195
194
|
service_key: "a-test-service-key",
|
196
195
|
incident_key: "a-test-incident-key",
|
@@ -202,7 +201,7 @@ describe Pagerduty do
|
|
202
201
|
context "a description and details" do
|
203
202
|
When(:resolve) { incident.resolve("test-description", { my: "detail" }) }
|
204
203
|
Then {
|
205
|
-
expect(transport).to have_received(:
|
204
|
+
expect(transport).to have_received(:send_payload).with(
|
206
205
|
event_type: "resolve",
|
207
206
|
service_key: "a-test-service-key",
|
208
207
|
incident_key: "a-test-incident-key",
|
@@ -217,11 +216,11 @@ describe Pagerduty do
|
|
217
216
|
|
218
217
|
context "PagerDuty successfully resolves the incident" do
|
219
218
|
Given {
|
220
|
-
transport.
|
219
|
+
allow(transport).to receive(:send_payload).and_return(
|
221
220
|
"status" => "success",
|
222
221
|
"incident_key" => "a-test-incident-key",
|
223
|
-
"message" => "Event resolved"
|
224
|
-
|
222
|
+
"message" => "Event resolved"
|
223
|
+
)
|
225
224
|
}
|
226
225
|
When(:resolve) { incident.resolve }
|
227
226
|
Then { expect(resolve).to be incident}
|
@@ -229,17 +228,17 @@ describe Pagerduty do
|
|
229
228
|
|
230
229
|
context "PagerDuty fails to create the incident" do
|
231
230
|
Given {
|
232
|
-
transport.
|
231
|
+
allow(transport).to receive(:send_payload).and_return(
|
233
232
|
"status" => "failure",
|
234
|
-
"message" => "Event not resolved"
|
235
|
-
|
233
|
+
"message" => "Event not resolved"
|
234
|
+
)
|
236
235
|
}
|
237
236
|
When(:resolve) { incident.resolve }
|
238
237
|
Then { expect(resolve).to have_failed PagerdutyException }
|
239
238
|
end
|
240
239
|
|
241
240
|
context "PagerDuty responds with HTTP bad request" do
|
242
|
-
Given { transport.
|
241
|
+
Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
|
243
242
|
When(:resolve) { incident.resolve }
|
244
243
|
Then { expect(resolve).to have_failed Net::HTTPServerException }
|
245
244
|
end
|
@@ -248,13 +247,13 @@ describe Pagerduty do
|
|
248
247
|
|
249
248
|
describe "#trigger" do
|
250
249
|
describe "provides the correct request" do
|
251
|
-
Given { transport.
|
250
|
+
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
|
252
251
|
|
253
252
|
context "no options" do
|
254
253
|
Given(:incident_key) { "instance incident_key" }
|
255
254
|
When(:trigger) { incident.trigger("description") }
|
256
255
|
Then {
|
257
|
-
expect(transport).to have_received(:
|
256
|
+
expect(transport).to have_received(:send_payload).with(
|
258
257
|
incident_key: "instance incident_key",
|
259
258
|
service_key: "a-test-service-key",
|
260
259
|
event_type: "trigger",
|
@@ -266,7 +265,7 @@ describe Pagerduty do
|
|
266
265
|
context "with incident_key option" do
|
267
266
|
When(:trigger) { incident.trigger("description", incident_key: "method param incident_key") }
|
268
267
|
Then {
|
269
|
-
expect(transport).to have_received(:
|
268
|
+
expect(transport).to have_received(:send_payload).with(
|
270
269
|
incident_key: "method param incident_key",
|
271
270
|
service_key: "a-test-service-key",
|
272
271
|
event_type: "trigger",
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagerduty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Somerville
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '1.
|
34
|
+
version: '1.7'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.7'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: rspec-given
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
126
|
version: '0'
|
113
127
|
requirements: []
|
114
128
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.4.5
|
116
130
|
signing_key:
|
117
131
|
specification_version: 4
|
118
132
|
summary: Pagerduty Integration API client library
|