pushpad 0.13.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: 859e8674ef09ee84c2bb6ab00a837aef0d48b2039774625974aae32f2ca3a2ee
4
- data.tar.gz: 71086f6109284229c8c02d01d48ca0980a4621065d43875a4131bc867b7c002a
3
+ metadata.gz: dccdac2f6334014fc3b1a7fa42b5cc0644135df02b3e58f9c44f17e7fe00a27e
4
+ data.tar.gz: 69c4ea4985bdd6c120445e36c58e8adf0f572874dd7fd3ef929ad90176c84b18
5
5
  SHA512:
6
- metadata.gz: 2cd5ae106f55214c5c16a7fc2eae7d33ecb4e6fb0c9b2917d44c643a754b5a6b124630b356969d9a230a25ed89fe0726b900d001452c777dba677f629c52ce6d
7
- data.tar.gz: f06eb68e6b96bbf6b6f59ab687c838fdc72a6a5f9df61a86e48772bd7f74d6990416d69ddbe8ea71855b8a42ba453e363c2fb4a1ae4b97268d437a545b9a0166
6
+ metadata.gz: b9ab88edcae1bcb44f8e6e1b388d25ee47459c81b6f2c72c9b450a1bf64b08dd874b019d518733a1cb4cf53c7f4f3c8feec7ffc418a144c81cc6b0864c1b67d2
7
+ data.tar.gz: 6540c56bb6cbaa46e496098669d081c7c66f35c20e1cc82bb4602510a696179c9fa71ba381dd1693c181fe32adf8a05ef5224ca9a2ea22f16648e35b2eca138b
@@ -10,9 +10,9 @@ jobs:
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
- ruby-version: ['2.7', '3.0', '3.1']
13
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
14
14
  steps:
