pagerduty 2.0.1 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79dcf1ccf6b3223a64d07a152f55b8a0b6a99f26
4
- data.tar.gz: bd86c131d6b99b475ffe82082a307defff905ec7
3
+ metadata.gz: 0164943fae7683d08ea5fad001e6ebea17af7524
4
+ data.tar.gz: 1d58093c6b70649b7877ed41425641d4330e065b
5
5
  SHA512:
6
- metadata.gz: e2d66e8ea5d2d101c6d5c484c51b5bbc0d9f7b462f2ef2a449344f7e8dd8b0b0b411fb336f978f2e28bf1d42b0ef46d1801f7ff04b2b953e0e9b046a8d71891c
7
- data.tar.gz: 0d6614d6104796bda5868fc529da1ac8b75de6688c67df41fda5aae39e3a386654ad49178304a375483465c9585935a41b33327ac2c6b48b92db15f378e30400
6
+ metadata.gz: 1ef62a628733a0cc02994789eb80ac7fbb7685c038c21595f82c897dafef17a53b5287af0ef52ad702104dd655aefd7a3517cab10f159fa401552e85c1eb610d
7
+ data.tar.gz: da5ae3770b892d4ce644d05b2c5a830b38007d19fcee3931dfc4f23454755afb3b1dde71b163a9c225b6ea606a9d33026d5c629a0e90b6ec70fbaed6ff1b320f
@@ -0,0 +1,27 @@
1
+ AllCops:
2
+ Exclude:
3
+ - .bundle/**/*
4
+ - bin/**/*
5
+ - vendor/**/*
6
+
7
+ Style/AccessModifierIndentation:
8
+ EnforcedStyle: outdent
9
+
10
+ Style/BlockDelimiters:
11
+ Exclude:
12
+ - spec/**/*
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/GuardClause:
18
+ Enabled: false
19
+
20
+ Style/SpecialGlobalVars:
21
+ Enabled: false
22
+
23
+ Style/StringLiterals:
24
+ EnforcedStyle: double_quotes
25
+
26
+ Style/TrailingComma:
27
+ EnforcedStyleForMultiline: comma
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
3
- - 2.2.0
4
- - 2.1.5
5
+ - 2.3.0
6
+ - 2.2.4
7
+ - 2.1.8
5
8
  - 2.0.0
6
9
  - 1.9.3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in pagerduty.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -39,6 +39,11 @@ incident = pagerduty.trigger("incident description")
39
39
  # Acknowledge and/or resolve the incident
40
40
  incident.acknowledge
41
41
  incident.resolve
42
+
43
+ # Acknowledge and/or resolve an existing incident
44
+ incident = pagerduty.get_incident("<unique-incident-key>")
45
+ incident.acknowledge
46
+ incident.resolve
42
47
  ```
43
48
 
44
49
  There are a whole bunch of properties you can send to PagerDuty when triggering
@@ -49,16 +54,36 @@ for the specifics.
49
54
  ```ruby
50
55
  pagerduty.trigger(
51
56
  "incident description",
52
- :incident_key => "my unique incident identifier",
53
- :client => "server in trouble",
54
- :client_url => "http://server.in.trouble",
55
- :details => { :my => "extra details" },
57
+ incident_key: "my unique incident identifier",
58
+ client: "server in trouble",
59
+ client_url: "http://server.in.trouble",
60
+ details: { my: "extra details" }
56
61
  )
57
62
  ```
58
63
 
64
+ ### HTTP Proxy Support
65
+
66
+ One can explicitly define an HTTP proxy like this:
67
+
68
+ ```ruby
69
+ # Instantiate a Pagerduty with your specific service key and proxy details
70
+ pagerduty = Pagerduty.new(
71
+ "<my-service-key>",
72
+ proxy_host: "my.http.proxy.local",
73
+ proxy_port: 3128,
74
+ proxy_username: "<my-proxy-username>",
75
+ proxy_password: "<my-proxy-password>",
76
+ )
77
+
78
+ # Then proceed to trigger your incident
79
+ # (sends the request to PagerDuty via the HTTP proxy)
80
+ incident = pagerduty.trigger("incident description")
81
+ ```
82
+
59
83
  ### Debugging Error Responses
60
84
 
61
- The gem doesn't encapsulate HTTP error responses from PagerDuty. Here's how to go about debugging these unhappy cases:
85
+ The gem doesn't encapsulate HTTP error responses from PagerDuty. Here's how to
86
+ go about debugging these unhappy cases:
62
87
 
63
88
  ```ruby
