pushpad 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -13
- data/lib/pushpad.rb +4 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d941c8e87de24cb7ba4198735ca46708021d3617
|
4
|
+
data.tar.gz: e524dc59cbeda5cc9206a19fa8337f74d0ba5b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eae7e84da75f77a2da39f00e9a3fea1c7ec7232c25083290aa3c3dc92fc70cad72388667007af012aea5cb5357eb011bea6cc6a9dbdde29b5e4c2434fa9f828
|
7
|
+
data.tar.gz: fbd1ad0c2488840b723dbc47efe20d0bf8aaa7e66cc6f2eec188b553f0a76ab20950269d7911a338edbdd8349be02ccec95e881a5070372dbbd804eac566e816
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Pushpad
|
1
|
+
# Pushpad - Web Push Notifications
|
2
2
|
|
3
3
|
Add native push notifications to your web app using [Pushpad](https://pushpad.xyz).
|
4
4
|
|
@@ -41,14 +41,16 @@ Pushpad.auth_token = '5374d7dfeffa2eb49965624ba7596a09'
|
|
41
41
|
Pushpad.project_id = 123 # set it here or pass it as a param to methods later
|
42
42
|
```
|
43
43
|
|
44
|
-
`auth_token` can be found in the user account settings.
|
45
|
-
`project_id` can be found in the project settings
|
44
|
+
- `auth_token` can be found in the user account settings.
|
45
|
+
- `project_id` can be found in the project settings. If your application uses multiple projects, you can pass the `project_id` as a param to methods (e.g. `notification.deliver_to user, project_id: 123`).
|
46
46
|
|
47
|
-
## Collecting user subscriptions
|
47
|
+
## Collecting user subscriptions to push notifications
|
48
|
+
|
49
|
+
Pushpad offers two different ways to collect subscriptions. [Learn more](https://pushpad.xyz/docs#simple_vs_custom_api_docs)
|
48
50
|
|
49
51
|
### Custom API
|
50
52
|
|
51
|
-
Read the
|
53
|
+
Choose the Custom API if you want to use Javascript for a seamless integration. [Read the docs](https://pushpad.xyz/docs#custom_api_docs)
|
52
54
|
|
53
55
|
If you need to generate the HMAC signature for the `uid` you can use this helper:
|
54
56
|
|
@@ -58,7 +60,7 @@ Pushpad.signature_for current_user.id
|
|
58
60
|
|
59
61
|
### Simple API
|
60
62
|
|
61
|
-
|
63
|
+
Add a link to let users subscribe to push notifications:
|
62
64
|
|
63
65
|
```erb
|
64
66
|
<a href="<%= Pushpad.path %>">Subscribe anonymous to push notifications</a>
|
@@ -70,26 +72,36 @@ Let users subscribe to your push notifications:
|
|
70
72
|
|
71
73
|
When a user clicks the link is sent to Pushpad, automatically asked to receive push notifications and redirected back to your website.
|
72
74
|
|
73
|
-
## Sending notifications
|
74
|
-
|
75
|
-
After you have collected the user subscriptions you can send them push notifications:
|
75
|
+
## Sending push notifications
|
76
76
|
|
77
77
|
```ruby
|
78
78
|
notification = Pushpad::Notification.new({
|
79
|
-
body: "Hello world!",
|
80
|
-
title: "Website Name", # optional, defaults to your project name
|
79
|
+
body: "Hello world!", # max 90 characters
|
80
|
+
title: "Website Name", # optional, defaults to your project name, max 30 characters
|
81
81
|
target_url: "http://example.com" # optional, defaults to your project website
|
82
82
|
})
|
83
83
|
|
84
|
+
# deliver to a user
|
84
85
|
notification.deliver_to user # or user_id
|
86
|
+
|
87
|
+
# deliver to a group of users
|
85
88
|
notification.deliver_to users # or user_ids
|
86
|
-
|
89
|
+
|
90
|
+
# deliver to some users only if they have a given preference
|
91
|
+
# e.g. only "users" who have a interested in "events" will be reached
|
92
|
+
notification.deliver_to users, tags: ['events']
|
93
|
+
|
94
|
+
# deliver to segments
|
95
|
+
notification.broadcast tags: ['segment1', 'segment2']
|
96
|
+
|
97
|
+
# deliver to everyone
|
98
|
+
notification.broadcast
|
87
99
|
# => {"scheduled": 12}
|
88
100
|
```
|
89
101
|
|
90
102
|
If no user with that id has subscribed to push notifications, that id is simply ignored.
|
91
103
|
|
92
|
-
The methods above return an hash: `
|
104
|
+
The methods above return an hash: `"scheduled"` is the number of devices to which the notification will be sent.
|
93
105
|
|
94
106
|
## License
|
95
107
|
|
data/lib/pushpad.rb
CHANGED
@@ -52,7 +52,7 @@ module Pushpad
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def broadcast(options = {})
|
55
|
-
deliver req_body, options
|
55
|
+
deliver req_body(nil, options[:tags]), options
|
56
56
|
end
|
57
57
|
|
58
58
|
def deliver_to(users, options = {})
|
@@ -63,7 +63,7 @@ module Pushpad
|
|
63
63
|
else
|
64
64
|
[users.respond_to?(:id) ? users.id : users]
|
65
65
|
end
|
66
|
-
deliver req_body(uids), options
|
66
|
+
deliver req_body(uids, options[:tags]), options
|
67
67
|
end
|
68
68
|
|
69
69
|
private
|
@@ -91,7 +91,7 @@ module Pushpad
|
|
91
91
|
}
|
92
92
|
end
|
93
93
|
|
94
|
-
def req_body(uids = nil)
|
94
|
+
def req_body(uids = nil, tags = nil)
|
95
95
|
body = {
|
96
96
|
"notification" => {
|
97
97
|
"body" => self.body,
|
@@ -100,6 +100,7 @@ module Pushpad
|
|
100
100
|
}
|
101
101
|
}
|
102
102
|
body["uids"] = uids if uids
|
103
|
+
body["tags"] = tags if tags
|
103
104
|
body.to_json
|
104
105
|
end
|
105
106
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pushpad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
|
-
rubygems_version: 2.0.14
|
44
|
+
rubygems_version: 2.0.14.1
|
45
45
|
signing_key:
|
46
46
|
specification_version: 4
|
47
47
|
summary: Web push notifications for Chrome, Firefox and Safari using Pushpad.
|