15
- - uses: actions/checkout@v2
15
+ - uses: actions/checkout@v3
16
16
  - name: Set up Ruby
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
data/README.md CHANGED
@@ -3,13 +3,9 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/pushpad.svg)](https://badge.fury.io/rb/pushpad)
4
4
  ![Build Status](https://github.com/pushpad/pushpad-ruby/workflows/CI/badge.svg)
5
5
 
6
- [Pushpad](https://pushpad.xyz) is a service for sending push notifications from your web app. It supports the **Push API** (Chrome, Firefox, Opera, Edge) and **APNs** (Safari).
6
+ [Pushpad](https://pushpad.xyz) is a service for sending push notifications from websites and web apps. It uses the **Push API**, which is a standard supported by all major browsers (Chrome, Firefox, Opera, Edge, Safari).
7
7
 
8
- Features:
9
-
10
- - notifications are delivered even when the user is not on your website
11
- - users don't need to install any app or plugin
12
- - you can target specific users or send bulk notifications
8
+ The notifications are delivered in real time even when the users are not on your website and you can target specific users or send bulk notifications.
13
9
 
14
10
  ## Installation
15
11
 
@@ -55,17 +51,40 @@ Pushpad.signature_for current_user.id
55
51
 
56
52
  ```ruby
57
53
  notification = Pushpad::Notification.new({
54
+ # required, the main content of the notification
58
55
  body: "Hello world!",
59
- title: "Website Name", # optional, defaults to your project name
60
- target_url: "https://example.com", # optional, defaults to your project website
61
- icon_url: "https://example.com/assets/icon.png", # optional, defaults to the project icon
62
- badge_url: "https://example.com/assets/badge.png" # optional, defaults to the project badge
63
- image_url: "https://example.com/assets/image.png", # optional, an image to display in the notification content
64
- ttl: 604800, # optional, drop the notification after this number of seconds if a device is offline
65
- require_interaction: true, # optional, prevent Chrome on desktop from automatically closing the notification after a few seconds
66
- silent: false, # optional, enable this option if you want a mute notification without any sound
67
- urgent: false, # optional, enable this option only for time-sensitive alerts (e.g. incoming phone call)
68
- custom_data: "123", # optional, a string that is passed as an argument to action button callbacks
56
+
57
+ # optional, the title of the notification (defaults to your project name)
58
+ title: "Website Name",
59
+
60
+ # optional, open this link on notification click (defaults to your project website)
61
+ target_url: "https://example.com",
62
+
63
+ # optional, the icon of the notification (defaults to the project icon)
64
+ icon_url: "https://example.com/assets/icon.png",
65
+
66
+ # optional, the small icon displayed in the status bar (defaults to the project badge)
67
+ badge_url: "https://example.com/assets/badge.png",
68
+
69
+ # optional, an image to display in the notification content
70
+ # see https://pushpad.xyz/docs/sending_images
71
+ image_url: "https://example.com/assets/image.png",
72
+
73
+ # optional, drop the notification after this number of seconds if a device is offline
74
+ ttl: 604800,
75
+
76
+ # optional, prevent Chrome on desktop from automatically closing the notification after a few seconds
77
+ require_interaction: true,
78
+
79
+ # optional, enable this option if you want a mute notification without any sound
80
+ silent: false,
81
+
82
+ # optional, enable this option only for time-sensitive alerts (e.g. incoming phone call)
83
+ urgent: false,
84
+
85
+ # optional, a string that is passed as an argument to action button callbacks
86
+ custom_data: "123",
87
+
69
88
  # optional, add some action buttons to the notification
70
89
  # see https://pushpad.xyz/docs/action_buttons
71
90
  actions: [
@@ -76,10 +95,14 @@ notification = Pushpad::Notification.new({
76
95
  action: "myActionName" # optional
77
96
  }
78
97
  ],
79
- starred: true, # optional, bookmark the notification in the Pushpad dashboard (e.g. to highlight manual notifications)
98
+
99
+ # optional, bookmark the notification in the Pushpad dashboard (e.g. to highlight manual notifications)
100
+ starred: true,
101
+
80
102
  # optional, use this option only if you need to create scheduled notifications (max 5 days)
81
103
  # see https://pushpad.xyz/docs/schedule_notifications
82
104
  send_at: Time.utc(2016, 7, 25, 10, 9),
105
+
83
106
  # optional, add the notification to custom categories for stats aggregation
84
107
  # see https://pushpad.xyz/docs/monitoring
85
108
  custom_metrics: ['examples', 'another_metric'] # up to 3 metrics per notification
@@ -100,7 +123,8 @@ notification.deliver_to users, tags: ['events']
100
123
  notification.broadcast tags: ['segment1', 'segment2']
101
124
 
102
125
  # you can use boolean expressions
103
- # they must be in the disjunctive normal form (without parenthesis)
126
+ # they can include parentheses and the operators !, &&, || (from highest to lowest precedence)
127
+ # https://pushpad.xyz/docs/tags
104
128
  notification.broadcast tags: ['zip_code:28865 && !optout:local_events || friend_of:Organizer123']
105
129
  notification.deliver_to users, tags: ['tag1 && tag2', 'tag3'] # equal to 'tag1 && tag2 || tag3'
106
130
 
@@ -138,22 +162,22 @@ notification = Pushpad::Notification.find(42)
138
162
 
139
163
  # get basic attributes
140
164
  notification.id # => 42
141
- notification.title # => "Foo Bar",
142
- notification.body # => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
143
- notification.target_url # => "https://example.com",
144
- notification.ttl # => 604800,
145
- notification.require_interaction # => false,
146
- notification.silent # => false,
147
- notification.urgent # => false,
148
- notification.icon_url # => "https://example.com/assets/icon.png",
149
- notification.badge_url # => "https://example.com/assets/badge.png",
165
+ notification.title # => "Foo Bar"
166
+ notification.body # => "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
167
+ notification.target_url # => "https://example.com"
168
+ notification.ttl # => 604800
169
+ notification.require_interaction # => false
170
+ notification.silent # => false
171
+ notification.urgent # => false
172
+ notification.icon_url # => "https://example.com/assets/icon.png"
173
+ notification.badge_url # => "https://example.com/assets/badge.png"
150
174
 
151
175
  # `created_at` is a `Time` instance
152
- notification.created_at.utc.to_s # => "2016-07-06 10:09:14 UTC",
176
+ notification.created_at.utc.to_s # => "2016-07-06 10:09:14 UTC"
153
177
 
154
178
  # get statistics
155
179
  notification.scheduled_count # => 1
156
- notification.successfully_sent_count # => 4,
180
+ notification.successfully_sent_count # => 4
157
181
  notification.opened_count # => 2
158
182
  ```
159
183
 
@@ -164,7 +188,7 @@ notifications = Pushpad::Notification.find_all(project_id: 5)
164
188
 
165
189
  # same attributes as for single notification in example above
166
190
  notifications[0].id # => 42
167
- notifications[0].title # => "Foo Bar",
191
+ notifications[0].title # => "Foo Bar"
168
192
  ```
169
193
 
170
194
  If `Pushpad.project_id` is defined, the `project_id` option can be
@@ -177,6 +201,26 @@ to get the full list in multiple requests.
177
201
  notifications = Pushpad::Notification.find_all(project_id: 5, page: 2)
178
202
  ```
179
203
 
204
+ ## Scheduled notifications
205
+
206
+ You can create scheduled notifications that will be sent in the future:
207
+
208
+ ```ruby
209
+ notification = Pushpad::Notification.new({
210
+ body: "This notification will be sent after 60 seconds",
211
+ send_at: Time.now.utc + 60
212
+ })
213
+
214
+ notification.broadcast
215
+ ```
216
+
217
+ You can also cancel a scheduled notification:
218
+
219
+ ```ruby
220
+ notification = Pushpad::Notification.find(5)
221
+ notification.cancel
222
+ ```
223
+
180
224
  ## Getting subscription count
181
225
 
182
226
  You can retrieve the number of subscriptions for a given project,
@@ -8,6 +8,9 @@ module Pushpad
8
8
 
9
9
  class FindError < RuntimeError
10
10
  end
11
+
12
+ class CancelError < RuntimeError
13
+ end
11
14
 
12
15
  class ReadonlyError < RuntimeError
13
16
  end
@@ -87,6 +90,14 @@ module Pushpad
87
90
  end
88
91
  deliver req_body(uids, options[:tags]), options
89
92
  end
93
+
94
+ def cancel
95
+ response = Request.delete("https://pushpad.xyz/api/v1/notifications/#{id}/cancel")
96
+
97
+ unless response.code == "204"
98
+ raise CancelError, "Response #{response.code} #{response.message}: #{response.body}"
99
+ end
100
+ end
90
101
 
91
102
  private
92
103
 
@@ -18,6 +18,10 @@ module Pushpad
18
18
  request.body = body
19
19
  end
20
20
  end
21
+
22
+ def delete(endpoint, options = {})
23
+ perform(Net::HTTP::Delete, endpoint, options)
24
+ end
21
25
 
22
26
  private
23
27
 
data/lib/pushpad.rb CHANGED
@@ -26,7 +26,7 @@ module Pushpad
26
26
 
27
27
  def self.signature_for(data)
28
28
  raise "You must set Pushpad.auth_token" unless Pushpad.auth_token
29
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), self.auth_token, data.to_s)
29
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), self.auth_token, data.to_s)
30
30
  end
