Module: Pushlayer

Defined in:
lib/pushlayer.rb,
lib/pushlayer/version.rb

Constant Summary collapse

VERSION =
'0.9.1'
@@api_id =
''
@@api_key =
''

Class Method Summary collapse

Class Method Details

.api_id=(id) ⇒ Object



13
14
15
# File 'lib/pushlayer.rb', line 13

def self.api_id=(id)
  @@api_id = id
end

.api_key=(key) ⇒ Object



17
18
19
# File 'lib/pushlayer.rb', line 17

def self.api_key=(key)
  @@api_key = key
end

.post_notification(device_token, alert_body, opts = {}) ⇒ Object

Send a push notification

Upon success, a Ruby hash object will be returned representing the notification object sent.

Under the hood, Pushlayer is using rest_client to communicate with the service. Be sure to familiarize yourself with rest_client’s behavior in terms of exceptions:

Examples:

Pushlayer.post_notification 'abc123', 'Hello from PushLayer!'

Parameters:

  • device_token (String)

    The device_token from the iOS device, returned by the system in response to the user giving your app permission to send push notifications.

  • alert_body (String)

    A string to send in the APNS alert_body payload param. Typically this is a message you want to display to the user in an alert.

  • opts (Hash) (defaults to: {})

    A hash of all remaining valid APNS payload parameters to include, such as badge, sound, etc.

Options Hash (opts):

  • :badge (String)
  • :sound (String)
  • :action_loc_key (String)
  • :loc_key (String)
  • :loc_args (String)
  • :launch_image (String)
  • :custom_payload (String)


45
46
47
48
49
50
# File 'lib/pushlayer.rb', line 45

def self.post_notification(device_token, alert_body, opts={})
  params = { device_token: device_token, alert_body: alert_body }.merge opts
  headers = { accept: :json, content_type: :json, user_agent: user_agent }

  RestClient.post endpoint, MultiJson.dump(params), headers
end