README.md in pushpad-0.5.1 vs README.md in pushpad-0.6.0

- old
+ new

@@ -1,6 +1,8 @@ # Pushpad - Web Push Notifications Service + +[![Build Status](https://travis-ci.org/pushpad/pushpad-ruby.svg?branch=master)](https://travis-ci.org/pushpad/pushpad-ruby) [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). Features: @@ -107,15 +109,85 @@ notification.broadcast ``` If no user with that id has subscribed to push notifications, that id is simply ignored. -The methods above return an hash: +The methods above return an hash: - `"id"` is the id of the notification on Pushpad - `"scheduled"` is the estimated reach of the notification (i.e. the number of devices to which the notification will be sent, which can be different from the number of users, since a user may receive notifications on multiple devices) - `"uids"` (`deliver_to` only) are the user IDs that will be actually reached by the notification because they are subscribed to your notifications. For example if you send a notification to `['uid1', 'uid2', 'uid3']`, but only `'uid1'` is subscribed, you will get `['uid1']` in response. Note that if a user has unsubscribed after the last notification sent to him, he may still be reported for one time as subscribed (this is due to [the way](http://blog.pushpad.xyz/2016/05/the-push-api-and-its-wild-unsubscription-mechanism/) the W3C Push API works). +The `id` and `scheduled_count` attribute are also stored on the notification object: + +```ruby + +notification.deliver_to user + +notification.id # => 1000 +notification.scheduled_count # => 5 +``` + +## Getting push notification data + +You can retrieve data for past notifications: + +```ruby +notification = Pushpad::Notification.find(42) + +# get basic attributes +notification.id # => 42 +notification.title # => "Foo Bar", +notification.body # => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", +notification.target_url # => "http://example.com", +notification.ttl # => 604800, +notification.require_interaction # => false, +notification.icon_url # => "http://example.com/assets/icon.png", + +# `created_at` is a `Time` instance +notification.created_at.utc.to_s # => "2016-07-06 10:09:14 UTC", + +# get statistics +notification.scheduled_count # => 1 +notification.successfully_sent_count # => 4, +notification.opened_count # => 2 +``` + +Or for mutliple notifications of a project at once: + +```ruby +notifications = Pushpad::Notification.find_all(project_id: 5) + +# same attributes as for single notification in example above +notifications[0].id # => 42 +notifications[0].title # => "Foo Bar", +``` + +If `Pushpad.project_id` is defined, the `project_id` option can be +omitted. + +The REST API paginates the result set. You can pass a `page` parameter +to get the full list in multiple requests. + +```ruby +notifications = Pushpad::Notification.find_all(project_id: 5, page: 2) +``` + +## Getting subscription count + +You can retrieve the number of subscriptions for a given project, +optionally filtered by `tags` or `uids`: + +```ruby +Pushpad::Subscription.count(project_id: 5) # => 100 +Pushpad::Subscription.count(project_id: 5, uids: ['user1']) # => 2 +Pushpad::Subscription.count(project_id: 5, tags: ['sports']) # => 10 +Pushpad::Subscription.count(project_id: 5, tags: 'sports && travel') # => 5 +Pushpad::Subscription.count(project_id: 5, uids: ['user1'], tags: 'sports && travel') # => 1 +``` + +If `Pushpad.project_id` is defined, the `project_id` option can be +omitted. + ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). -