We are pleased to announce the advancement of the OneSignal Ruby API client library as a RubyGem to general availability. This gem supports developers using OneSignal by providing an easy way to engage with the OneSignal REST API.

Benefits of Using the OneSignal Ruby Gem

The OneSignal RubyGem is the only gem fully supported and maintained by OneSignal. The gem is code-generated using OpenApi Generator. This allows us to more easily update all of our client libraries as we add or change features, endpoints, and schemas. We hope that this helps streamline the propagation of changes so that you get the most up-to-date tools as soon as they're available.

Adding the OneSignal Ruby Gem to Your Application

To get started, add this line to your application's Gemfile:

gem 'onesignal', '~> 1.0.1'

Check the OneSignal RubyGem releases page to identify what the latest release is and update the code above with the most recent release version.

Then, execute:

$ bundle

Or install the Gem yourself as:

$ gem install onesignal

Authenticating the OneSignal Ruby API Client Library

To use the client, you will need your User Auth Key, App ID, and App Auth Key from your OneSignal account.

User Auth Key

To locate your User Auth Key, click on your profile icon in the top right corner of your OneSignal dashboard and select Account & API Keys from the drop-down menu that appears.

Scroll down the page until you find the User Auth Key section. You may need to generate a new auth key if you didn't save it previously.

App Key

You can find your app's API key on this same page by scrolling up to the REST API Keys section. Find your app name in this section and copy the associated key.

App ID

The App ID cannot be found on the same page. To find this information, navigate back to your main dashboard menu by clicking back in your browser or clicking the OneSignal logo at the top left corner of your screen.

Once you've reached the main dashboard menu, select Apps from the menu at the top of the page. You should see a list of All Applications. Click into the application you'd like to update and then select the Settings tab to view information specific to this app.

Select Keys & IDs from the submenu.

You will see the application-specific ID here.

Pro tip: If you've clicked into an app, the App ID is the number located after "https://app.onesignal.com/apps/" in the browser URL.

Using the OneSignal Ruby Gem

Example:

require 'onesignal'

# setup authorization
OneSignal.configure do |config|
  # Configure Bearer authorization
  config.app_key = 'YOUR_APP_KEY'
  config.user_key = 'YOUR_USER_KEY'
end

api_instance = OneSignal::DefaultApi.new
notification = OneSignal::Notification.new({app_id: 'app_id_example'}) # Notification | 

begin
  # Create notification
  result = api_instance.create_notification(notification)
  p result
rescue OneSignal::ApiError => e
  puts "Error when calling DefaultApi->create_notification: #{e}"
end

The README in the Github repository contains the most in-depth documentation covering all API endpoints and models.

Additional Resources

Share Your Feedback

If you’ve had a chance to use our new Ruby Gem and have any feedback or suggestions you’d like to share, please do reach out to us on the GitHub repository or on our Discord server.

If you encounter any bugs or technical issues while using our new Ruby gem, we want to know so we can make things right. Please be sure to file a report on our GitHub repository.

If you’ve found the plugin useful, we’d appreciate it if you leave us a review on G2.