pushpad 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -13
  3. data/lib/pushpad.rb +4 -3
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 280dfb492f2142c46bc48aab853d09a1d2a6c8a8
4
- data.tar.gz: 30ae77b7b02d8c1f989f24870f2ed8f0918add83
3
+ metadata.gz: d941c8e87de24cb7ba4198735ca46708021d3617
4
+ data.tar.gz: e524dc59cbeda5cc9206a19fa8337f74d0ba5b86
5
5
  SHA512:
6
- metadata.gz: 3889d1b96e444ded703aa7900c2b47abc1462aae58dec4ac937103efc2dde2d4d34ea9e6f7532f4e8a0abc755f63b692ff1db96c6ca37416ff15089648927f37
7
- data.tar.gz: 83589e468d60ae8fde4af1239a9349bf916f09da1a509502483d462ffc33132a2314b68e1f1da169837789e04e1eb7ac71a8d71a8b3c93a835a9343968ce3962
6
+ metadata.gz: 1eae7e84da75f77a2da39f00e9a3fea1c7ec7232c25083290aa3c3dc92fc70cad72388667007af012aea5cb5357eb011bea6cc6a9dbdde29b5e4c2434fa9f828
7
+ data.tar.gz: fbd1ad0c2488840b723dbc47efe20d0bf8aaa7e66cc6f2eec188b553f0a76ab20950269d7911a338edbdd8349be02ccec95e881a5070372dbbd804eac566e816
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Pushpad: real push notifications for websites
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 on Pushpad. A project is a list of subscriptions. You can set it globally or pass it as a param to methods if your app uses multiple lists (e.g. `Pushpad.path_for current_user, project_id: 123`, `notification.deliver_to user, project_id: 123`).
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 [docs](https://pushpad.xyz/docs#custom_api_docs).
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
- Let users subscribe to your push notifications:
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
- notification.broadcast # deliver to everyone
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: `res["scheduled"]` contains the number of notifications that will be sent. For example if you call `notification.deliver_to user` but the user has never subscribed to push notifications the result will be `{"scheduled": 0}`.
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.2.1
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-03-15 00:00:00.000000000 Z
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.