webpush 0.2.2 → 0.2.3

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: 7e6ccc3dd4787eae13fbe2da57c74f0d9f9c5c46
4
- data.tar.gz: 331ade4d71f9919f63984e1d2b746e73cda4d34a
3
+ metadata.gz: e953b3c824daee3dcc0f07104b619bde19b87c94
4
+ data.tar.gz: 514a2b64a435383854756ef2f0e639ef952bdfd2
5
5
  SHA512:
6
- metadata.gz: e41e01d1e5018e304f53bcc3de50e2ad7c0e6906b9f46fad27248e98bf9e969f760a1f1b598721d3da303ca007b08debf01ed4f880f89035056dcaa4d86f999f
7
- data.tar.gz: e48347fae1ea9fc2c14d13710b6ebe8344cc189189c135c1239110bc7d3404c20a791872687ee1f52c65299c8a53957c5de9bee52ef34f769a3bcad007a5f0db
6
+ metadata.gz: ac855621814b93e3a0cb7dc858f137a6d83e38e3949507ed60444cc2b4402d34afc593007baedb7bcd1a0e03548ede1ed51965dfd3c2bf82e51eba58436a6393
7
+ data.tar.gz: a5f40a0682ce56be44f09533825dcf45bc41c10931df064b8c21bb7a87afb5d2557c1e522830c03d086df7171b12ed27dca86975f97d760321eecd18de4ed385
@@ -1,4 +1,11 @@
1
1
  module Webpush
2
+
3
+ class ResponseError < RuntimeError
4
+ end
5
+
6
+ class InvalidSubscription < ResponseError
7
+ end
8
+
2
9
  class Request
3
10
  def initialize(endpoint, options = {})
4
11
  @endpoint = endpoint
@@ -18,9 +25,16 @@ module Webpush
18
25
  end
19
26
  req = Net::HTTP::Post.new(uri.request_uri, headers)
20
27
  req.body = body
21
- http.request(req)
22
- rescue => e
23
- raise e
28
+ resp = http.request(req)
29
+
30
+ if resp.is_a?(Net::HTTPGone) || #Firefox unsubscribed response
31
+ (resp.is_a?(Net::HTTPBadRequest) && resp.message == "UnauthorizedRegistration") #Chrome unsubscribed response
32
+ raise InvalidSubscription.new(resp.inspect)
33
+ elsif !resp.is_a?(Net::HTTPSuccess) #unknown/unhandled response error
34
+ raise ResponseError.new "host: #{uri.host}, #{resp.inspect}\nbody:\n#{resp.body}"
35
+ end
36
+
37
+ resp
24
38
  end
25
39
 
26
40
  def headers
@@ -1,3 +1,3 @@
1
1
  module Webpush
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - zaru@sakuraba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hkdf