APPush v0.1 documentation

This Page

Ruby Client Library

A Ruby interface to talk to the Appush push notifications service. It uses the three levels of Appush authentification: RootUser, Application and Profile.

Data returned using this api may be parsed using a JSON parser: JSON.parse(data.to_s), depending on the http result it might be an array or hash or binary data.

new(token, secret[, service_url])

Instantiates an Appush API client

Parameters

  • token - required Appush token string (this is the http username)
  • secret - required Appush secret string (this is the http password)
  • service_url - Appush service URL (not required, default https://appush.com/api)

Example:

>> client = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
RootUser.create_application(name[, env, dev_pem, prod_pem])

Parameters

  • name - required Application name
  • env - application environment (dev, prod)
  • dev_pem - application development certificate
  • prod_pem - application production certificate

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.create_application("test")
>> "{"id":"YZgzHWpxdt4emUAYTptovTcfYdW"}"
RootUser.modify_application(id[, params])

Parameters

  • id - application resource id
  • params - a hashed parameters (:name=>”new name”)

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.modify_application("YZgzHWpxdt4emUAYTptovTcfYdW", :name=>"new app name", :env=>"dev")
>> ""
RootUser.list_applications()

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.list_applications
>> "["P9haDs2EjJmyuYwEpxio2KPZ4SH"]"
RootUser.get_application(id)

Parameters

  • id - application resource id

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.get_application("YZgzHWpxd...")
>> {"name":"My New Application", "application_token": "EVtmyITWMKzDRtawXxubVmfIYWU", "application_secret": "e52c6cbd232e2111671953d320ff80a2", "status":"dev","dev_pem":"Bag Attributes\n    ...", "active_devices":0}
RootUser.get_application_icon(id)

Parameters

  • id - application resource id

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> icon = root_user.get_application_icon("YZgzHWpxd...")
RootUser.save_application_icon(id, icon)

Parameters

  • id - application resource id
  • icon - binary icon

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> icon = File.read('icon.png')
>> root_user.save_application_icon("YZgzHWpxd...", icon)
RootUser.delete_application(id)

Parameters

  • id - application resource id

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.delete_application("YZgzHWpxd...")
RootUser.send_notification(id[, params])

Parameters

  • id - application resource id
  • tags - a list of strings to implicitly include a device in a notification
  • devices - the device token string to explicitly include
  • exclude - the device token string to explicitly exclude
  • alert - a string. the notification to be sent.
  • sound - a string. the sound, if available on the client device.
  • badge - an integer. The number to set the badge to.
  • kv - a hash table of arbitrary key value pairs to send to the device.

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.send_notification("YZgzHWpxd...", :tags=>["foo", "bar"])
RootUser.get_notification_status(app_id, notification_id)

Parameters

  • app_id - application resource id
  • notification_id - notification id

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_token.get_notification_status("YZgzHWpxd...", "P9haDs2Ej")
RootUser.get_devices_by_tag(app_id, tag)

Parameters

  • app_id - application resource id
  • tag - tag to query the devices

Example:

>> root_user = AppushClient::RootUser.new root_token="I6ieYi...", root_secret="48907eb..."
>> root_user.get_devices_by_tag("YZgzHWpxd...", "tag")
>> "{"devices":["3734cc9af9376b8cba3704bccbd7c5c7f0901476d07c3247ead2b55f479fbd76"]}"
Profile.get_device(device_token)

Parameters

  • device_token - device identifier

Example:

>> profile = AppushClient::Profile.new profile_token="I6ieYi...", profile_secret="48907eb..."
>> profile.get_device("3734cc9af9376b8cba37")
>> {"tags":["spam","bar","foo"]}
Profile.register_device(device_token[, tags])

Parameters

  • device_token - device identifier
  • tags - array of tags

Example:

>> profile = AppushClient::Profile.new profile_token="I6ieYi...", profile_secret="48907eb..."
>> profile.register_device("3734cc9af9376b8cba37", ["foo", "bar"])
Profile.unregister_device(device_token)

Parameters

  • device_token - device identifier

Example:

>> profile = AppushClient::Profile.new profile_token="I6ieYi...", profile_secret="48907eb..."
>> profile.unregister_device("3734cc9af9376b8cba37")
Application.create_profile

Example:

>> application = AppushClient::Application.new application_token="I6ieYi...", application_secret="48907eb..."
>> application.create_profile()
>> "{"token":"38d0f91a99c57d189416439ce377ccdcd92639d0", "secret":"7e734e90f9dfc4def902ecd3c2e81c7dd530448d"}"