pushpad 1.0.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: 48d7160263b210c7897b4171bb69b21916e155e3e3c5c252a23ab99f0d64252d
4
- data.tar.gz: e06bc7a3e1d946403e45cc4ed57672d1fd97e4076d9d0538bf42ba7b13a5aaf1
3
+ metadata.gz: dccdac2f6334014fc3b1a7fa42b5cc0644135df02b3e58f9c44f17e7fe00a27e
4
+ data.tar.gz: 69c4ea4985bdd6c120445e36c58e8adf0f572874dd7fd3ef929ad90176c84b18
5
5
  SHA512:
6
- metadata.gz: 33bc016ccd42f4ea8cced6e3b0a98e91c22c196ff1481b504f64ae231ec0ff0d67c4e47bd5fb5fd0ab42c544d3d97e559893ed85d71cce7057e355a5d138863e
7
- data.tar.gz: 927b49b786b2ed3114d6a1c8b88dddcea72a21c6688a4bc9adc51e6206a5a0d6229134fdaace40c7687e957f0eba3a7045edb1e512ccfac4436568704bcdf803
6
+ metadata.gz: b9ab88edcae1bcb44f8e6e1b388d25ee47459c81b6f2c72c9b450a1bf64b08dd874b019d518733a1cb4cf53c7f4f3c8feec7ffc418a144c81cc6b0864c1b67d2
7
+ data.tar.gz: 6540c56bb6cbaa46e496098669d081c7c66f35c20e1cc82bb4602510a696179c9fa71ba381dd1693c181fe32adf8a05ef5224ca9a2ea22f16648e35b2eca138b
@@ -10,7 +10,7 @@ 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
15
  - uses: actions/checkout@v3
16
16
  - name: Set up Ruby
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 desktop). iOS support is coming in 2023.
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
 
@@ -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/pushpad.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pushpad"
3
- spec.version = '1.0.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
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: 1.0.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-11-30 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.3.26
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