Class: APN::BroadcastNotification
- Extended by:
- ActionView::Helpers::TextHelper
- Includes:
- AASM, ActionView::Helpers::TextHelper
- Defined in:
- lib/urbanairship_on_rails/models/apn/broadcast_notification.rb
Overview
Represents the message you wish to send. An APN::Notification belongs to an APN::Device.
Example:
apn = APN::BroadcastNotification.new
apn.badge = 5
apn.sound = 'my_sound.aiff'
apn.alert = 'Hello!'
apn.custom_properties = {:email_id => "6", :link => "http://google.com"}
apn.save
To deliver call the following method:
APN::BroadcastNotification.process_pending
As each APN::BroadcastNotification is sent the sent_at
column will be timestamped, so as to not be sent again.
Constant Summary
Constants inherited from Base
APN::Base::MAX_RETRIES, APN::Base::OPEN_TIMEOUT, APN::Base::READ_TIMEOUT
Class Method Summary collapse
Instance Method Summary collapse
- #apple_hash ⇒ Object
- #check_response ⇒ Object
- #convert(input) ⇒ Object
- #push ⇒ Object
- #update_sent_at ⇒ Object
Methods inherited from Base
#http_delete, #http_get, #http_post, #http_put, table_name
Class Method Details
.process_pending ⇒ Object
73 74 75 76 77 |
# File 'lib/urbanairship_on_rails/models/apn/broadcast_notification.rb', line 73 def self.process_pending self.pending.each do |n| n.push end end |
Instance Method Details
#apple_hash ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/urbanairship_on_rails/models/apn/broadcast_notification.rb', line 39 def apple_hash result = {} result['aps'] = {} result['aps']['alert'] = self.alert if self.alert result['aps']['badge'] = convert(self.badge) if self.badge if self.sound result['aps']['sound'] = self.sound if self.sound end if self.custom_properties self.custom_properties.each do |key,value| result["#{key}"] = "#{value}" end end result['exclude_tokens'] = [] self.excluded_devices.each do |excluded| result['exclude_tokens'] << excluded.device.token_for_ua end result end |
#check_response ⇒ Object
79 80 81 |
# File 'lib/urbanairship_on_rails/models/apn/broadcast_notification.rb', line 79 def check_response self.last_response_code == 200 ? true : false end |
#convert(input) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/urbanairship_on_rails/models/apn/broadcast_notification.rb', line 83 def convert(input) if input.to_i > 0 && input.to_i.to_s == input return input.to_i else return input end end |
#push ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/urbanairship_on_rails/models/apn/broadcast_notification.rb', line 61 def push puts "process #{self.inspect}" result = http_post("/api/push/broadcast/", apple_hash, {}, true) self.last_response_code = result.code self.save self.process! end |
#update_sent_at ⇒ Object
69 70 71 |
# File 'lib/urbanairship_on_rails/models/apn/broadcast_notification.rb', line 69 def update_sent_at self.sent_at = Time.now end |