31
31
 
32
32
  end
data/pushpad.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pushpad"
3
- spec.version = '0.13.0'
3
+ spec.version = '1.1.0'
4
4
  spec.authors = ["Pushpad"]
5
5
  spec.email = ["support@pushpad.xyz"]
6
6
  spec.summary = "Web push notifications for Chrome, Firefox, Opera, Edge and Safari using Pushpad."
@@ -28,7 +28,6 @@ module Pushpad
28
28
  end
29
29
 
30
30
  def stub_notification_post(project_id, params = {}, response_body = "{}")
31
-
32
31
  stub_request(:post, "https://pushpad.xyz/api/v1/projects/#{project_id}/notifications").
33
32
  with(body: hash_including(params)).
34
33
  to_return(status: 201, body: response_body)
@@ -38,6 +37,16 @@ module Pushpad
38
37
  stub_request(:post, "https://pushpad.xyz/api/v1/projects/#{project_id}/notifications").
39
38
  to_return(status: 403)
40
39
  end
40
+
41
+ def stub_notification_delete(notification_id)
42
+ stub_request(:delete, "https://pushpad.xyz/api/v1/notifications/#{notification_id}/cancel").
43
+ to_return(status: 204)
44
+ end
45
+
46
+ def stub_failing_notification_delete(notification_id)
47
+ stub_request(:delete, "https://pushpad.xyz/api/v1/notifications/#{notification_id}/cancel").
48
+ to_return(status: 404)
49
+ end
41
50
 
42
51
  describe ".new" do
43
52
  it "allows delivering notifications even if an id attribute is supplied" do
@@ -409,5 +418,27 @@ module Pushpad
409
418
  end
410
419
  end
411
420
  end
421
+
422
+ describe "#cancel" do
423
+ it "cancels a scheduled notification" do
424
+ stub_notification_delete(5)
425
+
426
+ notification = Notification.new(id: 5)
427
+
428
+ res = notification.cancel
429
+ expect(res).to be_nil
430
+ end
431
+
432
+ it "fails with CancelError if response status code is not 204" do
433
+ stub_failing_notification_delete(5)
434
+
435
+ notification = Notification.new(id: 5)
436
+
437
+ expect {
438
+ notification.cancel
439
+ }.to raise_error(Notification::CancelError)
440
+ end
441
+ end
442
+
412
443
  end
413
444
  end
data/spec/pushpad_spec.rb CHANGED
@@ -16,9 +16,9 @@ describe Pushpad do
16
16
  end
17
17
 
18
18
  describe "#signature_for" do
19
- it "produces the hex-encoded HMAC-SHA1 signature for the data passed as argument" do
19
+ it "produces the hex-encoded HMAC-SHA256 signature for the data passed as argument" do
20
20
  signature = Pushpad.signature_for('myuid1')
21
- expect(signature).to eq '27fbe136f5a4aa0b6be74c0e18fa8ce81ad91b60'
21
+ expect(signature).to eq 'd213a2f146dd9aae9cb935b5233d42fecc9414e2b0e98896af7a43e7fce3ef31'
22
22
  end
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushpad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pushpad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubygems_version: 3.2.32
84
+ rubygems_version: 3.5.16
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Web push notifications for Chrome, Firefox, Opera, Edge and Safari using