pagerduty 1.4.1 → 2.0.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: b35425e697bdee8a4b3217052d579505b4655fc5
4
- data.tar.gz: 4861fe46da3e2c532a0b351e9519e1e7ec2323ff
3
+ metadata.gz: a22fab98bfd9b7ab4f99f8dd824b1ac10a6f7675
4
+ data.tar.gz: 5eb0a9c4074cd4aed73987137a3a53f81389c65f
5
5
  SHA512:
6
- metadata.gz: 6eb7f43eeaefad73c18f9e285258ebbc4c2381cd5478445f61e5102ed10f4c95fdd1319e4c8cc3950cf3b54b03ff2639b44eedc8917a0159948bdc4be767bbf0
7
- data.tar.gz: 4472c21d7aac15ac890ac87a565414aabd573e0f7895d8339cc3b34fe587da915320caa208edc52891285a7c7b0a2d180e8b48d174f02a86a274d192b5b496d2
6
+ metadata.gz: 001b8bb1ed10ae2e54f315233bf55f30c7173141c584dfccbb04236e84a5a65b6157c7e088bd525bdb71b42e94481154214e019762c935ad8a2d004a536b99da
7
+ data.tar.gz: a4f2bfb76c69a3bfe86aa32d45ee7cb285e1920ccc249f270af018ff4971fa8cf246901230302cc72ae9e8fc2aefcc3b492a8c64abf65ce331dfebadf9b9111b
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Envato & Charlie Somerville
1
+ Copyright (c) 2010 Envato, Charlie Somerville & Orien Madgwick
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,37 +1,87 @@
1
- pagerduty
2
- =========
1
+ # pagerduty
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/pagerduty.svg)](http://badge.fury.io/rb/pagerduty)
5
4
  [![Build Status](https://travis-ci.org/envato/pagerduty.svg?branch=master)](https://travis-ci.org/envato/pagerduty)
6
5
 
7
- Provides a simple interface for calling into the [Pagerduty](http://pagerduty.com) API.
6
+ Provides a lightweight Ruby interface for calling the [PagerDuty
7
+ Integration API](http://developer.pagerduty.com/documentation/integration/events).
8
8
 
9
- Installation
10
- ------------
9
+ ## Installation
11
10
 
12
- Install pagerduty with this command:
11
+ Add this line to your application's Gemfile:
13
12
 
14
- gem install pagerduty
13
+ ```ruby
14
+ gem 'pagerduty'
15
+ ```
15
16
 
16
- Usage
17
- -----
17
+ And then execute:
18
18
 
19
- Pagerduty exposes three classes, `Pagerduty`, `PagerdutyIncident` and `PagerdutyException`. Instances of `PagerdutyIncident` are created and returned for every API call.
19
+ $ bundle
20
20
 
21
- `Pagerduty`'s constructor takes 2 arguments - your `service_key` and an optional argument to set the 'incident_key' You can then use the method `trigger` to trigger a new incident with Pagerduty:
21
+ Or install it yourself as:
22
22
 
23
- require 'pagerduty'
24
- p = Pagerduty.new "your_pagerduty_service_key"
25
- incident = p.trigger "Everything went down!"
23
+ $ gem install pagerduty
26
24
 
27
- Incidents can be retriggered, acknowledged with the `PagerdutyIncident#acknowledge` method, and resolved with `PagerdutyIncident#resolve`.
25
+ ## Usage
28
26
 
29
- Additionally, all API methods (`trigger`, `acknowledge`, `resolve`) take an optional second parameter `details`, which should be a hash containing any extra information that should be recorded with Pagerduty.
27
+ ```ruby
28
+ # Don't forget to require the library
29
+ require "pagerduty"
30
30
 
31
- If the Pagerduty API does not return success, a `PagerdutyException` will be thrown which has the properties `pagerduty_instance` (the instance of either `Pagerduty` or `PagerdutyException` that caused the exception) and `api_response`, which is a hash representation of the JSON response from the Pagerduty API.
31
+ # Instantiate a Pagerduty with your specific service key
32
+ pagerduty = Pagerduty.new("<my-service-key>")
32
33
 
33
- Copyright
34
- ---------
34
+ # Trigger an incident
35
+ incident = pagerduty.trigger("incident description")
35
36
 
36
- Copyright (c) 2010 [Envato](http://envato.com) & [Charlie Somerville](http://charliesomerville.com). See LICENSE.txt for further details.
37
+ # Acknowledge and/or resolve the incident
38
+ incident.acknowledge
39
+ incident.resolve
40
+ ```
37
41
 
42
+ There are a whole bunch of properties you can send to PagerDuty when triggering
43
+ an incident. See the [PagerDuty
44
+ documentation](http://developer.pagerduty.com/documentation/integration/events/trigger)
45
+ for the specifics.
46
+
47
+ ```ruby
48
+ pagerduty.trigger(
49
+ "incident description",
50
+ :incident_key => "my unique incident identifier",
51
+ :client => "server in trouble",
52
+ :client_url => "http://server.in.trouble",
53
+ :details => { :my => "extra details" },
54
+ )
55
+ ```
56
+
57
+ ### Upgrading to Version 2.0.0
58
+
59
+ The API has changed in three ways that you need to be aware of:
60
+
61
+ 1. `Pagerduty` class initialiser no longer accepts an `incident_key`. This
62
+ attribute can now be provided when calling the `#trigger` method (see above).
63
+
64
+ 2. `Pagerduty#trigger` arguments have changed to accept all available options
65
+ rather than just details.
66
+
67
+ ```ruby
68
+ # This no longer works post v2.0.0. If you're
69
+ # providing details in this form, please migrate.
70
+ pagerduty.trigger("desc", :key => "value")
71
+
72
+ # Post v2.0.0 this is how to send details (migrate to this please).
73
+ pagerduty.trigger("desc", :details => { :key => "value" })
74
+ ```
75
+
76
+ 3. `PagerdutyException` now extends from `StandardError` rather than
77
+ `Exception`. This may affect how you rescue the error. i.e. `rescue
78
+ StandardError` will now rescue a `PagerdutyException` where it did not
79
+ before.
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it ( https://github.com/[my-github-username]/pagerduty/fork )
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,18 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require "rdoc/task"
4
3
 
5
4
  task :default => :spec
6
5
 
7
6
  RSpec::Core::RakeTask.new(:spec) do |t|
8
7
  t.verbose = false
9
8
  end
10
-
11
- RDoc::Task.new do |rdoc|
12
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
13
-
14
- rdoc.rdoc_dir = 'rdoc'
15
- rdoc.title = "pagerduty #{version}"
16
- rdoc.rdoc_files.include('README*')
17
- rdoc.rdoc_files.include('lib/**/*.rb')
18
- end
@@ -1,73 +1,162 @@
1
1
  require 'pagerduty/version'
2
2
  require 'pagerduty/http_transport'
3
3
 
4
- class PagerdutyException < Exception
4
+ class PagerdutyException < StandardError
5
5
  attr_reader :pagerduty_instance, :api_response
6
6
 
7
- def initialize(instance, resp)
7
+ def initialize(instance, response, message)
8
+ super(message)
8
9
  @pagerduty_instance = instance
9
- @api_response = resp
10
+ @api_response = response
10
11
  end
11
12
  end
12
13
 
13
14
  class Pagerduty
14
15
 
15
- attr_reader :service_key, :incident_key
16
+ attr_reader :service_key
16
17
 
17
- def initialize(service_key, incident_key = nil)
18
+ # @param [String] service_key The GUID of one of your "Generic API" services.
19
+ # This is the "service key" listed on a Generic API's service detail page.
20
+ #
21
+ def initialize(service_key)
18
22
  @service_key = service_key
19
- @incident_key = incident_key
20
23
  end
21
24
 
22
- def trigger(description, details = {})
23
- resp = api_call("trigger", description, details)
24
- raise PagerdutyException.new(self, resp) unless resp["status"] == "success"
25
-
26
- PagerdutyIncident.new @service_key, resp["incident_key"]
25
+ # Send PagerDuty a trigger event to report a new or ongoing problem. When
26
+ # PagerDuty receives a trigger event, it will either open a new incident, or
27
+ # add a new trigger log entry to an existing incident, depending on the
28
+ # provided incident_key.
29
+ #
30
+ # @param [String] description A short description of the problem that led to
31
+ # this trigger. This field (or a truncated version) will be used when
32
+ # generating phone calls, SMS messages and alert emails. It will also appear
33
+ # on the incidents tables in the PagerDuty UI. The maximum length is 1024
34
+ # characters.
35
+ #
36
+ # @option options [String] :incident_key Identifies the incident to which
37
+ # this trigger event should be applied. If there's no open (i.e. unresolved)
38
+ # incident with this key, a new one will be created. If there's already an
39
+ # open incident with a matching key, this event will be appended to that
40
+ # incident's log. The event key provides an easy way to "de-dup" problem
41
+ # reports. If this field isn't provided, PagerDuty will automatically open a
42
+ # new incident with a unique key.
43
+ #
44
+ # @option options [String] :client The name of the monitoring client that is
45
+ # triggering this event.
46
+ #
47
+ # @option options [String] :client_url The URL of the monitoring client that
48
+ # is triggering this event.
49
+ #
50
+ # @option options [Hash] :details An arbitrary hash containing any data you'd
51
+ # like included in the incident log.
52
+ #
53
+ # @return [PagerdutyIncident] The triggered incident.
54
+ #
55
+ # @raise [PagerdutyException] If PagerDuty responds with a status that is not
56
+ # "success"
57
+ #
58
+ def trigger(description, options = {})
59
+ resp = api_call("trigger", options.merge(:description => description))
60
+ ensure_success(resp)
61
+ PagerdutyIncident.new service_key, resp["incident_key"]
27
62
  end
28
63
 
64
+ # @return [PagerdutyIncident] The incident referenced by the key.
65
+ #
29
66
  def get_incident(incident_key)
30
- PagerdutyIncident.new @service_key, incident_key
67
+ PagerdutyIncident.new service_key, incident_key
31
68
  end
32
69
 
33
70
  protected
34
71
 
35
- def api_call(event_type, description, details = {})
36
- params = {
72
+ def api_call(event_type, args)
73
+ args = args.merge(
74
+ :service_key => service_key,
37
75
  :event_type => event_type,
38
- :service_key => @service_key,
39
- :description => description,
40
- :details => details
41
- }
42
- params[:incident_key] = @incident_key if @incident_key
43
- Pagerduty.transport.send(params)
76
+ )
77
+ Pagerduty.transport.send(args)
44
78
  end
45
79
 
46
- class << self
47
- def transport
48
- Pagerduty::HttpTransport
80
+ def ensure_success(response)
81
+ unless response["status"] == "success"
82
+ raise PagerdutyException.new(self, response, response["message"])
49
83
  end
50
84
  end
85
+
86
+ # @api private
87
+ def self.transport
88
+ Pagerduty::HttpTransport
89
+ end
51
90
  end
52
91
 
53
92
  class PagerdutyIncident < Pagerduty
93
+ attr_reader :incident_key
54
94
 
95
+ # @param [String] service_key The GUID of one of your "Generic API" services.
96
+ # This is the "service key" listed on a Generic API's service detail page.
97
+ #
98
+ # @param [String] incident_key The unique identifier for the incident.
99
+ #
55
100
  def initialize(service_key, incident_key)
56
101
  super service_key
57
102
  @incident_key = incident_key
58
103
  end
59
104
 
60
- def acknowledge(description, details = {})
61
- resp = api_call("acknowledge", description, details)
62
- raise PagerdutyException.new(self, resp) unless resp["status"] == "success"
105
+ # @param (see Pagerduty#trigger)
106
+ # @option (see Pagerduty#trigger)
107
+ def trigger(description, options = {})
108
+ super(description, { :incident_key => incident_key }.merge(options))
109
+ end
63
110
 
64
- self
111
+ # Acknowledge the referenced incident. While an incident is acknowledged, it
112
+ # won't generate any additional notifications, even if it receives new
113
+ # trigger events. Send PagerDuty an acknowledge event when you know someone
114
+ # is presently working on the problem.
115
+ #
116
+ # @param [String] description Text that will appear in the incident's log
117
+ # associated with this event.
118
+ #
119
+ # @param [Hash] details An arbitrary hash containing any data you'd like
120
+ # included in the incident log.
121
+ #
122
+ # @return [PagerdutyIncident] self
123
+ #
124
+ # @raise [PagerdutyException] If PagerDuty responds with a status that is not
125
+ # "success"
126
+ #
127
+ def acknowledge(description = nil, details = nil)
128
+ modify_incident("acknowledge", description, details)
129
+ end
130
+
131
+ # Resolve the referenced incident. Once an incident is resolved, it won't
132
+ # generate any additional notifications. New trigger events with the same
133
+ # incident_key as a resolved incident won't re-open the incident. Instead, a
134
+ # new incident will be created. Send PagerDuty a resolve event when the
135
+ # problem that caused the initial trigger event has been fixed.
136
+ #
137
+ # @param [String] description Text that will appear in the incident's log
138
+ # associated with this event.
139
+ #
140
+ # @param [Hash] details An arbitrary hash containing any data you'd like
141
+ # included in the incident log.
142
+ #
143
+ # @return [PagerdutyIncident] self
144
+ #
145
+ # @raise [PagerdutyException] If PagerDuty responds with a status that is not
146
+ # "success"
147
+ #
148
+ def resolve(description = nil, details = nil)
149
+ modify_incident("resolve", description, details)
65
150
  end
66
151
 
67
- def resolve(description, details = {})
68
- resp = api_call("resolve", description, details)
69
- raise PagerdutyException.new(self, resp) unless resp["status"] == "success"
152
+ private
70
153
 
154
+ def modify_incident(event_type, description, details)
155
+ options = { :incident_key => incident_key }
156
+ options[:description] = description if description
157
+ options[:details] = details if details
158
+ resp = api_call(event_type, options)
159
+ ensure_success(resp)
71
160
  self
72
161
  end
73
162
 
@@ -3,38 +3,38 @@ require 'json'
3
3
  require 'net/http'
4
4
  require 'net/https'
5
5
 
6
+ # @api private
6
7
  module Pagerduty::HttpTransport
7
- class << self
8
+ extend self
8
9
 
9
- HOST = "events.pagerduty.com"
10
- PORT = 443
11
- PATH = "/generic/2010-04-15/create_event.json"
10
+ HOST = "events.pagerduty.com"
11
+ PORT = 443
12
+ PATH = "/generic/2010-04-15/create_event.json"
12
13
 
13
- def send(payload = {})
14
- response = post payload.to_json
15
- response.error! unless transported?(response)
16
- JSON.parse(response.body)
17
- end
14
+ def send(payload = {})
15
+ response = post payload.to_json
16
+ response.error! unless transported?(response)
17
+ JSON.parse(response.body)
18
+ end
18
19
 
19
- private
20
+ private
20
21
 
21
- def post(payload)
22
- post = Net::HTTP::Post.new(PATH)
23
- post.body = payload
24
- http.request(post)
25
- end
22
+ def post(payload)
23
+ post = Net::HTTP::Post.new(PATH)
24
+ post.body = payload
25
+ http.request(post)
26
+ end
26
27
 
27
- def http
28
- http = Net::HTTP.new(HOST, PORT)
29
- http.use_ssl = true
30
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
31
- http.open_timeout = 60
32
- http.read_timeout = 60
33
- http
34
- end
28
+ def http
29
+ http = Net::HTTP.new(HOST, PORT)
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
32
+ http.open_timeout = 60
33
+ http.read_timeout = 60
34
+ http
35
+ end
35
36
 
36
- def transported?(response)
37
- response.kind_of? Net::HTTPSuccess or response.kind_of? Net::HTTPRedirection
38
- end
37
+ def transported?(response)
38
+ response.kind_of? Net::HTTPSuccess or response.kind_of? Net::HTTPRedirection
39
39
  end
40
40
  end
@@ -1,3 +1,3 @@
1
1
  class Pagerduty
2
- VERSION = "1.4.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -6,13 +6,18 @@ require 'pagerduty/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "pagerduty"
8
8
  gem.version = Pagerduty::VERSION
9
- gem.authors = ["Charlie Somerville"]
10
- gem.email = ["charlie@charliesomerville.com"]
11
- gem.description = %q{Provides a simple interface for calling into the Pagerduty API}
12
- gem.summary = %q{Pagerduty API client library}
9
+ gem.authors = ["Charlie Somerville", "Orien Madgwick"]
10
+ gem.email = ["charlie@charliesomerville.com", "_@orien.io"]
11
+ gem.description = %q{Provides a lightweight interface for calling the PagerDuty Integration API}
12
+ gem.summary = %q{Pagerduty Integration API client library}
13
13
  gem.homepage = "http://github.com/envato/pagerduty"
14
14
  gem.license = "MIT"
15
15
 
16
+ gem.post_install_message = <<-MSG
17
+ If upgrading to pagerduty 2.0.0 please note the API changes:
18
+ https://github.com/envato/pagerduty#upgrading-to-version-200
19
+ MSG
20
+
16
21
  gem.files = `git ls-files`.split($/)
17
22
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
23
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -9,20 +9,43 @@ describe Pagerduty do
9
9
  Given { Pagerduty.stub(:transport => transport) }
10
10
 
11
11
  describe "#trigger" do
12
- Given(:description) { "a-test-description" }
13
- Given(:details) { { key: "value" } }
14
12
 
15
13
  describe "provides the correct request" do
16
14
  Given { transport.stub(:send => standard_response) }
17
- When(:incident) { pagerduty.trigger(description, details) }
18
- Then {
19
- expect(transport).to have_received(:send).with(
20
- event_type: "trigger",
21
- service_key: "a-test-service-key",
22
- description: "a-test-description",
23
- details: { key: "value" }
24
- )
25
- }
15
+
16
+ context "no options" do
17
+ When(:incident) { pagerduty.trigger("a-test-description") }
18
+ Then {
19
+ expect(transport).to have_received(:send).with(
20
+ service_key: "a-test-service-key",
21
+ event_type: "trigger",
22
+ description: "a-test-description",
23
+ )
24
+ }
25
+ end
26
+
27
+ context "all options" do
28
+ When(:incident) {
29
+ pagerduty.trigger(
30
+ "a-test-description",
31
+ incident_key: "a-test-incident-key",
32
+ client: "a-test-client",
33
+ client_url: "a-test-client-url",
34
+ details: { key: "value" },
35
+ )
36
+ }
37
+ Then {
38
+ expect(transport).to have_received(:send).with(
39
+ service_key: "a-test-service-key",
40
+ event_type: "trigger",
41
+ description: "a-test-description",
42
+ incident_key: "a-test-incident-key",
43
+ client: "a-test-client",
44
+ client_url: "a-test-client-url",
45
+ details: { key: "value" },
46
+ )
47
+ }
48
+ end
26
49
  end
27
50
 
28
51
  describe "handles all responses" do
@@ -35,7 +58,7 @@ describe Pagerduty do
35
58
  "message" => "Event processed",
36
59
  })
37
60
  }
38
- When(:incident) { pagerduty.trigger(description, details) }
61
+ When(:incident) { pagerduty.trigger("description") }
39
62
  Then { expect(incident).to be_a PagerdutyIncident }
40
63
  Then { incident.service_key == service_key }
41
64
  Then { incident.incident_key == "My Incident Key" }
@@ -48,13 +71,13 @@ describe Pagerduty do
48
71
  "message" => "Event not processed",
49
72
  })
50
73
  }
51
- When(:incident) { pagerduty.trigger(description, details) }
74
+ When(:incident) { pagerduty.trigger("description") }
52
75
  Then { expect(incident).to have_raised PagerdutyException }
53
76
  end
54
77
 
55
78
  context "PagerDuty responds with HTTP bad request" do
56
79
  Given { transport.stub(:send).and_raise(Net::HTTPServerException.new(nil, nil)) }
57
- When(:incident) { pagerduty.trigger(description, details) }
80
+ When(:incident) { pagerduty.trigger("description") }
58
81
  Then { expect(incident).to have_raised Net::HTTPServerException }
59
82
  end
60
83
  end
@@ -71,23 +94,47 @@ describe Pagerduty do
71
94
  describe PagerdutyIncident do
72
95
  Given(:incident) { PagerdutyIncident.new(service_key, incident_key) }
73
96
  Given(:incident_key) { "a-test-incident-key" }
74
- Given(:description) { "a-test-description" }
75
- Given(:details) { { key: "value" } }
76
97
 
77
98
  describe "#acknowledge" do
78
99
 
79
100
  describe "provides the correct request" do
80
101
  Given { transport.stub(:send => standard_response) }
81
- When(:acknowledge) { incident.acknowledge(description, details) }
82
- Then {
83
- expect(transport).to have_received(:send).with(
84
- event_type: "acknowledge",
85
- service_key: "a-test-service-key",
86
- description: "a-test-description",
87
- details: { key: "value" },
88
- incident_key: "a-test-incident-key",
89
- )
90
- }
102
+
103
+ context "no args" do
104
+ When(:acknowledge) { incident.acknowledge }
105
+ Then {
106
+ expect(transport).to have_received(:send).with(
107
+ event_type: "acknowledge",
108
+ service_key: "a-test-service-key",
109
+ incident_key: "a-test-incident-key",
110
+ )
111
+ }
112
+ end
113
+
114
+ context "a description" do
115
+ When(:acknowledge) { incident.acknowledge("test-description") }
116
+ Then {
117
+ expect(transport).to have_received(:send).with(
118
+ event_type: "acknowledge",
119
+ service_key: "a-test-service-key",
120
+ incident_key: "a-test-incident-key",
121
+ description: "test-description",
122
+ )
123
+ }
124
+ end
125
+
126
+ context "a description and details" do
127
+ When(:acknowledge) { incident.acknowledge("test-description", { my: "detail" }) }
128
+ Then {
129
+ expect(transport).to have_received(:send).with(
130
+ event_type: "acknowledge",
131
+ service_key: "a-test-service-key",
132
+ incident_key: "a-test-incident-key",
133
+ description: "test-description",
134
+ details: { my: "detail" },
135
+ )
136
+ }
137
+ end
91
138
  end
92
139
 
93
140
  describe "handles all responses" do
@@ -100,7 +147,7 @@ describe Pagerduty do
100
147
  "message" => "Event acknowledged",
101
148
  })
