Class: StackMob::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/stackmob/push.rb

Constant Summary collapse

PUSH_SVC =
:push
DEVICE_TOKEN_PATH =
"/device_tokens"
BROADCAST_PATH =
"/push_broadcast"
PUSH_PATH =
"/push"
DEFAULT_BADGE =
0
DEFAULT_SOUND =
""

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cl) ⇒ Push

Returns a new instance of Push.



28
29
30
# File 'lib/stackmob/push.rb', line 28

def initialize(cl)
  self.client = cl
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



18
19
20
# File 'lib/stackmob/push.rb', line 18

def client
  @client
end

Instance Method Details

#broadcast(opts) ⇒ Object



36
37
38
39
40
41
# File 'lib/stackmob/push.rb', line 36

def broadcast(opts)
  aps_data = generate_aps_data(opts)
  payload = {:recipients => [], :aps => aps_data, :areRecipientsDeviceTokens => true, :exclude_tokens => []}

  self.client.request(:post, PUSH_SVC, BROADCAST_PATH, payload)
end

#register(user_id, device_token) ⇒ Object



32
33
34
# File 'lib/stackmob/push.rb', line 32

def register(user_id, device_token)
  self.client.request(:post, PUSH_SVC, DEVICE_TOKEN_PATH, :userId => user_id, :token => device_token) # using non-convential symbols to conform to StackMob Push API
end

#send_message(to, opts) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/stackmob/push.rb', line 43

def send_message(to, opts)
  aps_data = generate_aps_data(opts)
  recipients_are_device_tokens = (opts[:recipients_are_users]) ? false : true
  payload = {:recipients => Array(to), :aps => aps_data, :areRecipientsDeviceTokens => recipients_are_device_tokens, :exclude_tokens => []}

  self.client.request(:post, PUSH_SVC, PUSH_PATH, payload)
end