pushpad 0.5.0 → 0.5.1

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: a1bdf804e269c7ee9bcb0684030849617c955e98
4
- data.tar.gz: c0da7ef0194d0950671c86154e2bc45d0d6507b7
3
+ metadata.gz: 16e079cb71bb9a62497ef67e1d02d8e10ae52ef9
4
+ data.tar.gz: 8bd989647419688540a10b16f2ee6400f13176fc
5
5
  SHA512:
6
- metadata.gz: f8f8d324fe7068c3bc4fb0744637e311106146849a4fb0ccea0183b431d2ef7ae3a82313fa690143eda9a3a865b4ae961d44129c013566b9f0f5fd68d49a78b7
7
- data.tar.gz: db783ff3ebc5215fe7f9bf7315fa3f3debb13b48ae5ddc545471ceb3d514d7a95cb63199ff3cc4dc1bf27d78e240de094146f8236cb7d033cb7ec92ce7c533a2
6
+ metadata.gz: 239f05ffb94da74b1cf932d3200f4e0267e9b41fa53d937b745a919b78500f6aacec685b920c3c3f45032dbb2b791fb368715ea15dfa9a502d5fbd7f6a8646c7
7
+ data.tar.gz: 7ec1b731bb3a23a275ffdd76f05cbabc3616a05a1cef98aff83e114918d8f5c41829766363a8add0f288e91af64890d2251a1e93967879e0ee09f06f3c184e2a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pushpad - Web Push Notifications Service
2
2
 
3
- [Pushpad](https://pushpad.xyz) is a service for sending push notifications from your web app. It supports the **Push API** (Chrome and Firefox) and **APNs** (Safari).
3
+ [Pushpad](https://pushpad.xyz) is a service for sending push notifications from your web app. It supports the **Push API** (Chrome, Firefox, Opera) and **APNs** (Safari).
4
4
 
5
5
  Features:
6
6
 
@@ -12,6 +12,7 @@ Currently push notifications work on the following browsers:
12
12
 
13
13
  - Chrome (Desktop and Android)
14
14
  - Firefox (44+)
15
+ - Opera (42+)
15
16
  - Safari
16
17
 
17
18
  ## Installation
@@ -80,7 +81,7 @@ notification = Pushpad::Notification.new({
80
81
  target_url: "http://example.com", # optional, defaults to your project website
81
82
  icon_url: "http://example.com/assets/icon.png", # optional, defaults to the project icon
82
83
  ttl: 604800, # optional, drop the notification after this number of seconds if a device is offline
83
- require_interaction: true # optional, default is false, if true it prevents Chrome from automatically closing the notification after a few seconds
84
+ require_interaction: true # optional, if true it prevents Chrome from automatically closing the notification after a few seconds
84
85
  })
85
86
 
86
87
  # deliver to a user
data/lib/pushpad.rb CHANGED
@@ -51,7 +51,7 @@ module Pushpad
51
51
  self.target_url = options[:target_url]
52
52
  self.icon_url = options[:icon_url]
53
53
  self.ttl = options[:ttl]
54
- self.require_interaction = !!options[:require_interaction]
54
+ self.require_interaction = options[:require_interaction]
55
55
  end
56
56
 
57
57
  def broadcast(options = {})
@@ -95,16 +95,14 @@ module Pushpad
95
95
  end
96
96
 
97
97
  def req_body(uids = nil, tags = nil)
98
- body = {
99
- "notification" => {
100
- "body" => self.body,
101
- "title" => self.title,
102
- "target_url" => self.target_url,
103
- "icon_url" => self.icon_url,
104
- "ttl" => self.ttl,
105
- "require_interaction" => self.require_interaction
106
- }
107
- }
98
+ notification_params = { "body" => self.body }
99
+ notification_params["title"] = self.title if self.title
100
+ notification_params["target_url"] = self.target_url if self.target_url
101
+ notification_params["icon_url"] = self.icon_url if self.icon_url
102
+ notification_params["ttl"] = self.ttl if self.ttl
103
+ notification_params["require_interaction"] = self.require_interaction unless self.require_interaction.nil?
104
+
105
+ body = { "notification" => notification_params }
108
106
  body["uids"] = uids if uids
109
107
  body["tags"] = tags if tags
110
108
  body.to_json
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushpad do
4
+ let!(:auth_token) { Pushpad.auth_token = 'abc123' }
5
+ let!(:project_id) { Pushpad.project_id = 123 }
6
+ let(:notification) { Pushpad::Notification.new body: "Example message" }
7
+
8
+ describe "#auth_token=" do
9
+ it "sets the Pushpad auth token globally" do
10
+ Pushpad.auth_token = 'abc123'
11
+ expect(Pushpad.auth_token).to eq 'abc123'
12
+ end
13
+ end
14
+
15
+ describe "#project_id=" do
16
+ it "sets the Pushpad project id globally" do
17
+ Pushpad.project_id = 123
18
+ expect(Pushpad.project_id).to eq 123
19
+ end
20
+ end
21
+
22
+ describe "#signature_for" do
23
+ it "produces the hex-encoded HMAC-SHA1 signature for the data passed as argument" do
24
+ signature = Pushpad.signature_for('myuid1')
25
+ expect(signature).to eq '27fbe136f5a4aa0b6be74c0e18fa8ce81ad91b60'
26
+ end
27
+ end
28
+
29
+ def stub_notification_post project_id, params
30
+ stub_request(:post, "https://pushpad.xyz/projects/#{project_id}/notifications").
31
+ with(body: hash_including(params)).
32
+ to_return(status: 201, body: '{}')
33
+ end
34
+
35
+ describe "#deliver_to" do
36
+
37
+ shared_examples 'notification params' do
38
+ it "includes the params in the request" do
39
+ req = stub_notification_post project_id, notification: notification_params
40
+ notification.deliver_to [123, 456]
41
+ expect(req).to have_been_made.once
42
+ end
43
+ end
44
+
45
+ context "a notification with just the required params" do
46
+ let(:notification_params) do
47
+ { body: "Example message" }
48
+ end
49
+ let(:notification) { Pushpad::Notification.new body: notification_params[:body] }
50
+ include_examples 'notification params'
51
+ end
52
+
53
+ context "a notification with all the optional params" do
54
+ let(:notification_params) do
55
+ {
56
+ body: "Example message",
57
+ title: "Website Name",
58
+ target_url: "http://example.com",
59
+ icon_url: "http://example.com/assets/icon.png",
60
+ ttl: 604800,
61
+ require_interaction: true
62
+ }
63
+ end
64
+ let(:notification) { Pushpad::Notification.new notification_params }
65
+ include_examples 'notification params'
66
+ end
67
+
68
+ context "with a scalar as a param" do
69
+ it "reaches only that uid" do
70
+ req = stub_notification_post project_id, uids: [100]
71
+ notification.deliver_to(100)
72
+ expect(req).to have_been_made.once
73
+ end
74
+ end
75
+
76
+ context "with an array as a param" do
77
+ it "reaches only those uids" do
78
+ req = stub_notification_post project_id, uids: [123, 456]
79
+ notification.deliver_to([123, 456])
80
+ expect(req).to have_been_made.once
81
+ end
82
+ end
83
+
84
+ context "with uids and tags" do
85
+ it "filters audience by uids and tags" do
86
+ req = stub_notification_post project_id, uids: [123, 456], tags: ['tag1']
87
+ notification.deliver_to([123, 456], tags: ['tag1'])
88
+ expect(req).to have_been_made.once
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#broadcast" do
94
+
95
+ shared_examples 'notification params' do
96
+ it "includes the params in the request" do
97
+ req = stub_notification_post project_id, notification: notification_params
98
+ notification.broadcast
99
+ expect(req).to have_been_made.once
100
+ end
101
+ end
102
+
103
+ context "a notification with just the required params" do
104
+ let(:notification_params) do
105
+ { body: "Example message" }
106
+ end
107
+ let(:notification) { Pushpad::Notification.new body: notification_params[:body] }
108
+ include_examples 'notification params'
109
+ end
110
+
111
+ context "a notification with all the optional params" do
112
+ let(:notification_params) do
113
+ {
114
+ body: "Example message",
115
+ title: "Website Name",
116
+ target_url: "http://example.com",
117
+ icon_url: "http://example.com/assets/icon.png",
118
+ ttl: 604800,
119
+ require_interaction: true
120
+ }
121
+ end
122
+ let(:notification) { Pushpad::Notification.new notification_params }
123
+ include_examples 'notification params'
124
+ end
125
+
126
+ context "without params" do
127
+ it "reaches everyone" do
128
+ req = stub_notification_post project_id, {}
129
+ notification.broadcast
130
+ expect(req).to have_been_made.once
131
+ end
132
+ end
133
+
134
+ context "with tags" do
135
+ it "filters audience by tags" do
136
+ req = stub_notification_post project_id, tags: ['tag1', 'tag2']
137
+ notification.broadcast tags: ['tag1', 'tag2']
138
+ expect(req).to have_been_made.once
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'pushpad'
5
+ require 'webmock/rspec'
6
+
7
+ RSpec.configure do |config|
8
+ # some config
9
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushpad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pushpad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description:
14
42
  email:
15
43
  - support@pushpad.xyz
@@ -21,6 +49,8 @@ files:
21
49
  - LICENSE.txt
22
50
  - README.md
23
51
  - lib/pushpad.rb
52
+ - spec/pushpad_spec.rb
53
+ - spec/spec_helper.rb
24
54
  homepage: https://pushpad.xyz
25
55
  licenses:
26
56
  - MIT
@@ -31,18 +61,20 @@ require_paths:
31
61
  - lib
32
62
  required_ruby_version: !ruby/object:Gem::Requirement
33
63
  requirements:
34
- - - '>='
64
+ - - ">="
35
65
  - !ruby/object:Gem::Version
36
66
  version: '0'
37
67
  required_rubygems_version: !ruby/object:Gem::Requirement
38
68
  requirements:
39
- - - '>='
69
+ - - ">="
40
70
  - !ruby/object:Gem::Version
41
71
  version: '0'
42
72
  requirements: []
43
73
  rubyforge_project:
44
- rubygems_version: 2.0.14.1
74
+ rubygems_version: 2.4.5
45
75
  signing_key:
46
76
  specification_version: 4
47
77
  summary: Web push notifications for Chrome, Firefox and Safari using Pushpad.
48
- test_files: []
78
+ test_files:
79
+ - spec/spec_helper.rb
80
+ - spec/pushpad_spec.rb