urbanairship
is a Ruby library for using the Airship <http://airship.com/>
_ REST API for push notifications, message
center messages, email, and SMS.
We officially support the following Ruby versions::
2.6.7 2.7.2
Newer 2.x versions should work as well.
Version 8.0 is a major upgrade, as we have changed the tested/supported versions of Ruby. A more detailed list of changes can be found in the CHANGELOG.
The best place to ask questions or report a problem is our support site: http://support.airship.com/
If you have the bundler
gem (if not you can get it with
$ gem install bundler
) add this line to your application's
Gemfile:
.. code-block::
$ gem 'urbanairship'
And then execute:
.. code-block::
$ bundle
OR install it yourself as:
.. code-block::
$ gem install urbanairship
In your app initialization, you can do something like the following:
.. code-block:: ruby
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 end
If you want to use a custom logger (e.g Rails.logger), you can do:
.. code-block:: ruby
require 'urbanairship'
Urbanairship.configure do |config| config.custom_logger = Rails.logger config.log_level = Logger::WARN end
Once the gem has been installed you can start sending pushes!
See the full documentation <http://docs.airship.com/reference/libraries/ruby>
,
api examples <http://docs.airship.com/topic-guides/api-examples.html>
, as well as the
Airship API Documentation <http://docs.airship.com/api/>
_ for more
information.
.. code-block:: ruby
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_push
.. code-block:: ruby
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_push
By default, the request will be sent to the 'api.asnapius.com' server:
.. code-block:: ruby
require 'urbanairship'
Urbanairship::Client.new(key:'application_key', secret:'master_secret')
You can change the server globally in the Urbanairship configuration:
.. code-block:: ruby
require 'urbanairship'
Urbanairship.configure do |config| config.server = 'api.asnapieu.com' end
Urbanairship::Client.new(key:'application_key', secret:'master_secret')
Finally, you can change the targeted server on a request basis:
.. code-block:: ruby
require 'urbanairship'
Urbanairship.configure do |config| config.server = 'api.asnapieu.com' end
Urbanairship::Client.new(key:'application_key', secret:'master_secret', server: 'api.asnapius.com')
.. code-block:: ruby
require 'urbanairship'
UA = Urbanairship airship = UA::Client.new(key:'application_key', token:'token')
Note: If you include a token in your instantiation, the request
will use bearer token auth. Bearer token auth is required for some
endpoints, but not supported by others. Please check the Airship docs site <https://docs.airship.com/>
_ to see where it is supported.
.. code-block:: ruby
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
Note: You can not use both Oauth and bearer token auth
at the same time. Oauth also cannot be used with the older
'api.urbanairship.com' and 'api.airship.eu' base URLs. Lastly
there are some endpoints in which Oauth is not supported.
Please check the Airship docs site <https://docs.airship.com/>
_ to see where it is supported.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
contribution agreement <https://docs.google.com/forms/d/e/1FAIpQLScErfiz-fXSPpVZ9r8Di2Tr2xDFxt5MgzUel0__9vqUgvko7Q/viewform>
_.Note: Changes will not be approved and merged without a signed contribution agreement.
After checking out the repo, ensure you have bundler
installed
($ gem install bundler
) run::
>>> $ bin/setup
to install dependencies. Then, run::
>>> $ bin/console
for an interactive prompt that will allow you to experiment.
OR you can build a local gem to play with::
>>> $ gem build urbanairship.gemspec
>>> $ gem install ./urbanairship-<VERSION>.gem
Having a local build will give you better logging if you are running into issues, but be careful to make sure to use our released public gem in Production.