64
89
  begin
@@ -83,10 +108,10 @@ rather than just details.
83
108
  ```ruby
84
109
  # This no longer works post v2.0.0. If you're
85
110
  # providing details in this form, please migrate.
86
- pagerduty.trigger("desc", :key => "value")
111
+ pagerduty.trigger("desc", key: "value")
87
112
 
88
113
  # Post v2.0.0 this is how to send details (migrate to this please).
89
- pagerduty.trigger("desc", :details => { :key => "value" })
114
+ pagerduty.trigger("desc", details: { key: "value" })
90
115
  ```
91
116
 
92
117
  3. `PagerdutyException` now extends from `StandardError` rather than
@@ -96,7 +121,7 @@ before.
96
121
 
97
122
  ## Contributing
98
123
 
99
- 1. Fork it ( https://github.com/[my-github-username]/pagerduty/fork )
124
+ 1. Fork it ( https://github.com/envato/pagerduty/fork )
100
125
  2. Create your feature branch (`git checkout -b my-new-feature`)
101
126
  3. Commit your changes (`git commit -am 'Add some feature'`)
102
127
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,8 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
3
4
 
4
- task :default => :spec
5
+ task default: [:spec, :rubocop]
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec) do |t|
7
8
  t.verbose = false
9
+ t.ruby_opts = "-w"
8
10
  end
11
+
12
+ RuboCop::RakeTask.new(:rubocop)
@@ -1,5 +1,5 @@
1
- require 'pagerduty/version'
2
- require 'pagerduty/http_transport'
1
+ require "pagerduty/version"
2
+ require "pagerduty/http_transport"
3
3
 
4
4
  class PagerdutyException < StandardError
5
5
  attr_reader :pagerduty_instance, :api_response
@@ -12,14 +12,25 @@ class PagerdutyException < StandardError
12
12
  end
13
13
 
14
14
  class Pagerduty
15
-
16
15
  attr_reader :service_key
17
16
 
18
17
  # @param [String] service_key The GUID of one of your "Generic API" services.
19
18
  # This is the "service key" listed on a Generic API's service detail page.
20
19
  #
21
- def initialize(service_key)
20
+ # @option options [String] :proxy_host The DNS name or IP address of the
21
+ # proxy host. If nil or unprovided a proxy will not be used.
22
+ #
23
+ # @option options [String] :proxy_port The port to use to access the proxy.
24
+ #
25
+ # @option options [String] :proxy_username username if authorization is
26
+ # required to use the proxy.
27
+ #
28
+ # @option options [String] :proxy_password password if authorization is
29
+ # required to use the proxy.
30
+ #
31
+ def initialize(service_key, options = {})
22
32
  @service_key = service_key
33
+ @transport = transport_from_options(options)
23
34
  end
24
35
 
25
36
  # Send PagerDuty a trigger event to report a new or ongoing problem. When
@@ -56,36 +67,51 @@ class Pagerduty
56
67
  # "success"
57
68
  #
58
69
  def trigger(description, options = {})
59
- resp = api_call("trigger", options.merge(:description => description))
70
+ resp = api_call("trigger", options.merge(description: description))
60
71
  ensure_success(resp)
61
- PagerdutyIncident.new service_key, resp["incident_key"]
72
+ PagerdutyIncident.new(
73
+ service_key,
74
+ resp["incident_key"],
75
+ transport: @transport,
76
+ )
62
77
  end
63
78
 
79
+ # @param [String] incident_key The unique identifier for the incident.
80
+ #
64
81
  # @return [PagerdutyIncident] The incident referenced by the key.
65
82
  #
83
+ # @raise [ArgumentError] If incident_key is nil
84
+ #
66
85
  def get_incident(incident_key)
67
- PagerdutyIncident.new service_key, incident_key
86
+ fail ArgumentError, "incident_key is nil" if incident_key.nil?
87
+ PagerdutyIncident.new(
88
+ service_key,
89
+ incident_key,
90
+ transport: @transport,
91
+ )
68
92
  end
69
93
 
70
94
  protected
71
95
 
72
96
  def api_call(event_type, args)
73
97
  args = args.merge(
74
- :service_key => service_key,
75
- :event_type => event_type,
98
+ service_key: service_key,
99
+ event_type: event_type,
76
100
  )
77
- Pagerduty.transport.send_payload(args)
101
+ @transport.send_payload(args)
78
102
  end
79
103
 
80
104
  def ensure_success(response)
81
105
  unless response["status"] == "success"
82
- raise PagerdutyException.new(self, response, response["message"])
106
+ fail PagerdutyException.new(self, response, response["message"])
83
107
  end
84
108
  end
85
109
 
110
+ private
111
+
86
112
  # @api private
87
- def self.transport
88
- Pagerduty::HttpTransport
113
+ def transport_from_options(options = {})
114
+ options[:transport] || Pagerduty::HttpTransport.new(options)
89
115
  end
90
116
  end
91
117
 
@@ -97,15 +123,15 @@ class PagerdutyIncident < Pagerduty
97
123
  #
98
124
  # @param [String] incident_key The unique identifier for the incident.
99
125
  #
100
- def initialize(service_key, incident_key)
101
- super service_key
126
+ def initialize(service_key, incident_key, options = {})
127
+ super service_key, options
102
128
  @incident_key = incident_key
103
129
  end
104
130
 
105
131
  # @param (see Pagerduty#trigger)
106
132
  # @option (see Pagerduty#trigger)
107
133
  def trigger(description, options = {})
108
- super(description, { :incident_key => incident_key }.merge(options))
134
+ super(description, { incident_key: incident_key }.merge(options))
109
135
  end
110
136
 
111
137
  # Acknowledge the referenced incident. While an incident is acknowledged, it
@@ -152,12 +178,11 @@ class PagerdutyIncident < Pagerduty
152
178
  private
153
179
 
154
180
  def modify_incident(event_type, description, details)
155
- options = { :incident_key => incident_key }
181
+ options = { incident_key: incident_key }
156
182
  options[:description] = description if description
157
183
  options[:details] = details if details
158
184
  resp = api_call(event_type, options)
159
185
  ensure_success(resp)
160
186
  self
161
187
  end
162
-
163
188
  end
@@ -1,40 +1,52 @@
1
1
  # encoding: utf-8
2
- require 'json'
3
- require 'net/http'
4
- require 'net/https'
5
-
6
- # @api private
7
- module Pagerduty::HttpTransport
8
- extend self
9
-
10
- HOST = "events.pagerduty.com"
11
- PORT = 443
12
- PATH = "/generic/2010-04-15/create_event.json"
13
-
14
- def send_payload(payload = {})
15
- response = post payload.to_json
16
- response.error! unless transported?(response)
17
- JSON.parse(response.body)
18
- end
2
+ require "json"
3
+ require "net/https"
19
4
 
20
- private
5
+ class Pagerduty
6
+ # @api private
7
+ class HttpTransport
8
+ HOST = "events.pagerduty.com"
9
+ PORT = 443
10
+ PATH = "/generic/2010-04-15/create_event.json"
21
11
 
22
- def post(payload)
23
- post = Net::HTTP::Post.new(PATH)
24
- post.body = payload
25
- http.request(post)
26
- end
12
+ def initialize(options = {})
13
+ @options = options
14
+ end
27
15
 
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
16
+ def send_payload(payload = {})
17
+ response = post payload.to_json
18
+ response.error! unless transported?(response)
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ private
23
+
24
+ def post(payload)
25
+ post = Net::HTTP::Post.new(PATH)
26
+ post.body = payload
27
+ http.request(post)
28
+ end
29
+
30
+ def http
31
+ http = http_proxy.new(HOST, PORT)
32
+ http.use_ssl = true
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
34
+ http.open_timeout = 60
35
+ http.read_timeout = 60
36
+ http
37
+ end
38
+
39
+ def http_proxy
40
+ Net::HTTP.Proxy(
41
+ @options[:proxy_host],
42
+ @options[:proxy_port],
43
+ @options[:proxy_username],
44
+ @options[:proxy_password],
45
+ )
46
+ end
36
47
 
37
- def transported?(response)
38
- response.kind_of? Net::HTTPSuccess or response.kind_of? Net::HTTPRedirection
48
+ def transported?(response)
49
+ response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
50
+ end
39
51
  end
40
52
  end
@@ -1,3 +1,3 @@
1
1
  class Pagerduty
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -1,15 +1,16 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # encoding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'pagerduty/version'
4
+ require "pagerduty/version"
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "pagerduty"
8
8
  gem.version = Pagerduty::VERSION
9
9
  gem.authors = ["Charlie Somerville", "Orien Madgwick"]
10
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}
11
+ gem.description =
12
+ "Provides a lightweight interface for calling the PagerDuty Integration API"
13
+ gem.summary = "Pagerduty Integration API client library"
13
14
  gem.homepage = "http://github.com/envato/pagerduty"
