Skip to content

Commit 4163d28

Browse files
committed
Add project_id (returned by API) to notifications and subscriptions
1 parent 200c774 commit 4163d28

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

lib/pushpad/notification.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ class ReadonlyError < RuntimeError
1616
end
1717

1818
attr_accessor :body, :title, :target_url, :icon_url, :badge_url, :image_url, :ttl, :require_interaction, :silent, :urgent, :custom_data, :custom_metrics, :actions, :starred, :send_at
19-
attr_reader :id, :created_at, :scheduled_count, :successfully_sent_count, :opened_count
19+
attr_reader :id, :project_id, :created_at, :scheduled_count, :successfully_sent_count, :opened_count
2020

2121
def initialize(options)
2222
@id = options[:id]
23+
@project_id = options[:project_id]
2324
@created_at = options[:created_at] && Time.parse(options[:created_at])
2425
@scheduled_count = options[:scheduled_count]
2526
@successfully_sent_count = options[:successfully_sent_count]

lib/pushpad/subscription.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class FindError < RuntimeError
1515
class DeleteError < RuntimeError
1616
end
1717

18-
attr_reader :id, :endpoint, :p256dh, :auth, :uid, :tags, :last_click_at, :created_at
18+
attr_reader :id, :project_id, :endpoint, :p256dh, :auth, :uid, :tags, :last_click_at, :created_at
1919

2020
def initialize(options)
2121
@id = options[:id]
22+
@project_id = options[:project_id]
2223
@endpoint = options[:endpoint]
2324
@p256dh = options[:p256dh]
2425
@auth = options[:auth]
@@ -89,7 +90,7 @@ def self.find_all(options = {})
8990
end
9091

9192
def update(attributes, options = {})
92-
project_id = options[:project_id] || Pushpad.project_id
93+
project_id = project_id || options[:project_id] || Pushpad.project_id
9394
raise "You must set project_id" unless project_id
9495

9596
raise "You must set id" unless id
@@ -109,7 +110,7 @@ def update(attributes, options = {})
109110
end
110111

111112
def delete(options = {})
112-
project_id = options[:project_id] || Pushpad.project_id
113+
project_id = project_id || options[:project_id] || Pushpad.project_id
113114
raise "You must set project_id" unless project_id
114115

115116
raise "You must set id" unless id

pushpad.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = "pushpad"
3-
spec.version = '1.5.0'
3+
spec.version = '1.6.0'
44
spec.authors = ["Pushpad"]
55
spec.email = ["[email protected]"]
66
spec.summary = "Web push notifications for Chrome, Firefox, Opera, Edge and Safari using Pushpad."

spec/pushpad/notification_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def stub_failing_notification_delete(notification_id)
6262
it "returns notification with attributes from json response" do
6363
attributes = {
6464
id: 5,
65+
project_id: 123,
6566
title: "Foo Bar",
6667
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
6768
target_url: "https://example.com",
@@ -118,6 +119,7 @@ def stub_failing_notification_delete(notification_id)
118119
it "returns notifications of project with attributes from json response" do
119120
attributes = {
120121
id: 5,
122+
project_id: 123,
121123
title: "Foo Bar",
122124
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
123125
target_url: "https://example.com",

spec/pushpad/subscription_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def stub_failing_subscription_delete(project_id, id)
164164
it "returns subscription with attributes from json response" do
165165
attributes = {
166166
id: 5,
167+
project_id: 123,
167168
endpoint: "https://example.com/push/f7Q1Eyf7EyfAb1",
168169
p256dh: "BCQVDTlYWdl05lal3lG5SKr3VxTrEWpZErbkxWrzknHrIKFwihDoZpc_2sH6Sh08h-CacUYI-H8gW4jH-uMYZQ4=",
169170
auth: "cdKMlhgVeSPzCXZ3V7FtgQ==",
@@ -204,6 +205,7 @@ def stub_failing_subscription_delete(project_id, id)
204205
it "returns subscriptions of project with attributes from json response" do
205206
attributes = {
206207
id: 1169,
208+
project_id: 123,
207209
endpoint: "https://example.com/push/f7Q1Eyf7EyfAb1",
208210
p256dh: "BCQVDTlYWdl05lal3lG5SKr3VxTrEWpZErbkxWrzknHrIKFwihDoZpc_2sH6Sh08h-CacUYI-H8gW4jH-uMYZQ4=",
209211
auth: "cdKMlhgVeSPzCXZ3V7FtgQ==",

0 commit comments

Comments
 (0)