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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0499dcd1f7c46766c0c0f310f4bb2e786fdc875c'
4
- data.tar.gz: 5aeeedf8d5ead80dad72c9804547f24c8aa7450a
3
+ metadata.gz: e6d555b555c5277dc1abbe12a9808292b62b241a
4
+ data.tar.gz: 3f12232353b917a3135ce12f33a38f1a2a7f5388
5
5
  SHA512:
6
- metadata.gz: 48ec18d9fe4529ab4e16fed5e63b347497c5b1b2e964d4c5771c9d130871c65be066e95e41a004c0631e33ccd4ee474c10297b5152d984c41b59523d44280261
7
- data.tar.gz: ad6df7b328130176806a8111f28c86469eee04f268731534f8f888750b4ec061d0fac7d48be870e7e58ad928945fd77bd8fcaba16126405c00022676de09b98e
6
+ metadata.gz: b7429002edc35b7d8e92cb15ff6d329f52257d0f36ab46f316440c31f3141869d5617973e4c3250d79abd05efa4d60f0918194ab3160b42866cb400ba6220a20
7
+ data.tar.gz: 1a22cb446da2ff49013a3a5474bb970bbfa5789b3d24c693be4aadca2eca64e94db242cbe4fc36185a77dee25b45c3259ef8edb834de273f136db4efbfa98746
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.11.2
3
+ - 2.2
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ before_install: gem install bundler
6
8
  script: "bundle exec rake spec"
7
9
  addons:
8
10
  code_climate:
@@ -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
@@ -4,3 +4,5 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task default: :spec
7
+
8
+ import './lib/tasks/webpush.rake'
@@ -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
@@ -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,
@@ -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
@@ -0,0 +1,7 @@
1
+ module Webpush
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load 'tasks/webpush.rake'
5
+ end
6
+ end
7
+ end
@@ -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) || #Firefox unsubscribed response
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
 
@@ -1,3 +1,3 @@
1
1
  module Webpush
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
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.3.4
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: 2018-05-25 00:00:00.000000000 Z
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.11
172
+ rubygems_version: 2.6.13
170
173
  signing_key:
171
174
  specification_version: 4
172
175
  summary: Encryption Utilities for Web Push payload.