webpush 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/CHANGELOG.md +133 -0
- data/README.md +2 -1
- data/Rakefile +2 -0
- data/lib/tasks/webpush.rake +14 -0
- data/lib/webpush.rb +2 -0
- data/lib/webpush/errors.rb +5 -0
- data/lib/webpush/railtie.rb +7 -0
- data/lib/webpush/request.rb +15 -5
- data/lib/webpush/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d555b555c5277dc1abbe12a9808292b62b241a
|
4
|
+
data.tar.gz: 3f12232353b917a3135ce12f33a38f1a2a7f5388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7429002edc35b7d8e92cb15ff6d329f52257d0f36ab46f316440c31f3141869d5617973e4c3250d79abd05efa4d60f0918194ab3160b42866cb400ba6220a20
|
7
|
+
data.tar.gz: 1a22cb446da2ff49013a3a5474bb970bbfa5789b3d24c693be4aadca2eca64e94db242cbe4fc36185a77dee25b45c3259ef8edb834de273f136db4efbfa98746
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [Unreleased](https://github.com/zaru/webpush/tree/HEAD)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.4...HEAD)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Fix \#55 and \#51: raise the proper error based on the HTTP status code [\#58](https://github.com/zaru/webpush/pull/58) ([collimarco](https://github.com/collimarco))
|
10
|
+
- Add urgency option [\#57](https://github.com/zaru/webpush/pull/57) ([collimarco](https://github.com/collimarco))
|
11
|
+
- Add Rake task to generate VAPID keys [\#54](https://github.com/zaru/webpush/pull/54) ([stevenharman](https://github.com/stevenharman))
|
12
|
+
|
13
|
+
## [v0.3.4](https://github.com/zaru/webpush/tree/v0.3.4) (2018-05-25)
|
14
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.3...v0.3.4)
|
15
|
+
|
16
|
+
**Merged pull requests:**
|
17
|
+
|
18
|
+
- add http timeout options [\#50](https://github.com/zaru/webpush/pull/50) ([aishek](https://github.com/aishek))
|
19
|
+
|
20
|
+
## [v0.3.3](https://github.com/zaru/webpush/tree/v0.3.3) (2017-11-06)
|
21
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.2...v0.3.3)
|
22
|
+
|
23
|
+
**Merged pull requests:**
|
24
|
+
|
25
|
+
- Add typ to JWT header fields [\#46](https://github.com/zaru/webpush/pull/46) ([ykzts](https://github.com/ykzts))
|
26
|
+
- Specify the version of JWT strictly [\#45](https://github.com/zaru/webpush/pull/45) ([ykzts](https://github.com/ykzts))
|
27
|
+
|
28
|
+
## [v0.3.2](https://github.com/zaru/webpush/tree/v0.3.2) (2017-07-01)
|
29
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.1...v0.3.2)
|
30
|
+
|
31
|
+
**Merged pull requests:**
|
32
|
+
|
33
|
+
- feat: improve response error codes [\#39](https://github.com/zaru/webpush/pull/39) ([glennr](https://github.com/glennr))
|
34
|
+
- Update README.md [\#38](https://github.com/zaru/webpush/pull/38) ([kitaindia](https://github.com/kitaindia))
|
35
|
+
- Fix code example: Add close bracket [\#37](https://github.com/zaru/webpush/pull/37) ([kuranari](https://github.com/kuranari))
|
36
|
+
- fix code in README [\#36](https://github.com/zaru/webpush/pull/36) ([kuranari](https://github.com/kuranari))
|
37
|
+
- Minor fix in README: Close code blocks [\#32](https://github.com/zaru/webpush/pull/32) ([nicolas-fricke](https://github.com/nicolas-fricke))
|
38
|
+
- Copy edits for README clarifying GCM requirements [\#30](https://github.com/zaru/webpush/pull/30) ([rossta](https://github.com/rossta))
|
39
|
+
- Adding VAPID documentation [\#28](https://github.com/zaru/webpush/pull/28) ([rossta](https://github.com/rossta))
|
40
|
+
|
41
|
+
## [v0.3.1](https://github.com/zaru/webpush/tree/v0.3.1) (2016-10-24)
|
42
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.3.0...v0.3.1)
|
43
|
+
|
44
|
+
**Merged pull requests:**
|
45
|
+
|
46
|
+
- Bug fix invalid base64 [\#29](https://github.com/zaru/webpush/pull/29) ([rossta](https://github.com/rossta))
|
47
|
+
- Clarify VAPID usage further in README [\#27](https://github.com/zaru/webpush/pull/27) ([rossta](https://github.com/rossta))
|
48
|
+
|
49
|
+
## [v0.3.0](https://github.com/zaru/webpush/tree/v0.3.0) (2016-10-14)
|
50
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.2.5...v0.3.0)
|
51
|
+
|
52
|
+
**Merged pull requests:**
|
53
|
+
|
54
|
+
- Implement VAPID authorization [\#26](https://github.com/zaru/webpush/pull/26) ([rossta](https://github.com/rossta))
|
55
|
+
|
56
|
+
## [v0.2.5](https://github.com/zaru/webpush/tree/v0.2.5) (2016-09-14)
|
57
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.2.4...v0.2.5)
|
58
|
+
|
59
|
+
**Merged pull requests:**
|
60
|
+
|
61
|
+
- api key only needed for old google apis [\#24](https://github.com/zaru/webpush/pull/24) ([mohamedhafez](https://github.com/mohamedhafez))
|
62
|
+
|
63
|
+
## [v0.2.4](https://github.com/zaru/webpush/tree/v0.2.4) (2016-08-29)
|
64
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.2.3...v0.2.4)
|
65
|
+
|
66
|
+
**Merged pull requests:**
|
67
|
+
|
68
|
+
- VERIFY\_PEER by default - no need for a cert\_store option [\#20](https://github.com/zaru/webpush/pull/20) ([mohamedhafez](https://github.com/mohamedhafez))
|
69
|
+
|
70
|
+
## [v0.2.3](https://github.com/zaru/webpush/tree/v0.2.3) (2016-06-19)
|
71
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.2.2...v0.2.3)
|
72
|
+
|
73
|
+
**Merged pull requests:**
|
74
|
+
|
75
|
+
- detect and handle response errors [\#18](https://github.com/zaru/webpush/pull/18) ([mohamedhafez](https://github.com/mohamedhafez))
|
76
|
+
|
77
|
+
## [v0.2.2](https://github.com/zaru/webpush/tree/v0.2.2) (2016-06-13)
|
78
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.2.1...v0.2.2)
|
79
|
+
|
80
|
+
**Merged pull requests:**
|
81
|
+
|
82
|
+
- Don't include API key for firefox or other browsers [\#16](https://github.com/zaru/webpush/pull/16) ([mohamedhafez](https://github.com/mohamedhafez))
|
83
|
+
- Option to specify a cert store [\#15](https://github.com/zaru/webpush/pull/15) ([mohamedhafez](https://github.com/mohamedhafez))
|
84
|
+
- show ttl option in README [\#14](https://github.com/zaru/webpush/pull/14) ([mohamedhafez](https://github.com/mohamedhafez))
|
85
|
+
|
86
|
+
## [v0.2.1](https://github.com/zaru/webpush/tree/v0.2.1) (2016-05-23)
|
87
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.2.0...v0.2.1)
|
88
|
+
|
89
|
+
**Merged pull requests:**
|
90
|
+
|
91
|
+
- Make the response more detailed. [\#10](https://github.com/zaru/webpush/pull/10) ([kevinjom](https://github.com/kevinjom))
|
92
|
+
|
93
|
+
## [v0.2.0](https://github.com/zaru/webpush/tree/v0.2.0) (2016-05-16)
|
94
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.6...v0.2.0)
|
95
|
+
|
96
|
+
**Merged pull requests:**
|
97
|
+
|
98
|
+
- Make message payload optional [\#8](https://github.com/zaru/webpush/pull/8) ([rossta](https://github.com/rossta))
|
99
|
+
- Add specs [\#7](https://github.com/zaru/webpush/pull/7) ([rossta](https://github.com/rossta))
|
100
|
+
|
101
|
+
## [v0.1.6](https://github.com/zaru/webpush/tree/v0.1.6) (2016-05-12)
|
102
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.5...v0.1.6)
|
103
|
+
|
104
|
+
**Merged pull requests:**
|
105
|
+
|
106
|
+
- Add rake binstub [\#6](https://github.com/zaru/webpush/pull/6) ([rossta](https://github.com/rossta))
|
107
|
+
- Add syntax highlighting to README snippets [\#5](https://github.com/zaru/webpush/pull/5) ([rossta](https://github.com/rossta))
|
108
|
+
- Extract encryption module [\#4](https://github.com/zaru/webpush/pull/4) ([rossta](https://github.com/rossta))
|
109
|
+
- Add some happy case specs [\#3](https://github.com/zaru/webpush/pull/3) ([waheedel](https://github.com/waheedel))
|
110
|
+
|
111
|
+
## [v0.1.5](https://github.com/zaru/webpush/tree/v0.1.5) (2016-04-29)
|
112
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.4...v0.1.5)
|
113
|
+
|
114
|
+
**Merged pull requests:**
|
115
|
+
|
116
|
+
- add Ttl header parameter [\#1](https://github.com/zaru/webpush/pull/1) ([shouta-dev](https://github.com/shouta-dev))
|
117
|
+
|
118
|
+
## [v0.1.4](https://github.com/zaru/webpush/tree/v0.1.4) (2016-04-27)
|
119
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.3...v0.1.4)
|
120
|
+
|
121
|
+
## [v0.1.3](https://github.com/zaru/webpush/tree/v0.1.3) (2016-04-13)
|
122
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.2...v0.1.3)
|
123
|
+
|
124
|
+
## [v0.1.2](https://github.com/zaru/webpush/tree/v0.1.2) (2016-04-12)
|
125
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.1...v0.1.2)
|
126
|
+
|
127
|
+
## [v0.1.1](https://github.com/zaru/webpush/tree/v0.1.1) (2016-03-31)
|
128
|
+
[Full Changelog](https://github.com/zaru/webpush/compare/v0.1.0...v0.1.1)
|
129
|
+
|
130
|
+
## [v0.1.0](https://github.com/zaru/webpush/tree/v0.1.0) (2016-03-31)
|
131
|
+
|
132
|
+
|
133
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -247,7 +247,8 @@ Webpush.payload_send(
|
|
247
247
|
message: JSON.generate(message),
|
248
248
|
p256dh: "BO/aG9nYXNkZmFkc2ZmZHNmYWRzZmFl...",
|
249
249
|
auth: "aW1hcmthcmFpa3V6ZQ==",
|
250
|
-
ttl: 600 #optional, ttl in seconds, defaults to 2419200 (4 weeks)
|
250
|
+
ttl: 600, # optional, ttl in seconds, defaults to 2419200 (4 weeks)
|
251
|
+
urgency: 'normal' # optional, it can be very-low, low, normal, high, defaults to normal
|
251
252
|
)
|
252
253
|
```
|
253
254
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :webpush do
|
2
|
+
desc 'Generate VAPID public/private key pair'
|
3
|
+
task :generate_keys do
|
4
|
+
require 'webpush'
|
5
|
+
|
6
|
+
Webpush.generate_key.tap do |keypair|
|
7
|
+
puts <<-KEYS
|
8
|
+
Generated VAPID keypair:
|
9
|
+
Public -> #{keypair.public_key}
|
10
|
+
Private -> #{keypair.private_key}
|
11
|
+
KEYS
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/webpush.rb
CHANGED
@@ -9,6 +9,7 @@ require 'webpush/errors'
|
|
9
9
|
require 'webpush/vapid_key'
|
10
10
|
require 'webpush/encryption'
|
11
11
|
require 'webpush/request'
|
12
|
+
require 'webpush/railtie' if defined?(Rails)
|
12
13
|
|
13
14
|
module Webpush
|
14
15
|
class << self
|
@@ -26,6 +27,7 @@ module Webpush
|
|
26
27
|
# @option vapid [String] :private_key the VAPID private key
|
27
28
|
# @param options [Hash<Symbol,String>] additional options for the notification
|
28
29
|
# @option options [#to_s] :ttl Time-to-live in seconds
|
30
|
+
# @option options [#to_s] :urgency Urgency can be very-low, low, normal, high
|
29
31
|
def payload_send(message: "", endpoint:, p256dh: "", auth: "", vapid: {}, **options)
|
30
32
|
subscription = {
|
31
33
|
endpoint: endpoint,
|
data/lib/webpush/errors.rb
CHANGED
@@ -17,7 +17,12 @@ module Webpush
|
|
17
17
|
|
18
18
|
class ExpiredSubscription < ResponseError; end
|
19
19
|
|
20
|
+
class Unauthorized < ResponseError; end
|
21
|
+
|
20
22
|
class PayloadTooLarge < ResponseError; end
|
21
23
|
|
22
24
|
class TooManyRequests < ResponseError; end
|
25
|
+
|
26
|
+
class PushServiceError < ResponseError; end
|
27
|
+
|
23
28
|
end
|
data/lib/webpush/request.rb
CHANGED
@@ -26,15 +26,19 @@ module Webpush
|
|
26
26
|
req.body = body
|
27
27
|
resp = http.request(req)
|
28
28
|
|
29
|
-
if resp.is_a?(Net::HTTPGone)
|
30
|
-
(resp.is_a?(Net::HTTPBadRequest) && resp.message == "UnauthorizedRegistration") #Chrome unsubscribed response
|
31
|
-
raise InvalidSubscription.new(resp, uri.host)
|
32
|
-
elsif resp.is_a?(Net::HTTPNotFound) # 404
|
29
|
+
if resp.is_a?(Net::HTTPGone) # 410
|
33
30
|
raise ExpiredSubscription.new(resp, uri.host)
|
31
|
+
elsif resp.is_a?(Net::HTTPNotFound) # 404
|
32
|
+
raise InvalidSubscription.new(resp, uri.host)
|
33
|
+
elsif resp.is_a?(Net::HTTPUnauthorized) || # 401, Mozilla autopush
|
34
|
+
resp.is_a?(Net::HTTPBadRequest) && resp.message == "UnauthorizedRegistration" # 400, Google FCM
|
35
|
+
raise Unauthorized.new(resp, uri.host)
|
34
36
|
elsif resp.is_a?(Net::HTTPRequestEntityTooLarge) # 413
|
35
37
|
raise PayloadTooLarge.new(resp, uri.host)
|
36
38
|
elsif resp.is_a?(Net::HTTPTooManyRequests) # 429, try again later!
|
37
39
|
raise TooManyRequests.new(resp, uri.host)
|
40
|
+
elsif resp.is_a?(Net::HTTPServerError) # 5xx
|
41
|
+
raise PushServiceError.new(resp, uri.host)
|
38
42
|
elsif !resp.is_a?(Net::HTTPSuccess) # unknown/unhandled response error
|
39
43
|
raise ResponseError.new(resp, uri.host)
|
40
44
|
end
|
@@ -46,6 +50,7 @@ module Webpush
|
|
46
50
|
headers = {}
|
47
51
|
headers["Content-Type"] = "application/octet-stream"
|
48
52
|
headers["Ttl"] = ttl
|
53
|
+
headers["Urgency"] = urgency
|
49
54
|
|
50
55
|
if @payload.has_key?(:server_public_key)
|
51
56
|
headers["Content-Encoding"] = "aesgcm"
|
@@ -89,6 +94,10 @@ module Webpush
|
|
89
94
|
@options.fetch(:ttl).to_s
|
90
95
|
end
|
91
96
|
|
97
|
+
def urgency
|
98
|
+
@options.fetch(:urgency).to_s
|
99
|
+
end
|
100
|
+
|
92
101
|
def dh_param
|
93
102
|
trim_encode64(@payload.fetch(:server_public_key))
|
94
103
|
end
|
@@ -131,7 +140,8 @@ module Webpush
|
|
131
140
|
|
132
141
|
def default_options
|
133
142
|
{
|
134
|
-
ttl: 60*60*24*7*4 # 4 weeks
|
143
|
+
ttl: 60*60*24*7*4, # 4 weeks
|
144
|
+
urgency: 'normal'
|
135
145
|
}
|
136
146
|
end
|
137
147
|
|
data/lib/webpush/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zaru@sakuraba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hkdf
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
134
|
- ".travis.yml"
|
135
|
+
- CHANGELOG.md
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE
|
137
138
|
- README.md
|
@@ -140,9 +141,11 @@ files:
|
|
140
141
|
- bin/rake
|
141
142
|
- bin/rspec
|
142
143
|
- bin/setup
|
144
|
+
- lib/tasks/webpush.rake
|
143
145
|
- lib/webpush.rb
|
144
146
|
- lib/webpush/encryption.rb
|
145
147
|
- lib/webpush/errors.rb
|
148
|
+
- lib/webpush/railtie.rb
|
146
149
|
- lib/webpush/request.rb
|
147
150
|
- lib/webpush/vapid_key.rb
|
148
151
|
- lib/webpush/version.rb
|
@@ -166,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
169
|
version: '0'
|
167
170
|
requirements: []
|
168
171
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.6.
|
172
|
+
rubygems_version: 2.6.13
|
170
173
|
signing_key:
|
171
174
|
specification_version: 4
|
172
175
|
summary: Encryption Utilities for Web Push payload.
|