102
149
  }
103
- When(:acknowledge) { incident.acknowledge(description, details) }
150
+ When(:acknowledge) { incident.acknowledge }
104
151
  Then { expect(acknowledge).to be incident}
105
152
  end
106
153
 
@@ -112,13 +159,13 @@ describe Pagerduty do
112
159
  "message" => "Event not acknowledged",
113
160
  })
114
161
  }
115
- When(:acknowledge) { incident.acknowledge(description, details) }
162
+ When(:acknowledge) { incident.acknowledge }
116
163
  Then { expect(acknowledge).to have_failed PagerdutyException }
117
164
  end
118
165
 
119
166
  context "PagerDuty responds with HTTP bad request" do
120
167
  Given { transport.stub(:send).and_raise(Net::HTTPServerException.new(nil, nil)) }
121
- When(:acknowledge) { incident.acknowledge(description, details) }
168
+ When(:acknowledge) { incident.acknowledge }
122
169
  Then { expect(acknowledge).to have_failed Net::HTTPServerException }
123
170
  end
124
171
  end
@@ -128,16 +175,42 @@ describe Pagerduty do
128
175
 
129
176
  describe "provides the correct request" do
130
177
  Given { transport.stub(:send => standard_response) }
131
- When(:resolve) { incident.resolve(description, details) }
132
- Then {
133
- expect(transport).to have_received(:send).with(
134
- event_type: "resolve",
135
- service_key: "a-test-service-key",
136
- description: "a-test-description",
137
- details: { key: "value" },
138
- incident_key: "a-test-incident-key",
139
- )
140
- }
178
+
179
+ context "no args" do
180
+ When(:resolve) { incident.resolve }
181
+ Then {
182
+ expect(transport).to have_received(:send).with(
183
+ event_type: "resolve",
184
+ service_key: "a-test-service-key",
185
+ incident_key: "a-test-incident-key",
186
+ )
187
+ }
188
+ end
189
+
190
+ context "a description" do
191
+ When(:resolve) { incident.resolve("test-description") }
192
+ Then {
193
+ expect(transport).to have_received(:send).with(
194
+ event_type: "resolve",
195
+ service_key: "a-test-service-key",
196
+ incident_key: "a-test-incident-key",
197
+ description: "test-description",
198
+ )
199
+ }
200
+ end
201
+
202
+ context "a description and details" do
203
+ When(:resolve) { incident.resolve("test-description", { my: "detail" }) }
204
+ Then {
205
+ expect(transport).to have_received(:send).with(
206
+ event_type: "resolve",
207
+ service_key: "a-test-service-key",
208
+ incident_key: "a-test-incident-key",
209
+ description: "test-description",
210
+ details: { my: "detail" },
211
+ )
212
+ }
213
+ end
141
214
  end