14
15
  gem.license = "MIT"
15
16
 
@@ -19,13 +20,13 @@ https://github.com/envato/pagerduty#upgrading-to-version-200
19
20
  MSG
20
21
 
21
22
  gem.files = `git ls-files`.split($/)
22
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
23
24
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
25
  gem.require_paths = ["lib"]
25
26
 
26
27
  gem.add_runtime_dependency "json", ">= 1.7.7"
27
- gem.add_development_dependency "bundler", "~> 1.7"
28
+ gem.add_development_dependency "bundler"
28
29
  gem.add_development_dependency "rake"
29
- gem.add_development_dependency "rspec"
30
30
  gem.add_development_dependency "rspec-given"
31
+ gem.add_development_dependency "rubocop", "0.34.2"
31
32
  end
@@ -2,53 +2,70 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe Pagerduty::HttpTransport do
5
- Given(:http_transport) { Pagerduty::HttpTransport }
5
+ Given(:http_transport) { Pagerduty::HttpTransport.new(options) }
6
6
 
7
- Given(:http) { double.as_null_object }
7
+ Given(:options) { {} }
8
+ Given(:http) { spy }
9
+ Given(:http_proxy) { spy(new: http) }
8
10
  Given { allow(http).to receive(:request).and_return(standard_response) }
