Docs

  • Channels Channels
  • Beams Beams
  • Developers
  • Support
  • Blog
  • Sign up
    • Search powered by Algolia
    • Sign in
    • Sign up
    • Channels
    • Beams
    • Getting started
      • Android
        • 1. Configure FCM
        • 2. Integrate SDK
        • 3. Initialize Beams
        • 4. Publish Notifications
      • iOS
        • 1. Configure APNS
        • 2. Integrate SDK
        • 3. Publish Notifications
      • Web
        • 1. SDK integration
        • 2. Safari configuration
      • Flutter
        • 1. Configure FCM and APNS
        • 2. Integrate SDK
        • 4. Publish Notifications
    • Concepts
      • Subscribers
      • Device interests
      • Authenticated users
      • Insights
      • Webhooks
    • Guides
      • Handle incoming notifications
        • Android
        • iOS
        • Web
        • Flutter
      • Publishing to multiple devices
      • Publish to specific user
        • Android
        • iOS
        • Web
        • Flutter
      • Web push guides
        • Using an existing service worker
        • Web notification permissions in Firefox
        • Handling Safari certificate expiration
    • Reference
      • Client SDKs
        • Android
        • iOS
        • Web
      • All Libraries
      • Server SDKs
        • Go
        • PHP
        • Node.js
        • Python
        • Java/Kotlin
        • Ruby
        • Swift
      • API
        • Publish API
        • Customer API
        • Device API
        • Reporting API
        • Webhooks
      • Platform Publish Formats
    • Pusher lab

    ∞ 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')

    Contents

    • Ruby Server SDK
    • Installation
    • Reference
      • Class: PushNotifications
      • publish_to_interests(interests, payload)
      • publish_to_users(users, publishRequest)
      • generate_token(userId)
      • delete_user(userId)

    Spotted something that isn’t quite right? Create an issue on GitHub.

    Copyright © 2023 Pusher Ltd. All rights reserved.

    • Support,
    • Status
    • Follow Pusher on Twitter Twitter
    • Subscribe to Pusher’s channel on YouTube
    • Follow Pusher on LinkedIn
    • Follow Pusher on Github GitHub
    • Follow Pusher on Twitch Twitch
    • Follow Pusher on Discord Discord