142
215
 
143
216
  describe "handles all responses" do
@@ -150,7 +223,7 @@ describe Pagerduty do
150
223
  "message" => "Event resolved",
151
224
  })
152
225
  }
153
- When(:resolve) { incident.resolve(description, details) }
226
+ When(:resolve) { incident.resolve }
154
227
  Then { expect(resolve).to be incident}
155
228
  end
156
229
 
@@ -161,17 +234,48 @@ describe Pagerduty do
161
234
  "message" => "Event not resolved",
162
235
  })
163
236
  }
164
- When(:resolve) { incident.resolve(description, details) }
237
+ When(:resolve) { incident.resolve }
165
238
  Then { expect(resolve).to have_failed PagerdutyException }
166
239
  end
167
240
 
168
241
  context "PagerDuty responds with HTTP bad request" do
169
242
  Given { transport.stub(:send).and_raise(Net::HTTPServerException.new(nil, nil)) }
170
- When(:resolve) { incident.resolve(description, details) }
243
+ When(:resolve) { incident.resolve }
171
244
  Then { expect(resolve).to have_failed Net::HTTPServerException }
172
245
  end
173
246
  end
174
247
  end
248
+
249
+ describe "#trigger" do
250
+ describe "provides the correct request" do
251
+ Given { transport.stub(:send => standard_response) }
252
+
253
+ context "no options" do
254
+ Given(:incident_key) { "instance incident_key" }
255
+ When(:trigger) { incident.trigger("description") }
256
+ Then {
257
+ expect(transport).to have_received(:send).with(
258
+ incident_key: "instance incident_key",
259
+ service_key: "a-test-service-key",
260
+ event_type: "trigger",
261
+ description: "description",
262
+ )
263
+ }
264
+ end
265
+
266
+ context "with incident_key option" do
267
+ When(:trigger) { incident.trigger("description", incident_key: "method param incident_key") }
268
+ Then {
269
+ expect(transport).to have_received(:send).with(
270
+ incident_key: "method param incident_key",
271
+ service_key: "a-test-service-key",
272
+ event_type: "trigger",
273
+ description: "description",
274
+ )
275
+ }
276
+ end
277
+ end
278
+ end
175
279
  end