9
- Given { allow(Net::HTTP).to receive(:new).and_return(http) }
10
- Given(:post) { double.as_null_object }
11
+ Given { allow(Net::HTTP).to receive(:Proxy).and_return(http_proxy) }
12
+ Given(:post) { spy }
11
13
  Given { allow(Net::HTTP::Post).to receive(:new).and_return(post) }
12
14
 
13
15
  describe "::send_payload" do
14
- Given(:payload) { {
15
- event_type: "trigger",
16
- service_key: "test-srvc-key",
17
- description: "test-desc",
18
- details: { key: "value" },
19
- } }
16
+ Given(:payload) {
17
+ {
18
+ event_type: "trigger",
19
+ service_key: "test-srvc-key",
20
+ description: "test-desc",
21
+ details: { key: "value" },
22
+ }
23
+ }
20
24
 
21
25
  When(:response) { http_transport.send_payload(payload) }
22
26
 
23
27
  describe "provides the correct request" do
24
28
  Then {
25
29
  expect(post).to have_received(:body=).with(
26
- '{"event_type":"trigger","service_key":"test-srvc-key","description":"test-desc","details":{"key":"value"}}'
30
+ '{"event_type":"trigger",'\
31
+ '"service_key":"test-srvc-key",'\
32
+ '"description":"test-desc",'\
33
+ '"details":{"key":"value"}}',
27
34
  )
28
35
  }
29
36
  end
30
37
 
31
38
  describe "handles all responses" do
32
-
33
39
  context "PagerDuty successfully creates the incident" do
34
- Given { allow(http).to receive(:request).and_return(response_with_body(<<-JSON)) }
35
- {
36
- "status": "success",
37
- "incident_key": "My Incident Key",
38
- "message": "Event processed"
39
- }
40
- JSON
40
+ Given {
41
+ allow(http)
42
+ .to receive(:request)
43
+ .and_return(response_with_body(<<-JSON))
44
+ {
45
+ "status": "success",
46
+ "incident_key": "My Incident Key",
47
+ "message": "Event processed"
48
+ }
49
+ JSON
50
+ }
51
+
41
52
  Then { expect(response).to include("status" => "success") }
42
- Then { expect(response).to include("incident_key" => "My Incident Key") }
53
+ Then {
54
+ expect(response).to include("incident_key" => "My Incident Key")
55
+ }
43
56
  end
44
57
 
45
58
  context "PagerDuty fails to create the incident" do
46
- Given { allow(http).to receive(:request).and_return(response_with_body(<<-JSON)) }
47
- {
48
- "status": "failure",
49
- "message": "Event not processed"
50
- }
51
- JSON
59
+ Given {
60
+ allow(http)
61
+ .to receive(:request)
62
+ .and_return(response_with_body(<<-JSON))
63
+ {
64
+ "status": "failure",
65
+ "message": "Event not processed"
66
+ }
67
+ JSON
68
+ }
52
69
  Then { expect(response).to include("status" => "failure") }
53
70
  Then { expect(response).to_not include("incident_key") }
54
71
  end
@@ -61,9 +78,34 @@ describe Pagerduty::HttpTransport do
61
78
 
62
79
  describe "HTTPS use" do
63
80
  Then { expect(http).to have_received(:use_ssl=).with(true) }
64
- Then { expect(http).to have_received(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER) }
65
81
  Then { expect(http).to_not have_received(:ca_path=) }
66
82
  Then { expect(http).to_not have_received(:verify_depth=) }
83
+ Then {
84
+ expect(http)
85
+ .to have_received(:verify_mode=)
86
+ .with(OpenSSL::SSL::VERIFY_PEER)
87
+ }
88
+ end
89
+
90
+ describe "proxy use" do
91
+ Given(:options) {
92
+ {
93
+ proxy_host: "test-proxy-host",
94
+ proxy_port: "test-proxy-port",
95
+ proxy_username: "test-proxy-username",
96
+ proxy_password: "test-proxy-password",
97
+ }
98
+ }
99
+ Then {
100
+ expect(Net::HTTP)
101
+ .to have_received(:Proxy)
102
+ .with(
103
+ "test-proxy-host",
104
+ "test-proxy-port",
105
+ "test-proxy-username",
106
+ "test-proxy-password",
107
+ )
108
+ }
67
109
  end
68
110
 
69
111
  describe "timeouts" do
@@ -73,7 +115,9 @@ describe Pagerduty::HttpTransport do
73
115
  end
74
116
 
75
117
  def standard_response
76
- response_with_body '{ "status": "success", "incident_key": "My Incident Key" }'
118
+ response_with_body(
119
+ '{ "status": "success", "incident_key": "My Incident Key" }',
120
+ )
77
121
  end
78
122
 
79
123
  def response_with_body(body)
@@ -85,5 +129,4 @@ describe Pagerduty::HttpTransport do
85
129
  def bad_request
86
130
  Net::HTTPBadRequest.new 1.1, "400", "Bad Request"
87
131
  end
88
-
89
132
  end
@@ -2,16 +2,19 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe Pagerduty do
5
- Given(:pagerduty) { Pagerduty.new(service_key) }
6
- Given(:service_key) { "a-test-service-key" }
5
+ Given(:pagerduty) { Pagerduty.new(service_key, options) }
7
6
 
8
- Given(:transport) { double.as_null_object }
9
- Given { allow(Pagerduty).to receive(:transport).and_return(transport) }
7
+ Given(:service_key) { "a-test-service-key" }
8
+ Given(:options) { { transport: transport } }
9
+ Given(:transport) { spy }
10
10
 
11
11
  describe "#trigger" do
12
-
13
12
  describe "provides the correct request" do
14
- Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
13
+ Given {
14
+ allow(transport)
15
+ .to receive(:send_payload)
16
+ .and_return(standard_response)
17
+ }
15
18
 
16
19
  context "no options" do
17
20
  When(:incident) { pagerduty.trigger("a-test-description") }
@@ -46,12 +49,37 @@ describe Pagerduty do
46
49
  )
