Class: Pushofy::PushMessage
- Inherits:
-
Object
- Object
- Pushofy::PushMessage
- Defined in:
- lib/pushofy/push_message.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ PushMessage
constructor
A new instance of PushMessage.
- #send_push ⇒ Object
- #send_to_android(device) ⇒ Object
- #send_to_ios(device) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ PushMessage
Returns a new instance of PushMessage.
8 9 10 11 12 13 |
# File 'lib/pushofy/push_message.rb', line 8 def initialize(args = {}) @id = args[:id] = args[:message] @app = args[:app] @from = args[:from] end |
Instance Method Details
#send_push ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/pushofy/push_message.rb', line 17 def send_push device = Device.find(@id) device_type = device.device_type if device_type == 'IOS' send_to_ios(device) elsif device_type == 'Android' send_to_android(device) end end |
#send_to_android(device) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pushofy/push_message.rb', line 45 def send_to_android(device) body = {} arr = [] arr << device.registration_id body['registration_ids'] = arr # body['collapse_key'] = 'Updates Available' # body['registration_ids'] = registration_ids # body['data'] = 'Hi this is my first push message' # body['delay_while_idle'] = # true or false # body['time_to_live'] = # number in seconds android_payload = { 'message' => "You have a new #{app} from #{from}" } android_payload['app'] = @app android_payload['url'] = body['data'] = android_payload a = AndroidPush.new a.push(body) end |
#send_to_ios(device) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pushofy/push_message.rb', line 27 def send_to_ios(device) payload_hash = { aps: { alert: { body: "You have a new #{@app}, form #{@from}" }, sound: 'default', badge: 1, }, app: @app, url: } ApplePush.new(payload_hash, device_token_hex).push end |