Ruby Server SDK

Installation

The Pusher Beams Ruby server SDK is available on RubyGems. Add this line to your application’s Gemfile:

Gemfile

1
gem 'pusher-push-notifications'

Usage

Configuring the SDK for Your Instance

Use your instance id and secret (you can get these from the dashboard) to create a PushNotifications instance:

Ruby

1
2
3
4
Pusher::PushNotifications.configure do |config|
  config.instance_id = 'YOUR_INSTANCE_ID_HERE'
  config.secret_key = 'YOUR_SECRET_KEY_HERE'
end

Publishing a Notification

Once you have created your PushNotifications instance you can publish a push notification to your registered & subscribed devices:

Ruby

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
data = {
  apns: {
    aps: {
      alert: {
        title: 'Hello',
        body: 'Hello, world!'
      }
    }
  },
  fcm: {
    notification: {
      title: 'Hello',
      body: 'Hello, world!'
    }
  }
}

Pusher::PushNotifications.publish(interests: ['hello'], payload: data)

Reference

Class: PushNotifications

Arguments

  • instance_id(string): The unique identifier for your Push notifications instance. This can be found in the dashboard under "keys".
  • secret_key(string): The secret key your server will use to access your Beams instance. This can be found in the dashboard under "keys".

publish(interests, payload)

Publish a new push notification to Pusher Beams with the given payload.

Arguments

  • interests: List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Interests.
  • payload: Map containing the body of the push notification publish request. See publish API reference.

Returns
String that contains publish_id: See publish API reference

Did you find this document useful?

We are always striving to create the most accurate and informative docs as possible. If there is something especially wrong (or right) here then please let us know.