47
50
  }
48
51
  end
52
+
53
+ context "with proxy" do
54
+ Given(:options) {
55
+ {
56
+ proxy_host: "test-proxy-host",
57
+ proxy_port: "test-proxy-port",
58
+ proxy_username: "test-proxy-username",
59
+ proxy_password: "test-proxy-password",
60
+ }
61
+ }
62
+ Given {
63
+ allow(Pagerduty::HttpTransport)
64
+ .to receive(:new)
65
+ .and_return(transport)
66
+ }
67
+ When(:incident) { pagerduty.trigger("a-test-description") }
68
+ Then {
69
+ expect(Pagerduty::HttpTransport).to have_received(:new).with(
70
+ proxy_host: "test-proxy-host",
71
+ proxy_port: "test-proxy-port",
72
+ proxy_username: "test-proxy-username",
73
+ proxy_password: "test-proxy-password",
74
+ )
75
+ }
76
+ end
49
77
  end
50
78
 
51
79
  describe "handles all responses" do
52
-
53
80
  context "PagerDuty successfully creates the incident" do
54
- Given { allow(transport).to receive(:send_payload).and_return(
81
+ Given {
82
+ allow(transport).to receive(:send_payload).and_return(
55
83
  "status" => "success",
56
84
  "incident_key" => "My Incident Key",
57
85
  "message" => "Event processed",
@@ -61,13 +89,14 @@ describe Pagerduty do
61
89
  Then { expect(incident).to be_a PagerdutyIncident }
62
90
  Then { incident.service_key == service_key }
63
91
  Then { incident.incident_key == "My Incident Key" }
92
+ Then { incident.instance_variable_get("@transport") == transport }
64
93
  end
65
94
 
66
95
  context "PagerDuty fails to create the incident" do
67
96
  Given {
68
97
  allow(transport).to receive(:send_payload).and_return(
69
98
  "status" => "failure",
70
- "message" => "Event not processed"
99
+ "message" => "Event not processed",
71
100
  )
72
101
  }
73
102
  When(:incident) { pagerduty.trigger("description") }
@@ -75,7 +104,11 @@ describe Pagerduty do
75
104
  end
76
105
 
77
106
  context "PagerDuty responds with HTTP bad request" do
78
- Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
107
+ Given {
108
+ allow(transport)
109
+ .to receive(:send_payload)
110
+ .and_raise(Net::HTTPServerException.new(nil, nil))
111
+ }
79
112
  When(:incident) { pagerduty.trigger("description") }
80
113
  Then { expect(incident).to have_raised Net::HTTPServerException }
81
114
  end
@@ -83,21 +116,35 @@ describe Pagerduty do
83
116
  end
84
117
 
85
118
  describe "#get_incident" do
86
- Given(:incident_key) { "a-test-incident-key" }
87
119
  When(:incident) { pagerduty.get_incident(incident_key) }
88
- Then { expect(incident).to be_a PagerdutyIncident }
89
- Then { incident.service_key == service_key }
90
- Then { incident.incident_key == incident_key }
120
+
121
+ context "a valid incident_key" do
122
+ Given(:incident_key) { "a-test-incident-key" }
123
+ Then { expect(incident).to be_a PagerdutyIncident }
124
+ Then { incident.service_key == service_key }
125
+ Then { incident.incident_key == incident_key }
126
+ Then { incident.instance_variable_get("@transport") == transport }
127
+ end
128
+
129
+ context "a nil incident_key" do
130
+ Given(:incident_key) { nil }
131
+ Then { expect(incident).to have_failed ArgumentError }
132
+ end
91
133
  end
92
134
 
93
135
  describe PagerdutyIncident do
94
- Given(:incident) { PagerdutyIncident.new(service_key, incident_key) }
136
+ Given(:incident) {
137
+ PagerdutyIncident.new(service_key, incident_key, options)
138
+ }
95
139
  Given(:incident_key) { "a-test-incident-key" }
96
140
 
97
141
  describe "#acknowledge" do
98
-
99
142
  describe "provides the correct request" do
100
- Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
143
+ Given {
144
+ allow(transport)
145
+ .to receive(:send_payload)
146
+ .and_return(standard_response)
147
+ }
101
148
 
102
149
  context "no args" do
103
150
  When(:acknowledge) { incident.acknowledge }
@@ -123,7 +170,9 @@ describe Pagerduty do
123
170
  end
124
171
 
125
172
  context "a description and details" do
126
- When(:acknowledge) { incident.acknowledge("test-description", { my: "detail" }) }
173
+ When(:acknowledge) {
174
+ incident.acknowledge("test-description", my: "detail")
175
+ }
127
176
  Then {
128
177
  expect(transport).to have_received(:send_payload).with(
129
178
  event_type: "acknowledge",
@@ -137,17 +186,16 @@ describe Pagerduty do
137
186
  end
138
187
 
139
188
  describe "handles all responses" do
140
-
141
189
  context "PagerDuty successfully acknowledges the incident" do
142
190
  Given {
143
191
  allow(transport).to receive(:send_payload).and_return(
144
192
  "status" => "success",
145
193
  "incident_key" => "a-test-incident-key",
146
- "message" => "Event acknowledged"
194
+ "message" => "Event acknowledged",
147
195
  )
148
196
  }
149
197
  When(:acknowledge) { incident.acknowledge }
150
- Then { expect(acknowledge).to be incident}
198
+ Then { expect(acknowledge).to be incident }
151
199
  end
152
200
 
153
201
  context "PagerDuty fails to acknowledge the incident" do
@@ -163,7 +211,11 @@ describe Pagerduty do
163
211
  end
164
212
 
165
213
  context "PagerDuty responds with HTTP bad request" do
166
- Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
214
+ Given {
215
+ allow(transport)
216
+ .to receive(:send_payload)
217
+ .and_raise(Net::HTTPServerException.new(nil, nil))
218
+ }
167
219
  When(:acknowledge) { incident.acknowledge }
168
220
  Then { expect(acknowledge).to have_failed Net::HTTPServerException }
169
221
  end
@@ -171,9 +223,12 @@ describe Pagerduty do
171
223
  end
172
224
 
173
225
  describe "#resolve" do
174
-
175
226
  describe "provides the correct request" do
176
- Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
227
+ Given {
228
+ allow(transport)
229
+ .to receive(:send_payload)
230
+ .and_return(standard_response)
231
+ }
177
232
 
178
233
  context "no args" do
179
234
  When(:resolve) { incident.resolve }
@@ -199,7 +254,7 @@ describe Pagerduty do
199
254
  end
200
255
 
201
256
  context "a description and details" do
202
- When(:resolve) { incident.resolve("test-description", { my: "detail" }) }
257
+ When(:resolve) { incident.resolve("test-description", my: "detail") }
203
258
  Then {
204
259
  expect(transport).to have_received(:send_payload).with(
205
260
  event_type: "resolve",
@@ -213,24 +268,23 @@ describe Pagerduty do
213
268
  end
214
269
 
215
270
  describe "handles all responses" do
216
-
217
271
  context "PagerDuty successfully resolves the incident" do
218
272
  Given {
219
273
  allow(transport).to receive(:send_payload).and_return(
220
274
  "status" => "success",
221
275
  "incident_key" => "a-test-incident-key",
222
- "message" => "Event resolved"
276
+ "message" => "Event resolved",
223
277
  )
224
278
  }
225
279
  When(:resolve) { incident.resolve }
226
- Then { expect(resolve).to be incident}
280
+ Then { expect(resolve).to be incident }
227
281
  end
228
282
 
229
283
  context "PagerDuty fails to create the incident" do
230
284
  Given {
231
285
  allow(transport).to receive(:send_payload).and_return(
232
286
  "status" => "failure",
233
- "message" => "Event not resolved"
287
+ "message" => "Event not resolved",
234
288
  )
235
289
  }
236
290
  When(:resolve) { incident.resolve }
@@ -238,7 +292,11 @@ describe Pagerduty do
238
292
  end
239
293
 
240
294
  context "PagerDuty responds with HTTP bad request" do
241
- Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
295
+ Given {
296
+ allow(transport)
297
+ .to receive(:send_payload)
298
+ .and_raise(Net::HTTPServerException.new(nil, nil))
299
+ }
242
300
  When(:resolve) { incident.resolve }
243
301
  Then { expect(resolve).to have_failed Net::HTTPServerException }
244
302
  end
@@ -247,7 +305,11 @@ describe Pagerduty do
247
305
 
248
306
  describe "#trigger" do
249
307
  describe "provides the correct request" do
250
- Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
308
+ Given {
309
+ allow(transport)
310
+ .to receive(:send_payload)
311
+ .and_return(standard_response)
312
+ }
251
313
 
252
314
  context "no options" do
253
315
  Given(:incident_key) { "instance incident_key" }
@@ -263,7 +325,12 @@ describe Pagerduty do
263
325
  end
264
326
 
265
327
  context "with incident_key option" do
266
- When(:trigger) { incident.trigger("description", incident_key: "method param incident_key") }
328
+ When(:trigger) {
329
+ incident.trigger(
330
+ "description",
331
+ incident_key: "method param incident_key",
332
+ )
333
+ }
267
334
  Then {
268
335
  expect(transport).to have_received(:send_payload).with(
269
336
  incident_key: "method param incident_key",
@@ -286,7 +353,9 @@ describe Pagerduty do
286
353
  Given(:api_response) { double }
287
354
  Given(:message) { "a test error message" }
288
355
 
289
- When(:pagerduty_exception) { PagerdutyException.new(pagerduty_instance, api_response, message) }
356
+ When(:pagerduty_exception) {
357
+ PagerdutyException.new(pagerduty_instance, api_response, message)
358
+ }
290
359
 
291
360
  Then { pagerduty_exception.pagerduty_instance == pagerduty_instance }
292
361
  Then { pagerduty_exception.api_response == api_response }
@@ -1,9 +1,14 @@
1
1
  # encoding: utf-8
2
- require "pagerduty"
3
- require "rspec/given"
4
-
5
2
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
6
3
 
4
+ Warnings.silenced do
5
+ require "rspec/given"
6
+ require "json"
7
+ require "net/https"
8
+ end
9
+
10
+ require "pagerduty"
11
+
7
12
  RSpec.configure do |config|
8
13
  config.color = true
9
14
  end
@@ -0,0 +1,12 @@
1
+ module Warnings
2
+ def self.silenced(&block)
3
+ with_flag(nil, &block)
4
+ end
5
+
6
+ def self.with_flag(flag)
7
+ old_verbose, $VERBOSE = $VERBOSE, flag
8
+ yield
9
+ ensure
10
+ $VERBOSE = old_verbose
11
+ end
12
+ end
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.1
4
+ version: 2.1.0
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: 2015-03-29 00:00:00.000000000 Z
12
+ date: 2016-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '1.7'
34
+ version: '0'
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.7'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rspec
57
+ name: rspec-given
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -68,19 +68,19 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rspec-given
71
+ name: rubocop
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - '='
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: 0.34.2
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - '='
82
82
  - !ruby/object:Gem::Version
83
- version: '0'
83
+ version: 0.34.2
84
84
  description: Provides a lightweight interface for calling the PagerDuty Integration
85
85
  API
86
86
  email:
@@ -91,6 +91,7 @@ extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
93
93
  - ".gitignore"
94
+ - ".rubocop.yml"
94
95
  - ".travis.yml"
95
96
  - Gemfile
96
97
  - LICENSE.txt
@@ -104,6 +105,7 @@ files:
104
105
  - spec/pagerduty/http_transport_spec.rb
105
106
  - spec/pagerduty_spec.rb
106
107
  - spec/spec_helper.rb
108
+ - spec/support/warnings.rb
107
109
  homepage: http://github.com/envato/pagerduty
108
110
  licenses:
109
111
  - MIT
@@ -126,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
128
  version: '0'
127
129
  requirements: []
128
130
  rubyforge_project:
129
- rubygems_version: 2.4.5
131
+ rubygems_version: 2.5.1
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: Pagerduty Integration API client library
@@ -134,3 +136,4 @@ test_files:
134
136
  - spec/pagerduty/http_transport_spec.rb
135
137
  - spec/pagerduty_spec.rb
136
138
  - spec/spec_helper.rb
139
+ - spec/support/warnings.rb