176
280
 
177
281
  def standard_response
@@ -181,10 +285,12 @@ describe Pagerduty do
181
285
  describe PagerdutyException do
182
286
  Given(:pagerduty_instance) { double }
183
287
  Given(:api_response) { double }
288
+ Given(:message) { "a test error message" }
184
289
 
185
- When(:pagerduty_exception) { PagerdutyException.new(pagerduty_instance, api_response) }
290
+ When(:pagerduty_exception) { PagerdutyException.new(pagerduty_instance, api_response, message) }
186
291
 
187
292
  Then { pagerduty_exception.pagerduty_instance == pagerduty_instance }
188
293
  Then { pagerduty_exception.api_response == api_response }
294
+ Then { pagerduty_exception.message == message }
189
295
  end
190
296
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagerduty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Somerville
8
+ - Orien Madgwick
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
12
+ date: 2014-05-26 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json
@@ -66,14 +67,15 @@ dependencies:
66
67
  - - ">="
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
- description: Provides a simple interface for calling into the Pagerduty API
70
+ description: Provides a lightweight interface for calling the PagerDuty Integration
71
+ API
70
72
  email:
71
73
  - charlie@charliesomerville.com
74
+ - _@orien.io
72
75
  executables: []
73
76
  extensions: []
74
77
  extra_rdoc_files: []
75
78
  files:
76
- - ".document"
77
79
  - ".gitignore"
78
80
  - ".travis.yml"
79
81
  - Gemfile
@@ -92,7 +94,9 @@ homepage: http://github.com/envato/pagerduty
92
94
  licenses:
93
95
  - MIT
94
96
  metadata: {}
95
- post_install_message:
97
+ post_install_message: |
98
+ If upgrading to pagerduty 2.0.0 please note the API changes:
99
+ https://github.com/envato/pagerduty#upgrading-to-version-200
96
100
  rdoc_options: []
97
101
  require_paths:
98
102
  - lib
@@ -111,7 +115,7 @@ rubyforge_project:
111
115
  rubygems_version: 2.2.2
112
116
  signing_key:
113
117
  specification_version: 4
114
- summary: Pagerduty API client library
118
+ summary: Pagerduty Integration API client library
115
119
  test_files:
116
120
  - spec/pagerduty/http_transport_spec.rb
117
121
  - spec/pagerduty_spec.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt