slack-notifier 2.1.0 → 2.2.1

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: 2de365236adc9d11e81ff2d438f8f8623de09e8a
4
- data.tar.gz: cdf04ae41bb99465317aa0be35aecb9fa841d52b
3
+ metadata.gz: f5599f6fb6901d7b9c7009d6343288916829b97a
4
+ data.tar.gz: 60d21036bd104a7bda04b8dbb9da0b4a0747a8b7
5
5
  SHA512:
6
- metadata.gz: a83b5175eacbc6694b640ccdb42dbf11f7fcd46d35ee91c59da8d0cb48972f77fcaef35a2caa4175bf6e95b9480b51ed4a36a4bcff39e789f0b744ec5b56f06c
7
- data.tar.gz: 1f0fa17db345193cf89a412934743bc2b972c434e19557a6f64cbebbda15149b6690507306767a3ec4906b4f7811b0b38ef4fd753f4f2c22861940001ddaf7e8
6
+ metadata.gz: b6199f52c950a2470e651937f2f91ceb67abf95d0987b3c7cf441f9fe3e2e8b405a14a3570d110f367c308bdebafe7bd4f797661c9ce6f563d1ec5d54ea077bf
7
+ data.tar.gz: 9b7efc69cbeaa137a68e6240f94a198e8932ec4ea7deb48b45d9b46b5091b8118a1ad511d455c4eb91de7d38471c5e54119f5122586d7fed6b9463b6b4525daa
@@ -2,8 +2,11 @@
2
2
 
3
3
  require "net/http"
4
4
 
5
+
5
6
  module Slack
6
7
  class Notifier
8
+ class APIError < StandardError; end
9
+
7
10
  module Util
8
11
  class HTTPClient
9
12
  class << self
@@ -21,7 +24,14 @@ module Slack
21
24
  end
22
25
 
23
26
  def call
24
- http_obj.request request_obj
27
+ http_obj.request(request_obj).tap do |response|
28
+ unless response.is_a?(Net::HTTPSuccess)
29
+ raise Slack::Notifier::APIError, <<-MSG
30
+ The slack API returned an error: #{response.body} (HTTP Code #{response.code})
31
+ Check the "Handling Errors" section on https://api.slack.com/incoming-webhooks for more information
32
+ MSG
33
+ end
34
+ end
25
35
  end
26
36
 
27
37
  private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Slack
3
3
  class Notifier
4
- VERSION = "2.1.0".freeze # rubocop:disable Style/RedundantFreeze
4
+ VERSION = "2.2.1".freeze # rubocop:disable Style/RedundantFreeze
5
5
  end
6
6
  end
@@ -24,11 +24,31 @@ RSpec.describe Slack::Notifier::Util::HTTPClient do
24
24
 
25
25
  allow(Net::HTTP).to receive(:new).and_return(net_http_double)
26
26
  allow(net_http_double).to receive(:use_ssl=)
27
- allow(net_http_double).to receive(:request)
27
+ allow(net_http_double).to receive(:request).with(anything) do
28
+ Net::HTTPOK.new("GET", "200", "OK")
29
+ end
28
30
 
29
31
  expect(net_http_double).to receive(:open_timeout=).with(5)
30
32
 
31
33
  http_client.call
32
34
  end
33
35
  end
36
+
37
+ describe "#call" do
38
+ it "raises an error when the response is unsuccessful" do
39
+ net_http_double = instance_double("Net::HTTP")
40
+ http_client = described_class.new URI.parse("http://example.com"), {}
41
+ bad_request = Net::HTTPBadRequest.new("GET", "400", "Bad Request")
42
+
43
+ allow(bad_request).to receive(:body).and_return("something_bad")
44
+ allow(Net::HTTP).to receive(:new).and_return(net_http_double)
45
+ allow(net_http_double).to receive(:use_ssl=)
46
+ allow(net_http_double).to receive(:request).with(anything) do
47
+ bad_request
48
+ end
49
+
50
+ expect { http_client.call }.to raise_error(Slack::Notifier::APIError,
51
+ /something_bad \(HTTP Code 400\)/)
52
+ end
53
+ end
34
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " A slim ruby wrapper for posting to slack webhooks "
14
14
  email: