Airship Ruby Library
Ruby library for using Airship’s messaging platform and related features.
Resources
Installation
If you do not yet have the bundler gem, get it using:
Install Bundler
gem install bundlerOnce you have the bundler gem, add this line to your application’s
Gemfile:
Install our gem
gem 'urbanairship'And then execute:
Bundle
bundleOr install it yourself as:
Alternative installation
gem install urbanairshipConfiguration
In your app initialization, you can do something like the following:
Example configuration
require 'urbanairship'
Urbanairship.configure do |config|
config.server = 'api.asnapieu.com'
config.oauth_server = 'oauth2.asnapieu.com'
config.log_path = '/path/to/your/logfile'
config.log_level = Logger::WARN
config.timeout = 60
endIf you want to use a custom logger such as Rails.logger, you can do:
Custom logger
require 'urbanairship'
Urbanairship.configure do |config|
config.custom_logger = Rails.logger
config.log_level = Logger::WARN
endAvailable configurations
Allowances per configuration:
- log_path — Allows defining the folder where the log file will be created. The default is nil.
- log_level — Allows defining the log level. Only messages at that level or higher will be printed. The default is INFO.
- server — Allows defining the Airship server you want to use (“api.asnapieu.com” for EU or “api.asnapius.com” for US)
- oauth_server — Allows defining the Airship OAuth server you want to use. Use
oauth2.asnapieu.comfor EU oroauth2.asnapius.comfor US. - timeout — Allows defining the request timeout in seconds. The default is 5.
Usage
Broadcast to all devices:
Broadcast
require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key:'application_key', secret:'master_secret')
p = airship.create_push
p.audience = UA.all
p.notification = UA.notification(alert: 'Hello')
p.device_types = UA.device_types(['ios','android'])
p.send_pushBasic tag push:
Tag push
require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key:'application_key', secret:'master_secret')
p = airship.create_push
p.audience = UA.tag('some_tag')
p.notification = UA.notification(alert: 'Hello')
p.device_types = UA.device_types(['ios','android'])
p.send_pushSpecify the Airship server used to make your requests
By default, the request will be sent to server api.asnapius.com:
Default server with Basic auth
require 'urbanairship'
Urbanairship::Client.new(key:'application_key', secret:'master_secret')You can change the server globally in the Urbanairship configuration:
Using a different server
require 'urbanairship'
Urbanairship.configure do |config|
config.server = 'api.asnapieu.com'
end
Urbanairship::Client.new(key:'application_key', secret:'master_secret')
# request will be sent to the 'api.asnapieu.com' serverUsing Bearer Token auth
Bearer token authentication
require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key:'application_key', token:'token')
# Then continue as you would otherwiseUsing OAuth
OAuth
require 'urbanairship'
UA = Urbanairship
app_key = 'application_key'
oauth = UA::Oauth.new(
client_id: 'client_id',
key: app_key,
assertion_private_key: 'your_private_key',
scopes: ['psh', 'chn'], # Optional
ip_addresses: ['23.74.131.15/22'], # Optional
oauth_server: 'api.asnapieu.com' # Optional
)
airship = UA::Client.new(key: app_key, oauth: oauth)
# Then continue as you would otherwise- You cannot use both OAuth and Bearer Token auth at the same time.
- OAuth cannot be used with the older
api.urbanairship.comandapi.airship.eubase URLs. See Base URL and OAuth in the Airship API reference. - OAuth is not supported for all endpoints. See the Airship API Authorization Reference.
Feedback
Was this page helpful?