∞ Ruby Server SDK
∞ Installation
The Pusher Beams Ruby server SDK is available on RubyGems. Add this line to your application’s Gemfile:
gem 'pusher-push-notifications'
∞ Reference
∞ Class: PushNotifications
∞ Arguments
- ∞ instance_idString Required
-
The unique identifier for your Push notifications instance. This can be found in the dashboard under “Credentials”.
- ∞ secret_keyString Required
-
The secret key your server will use to access your Beams instance. This can be found in the dashboard under “Credentials”.
∞ Example
Pusher::PushNotifications.configure do |config|
config.instance_id = 'YOUR_INSTANCE_ID_HERE'
config.secret_key = 'YOUR_SECRET_KEY_HERE'
end
∞ publish_to_interests(interests, payload)
Publish a new push notification to Pusher Beams with the given payload.
∞ Arguments
- ∞ interestsArray Required
-
List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Interests.
- ∞ payloadMap
-
Map containing the body of the push notification publish request. See publish API reference.
∞ Returns
String that contains publish_id
: See publish API reference
∞ Example
data = {
apns: {
aps: {
alert: {
title: 'Hello',
body: 'Hello, world!'
}
}
},
fcm: {
notification: {
title: 'Hello',
body: 'Hello, world!'
}
}
}
Pusher::PushNotifications.publish_to_interests(interests: ['hello'], payload: data)
∞ publish_to_users(users, publishRequest)
Publish the given publishRequest
to specified users.
∞ Arguments
- ∞ usersArray Required
-
Array of ids of users to send the push notification to, ranging from 1 to 1000 per publish request. See Authenticated Users.
- ∞ publishRequestMap
-
Map containing the body of the push notification publish request. See publish API reference.
∞ Returns
String that contains publishId
: See publish API reference
∞ Example
users = ['cucas', 'jonathan', 'jordan', 'luis', 'luka', 'mina']
Pusher::PushNotifications.publish_to_users(users: users, payload: data)
∞ generate_token(userId)
Generate a Beams auth token to allow a user to associate their device with their user ID. The token is valid for 24 hours.
∞ Arguments
- ∞ userId Required
-
ID of the user you would like to generate a Beams auth token for.
∞ Example
Pusher::PushNotifications.generate_token(user: 'Elmo')
∞ delete_user(userId)
Remove the given user (and all of their devices) from Beams. This user will no longer receive any notifications and all state stored about their devices will be deleted.
∞ Arguments
- ∞ userId Required
-
ID of the user you would like to remove from Beams.
∞ Example
Pusher::PushNotifications.delete_user(user: 'Elmo')