This gem provides a simple SDK to access the OneSignal API.
Also check my onesignal-go library.
gem install one_signal
Run bin/setup
to install dependencies and set your API keys.
Run the tests
bundle exec rake
You can also run bin/console
for an interactive prompt that will allow you to experiment with authenticated library methods.
See some basic examples in example.rb. To run it:
- run
bin/setup
to set your API keys - then run
ruby example.rb
Specify your User Auth key to deal with Apps:
OneSignal::OneSignal.user_auth_key = YOUR_USER_AUTH_KEY
Specify your API key to deal with Players and Notifications:
OneSignal::OneSignal.api_key = YOUR_API_KEY
Then call the following methods on the App
, Player
and Notification
classes.
The params
argument in those methods is a ruby hash and the accepted/required keys for this hash are documented in the OneSignal API documentation
Each method also accepts an optional opts
hash that allows you to specify the user_auth_key
/api_key
on a per method basis. It allows a ruby app to talk to several different OneSignal apps:
app_1_api_key = "fake api key 1"
app_2_api_key = "fake api key 2"
# by default, method calls will use app_1_api_key
OneSignal::OneSignal.api_key = app_1_api_key
# get player with id "123" in app_1
OneSignal::Player.get(id: "123")
# get player with id "456" in app_2
OneSignal::Player.get(id: "123", opts: {auth_key: app_2_api_key})
The return value of each method is a Net::HTTPResponse
.
- OneSignal::App.all(params:)
- OneSignal::App.get(id:)
- OneSignal::App.create(params:)
- OneSignal::App.update(id:, params:)
- OneSignal::Player.all(params:)
- OneSignal::Player.csv_export(params:)
- OneSignal::Player.get(id:)
- OneSignal::Player.create(params:)
- OneSignal::Player.create_session(id:, params:)
- OneSignal::Player.create_purchase(id:, params:)
- OneSignal::Player.create_focus(id:, params:)
- OneSignal::Player.update(id:, params:)
- OneSignal::Player.delete(id:, params:)
- OneSignal::Notification.all(params:)
- OneSignal::Notification.get(id:, params:)
- OneSignal::Notification.create(params:)
- OneSignal::Notification.update(id:, params:)
- OneSignal::Notification.delete(id:, params:)
See CHANGELOG.txt
They are listed here, thanks to them!
Please see LICENSE for licensing details.