Class: Pntfr::Notifier
- Inherits:
-
BaseService
- Object
- BaseService
- Pntfr::Notifier
- Defined in:
- lib/pntfr/notifier.rb
Instance Attribute Summary collapse
-
#andr_responses ⇒ Object
readonly
Returns the value of attribute andr_responses.
-
#ios_responses ⇒ Object
readonly
Returns the value of attribute ios_responses.
Class Method Summary collapse
Instance Method Summary collapse
- #any_android_device? ⇒ Boolean
- #any_ios_device? ⇒ Boolean
-
#initialize(credentials = nil) ⇒ Notifier
constructor
credentials
is a hash with 2 keys :andr and :ios, each one with its given credentials: - :andr => a string with the notification_key - :ios => a hash of the form { host: ‘test-host’, pem: ‘test-pem’, port: ‘test-port’, pass: ‘test-password’, }. - #msg(content, custom = nil) ⇒ Object
- #notify ⇒ Object
- #update_devices(devices) ⇒ Object
Constructor Details
#initialize(credentials = nil) ⇒ Notifier
credentials
is a hash with 2 keys :andr and :ios, each one with its given credentials:
-
:andr => a string with the notification_key
-
:ios => a hash of the form
host: 'test-host', pem: 'test-pem', port: 'test-port', pass: 'test-password',
28 29 30 31 32 33 |
# File 'lib/pntfr/notifier.rb', line 28 def initialize credentials=nil super @andr_responses=[] @ios_responses= [] end |
Instance Attribute Details
#andr_responses ⇒ Object (readonly)
Returns the value of attribute andr_responses.
14 15 16 |
# File 'lib/pntfr/notifier.rb', line 14 def andr_responses @andr_responses end |
#ios_responses ⇒ Object (readonly)
Returns the value of attribute ios_responses.
15 16 17 |
# File 'lib/pntfr/notifier.rb', line 15 def ios_responses @ios_responses end |
Class Method Details
Instance Method Details
#any_android_device? ⇒ Boolean
65 66 67 |
# File 'lib/pntfr/notifier.rb', line 65 def any_android_device? @andr_ids.any? end |
#any_ios_device? ⇒ Boolean
69 70 71 |
# File 'lib/pntfr/notifier.rb', line 69 def any_ios_device? @ios_devices.any? end |
#msg(content, custom = nil) ⇒ Object
51 52 53 54 |
# File 'lib/pntfr/notifier.rb', line 51 def msg content, custom=nil @msg= Notification.new(content, custom) self end |
#notify ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/pntfr/notifier.rb', line 56 def notify if any_android_device? @andr_responses << andr_session.notify(@andr_ids, @msg.to_android) end if any_ios_device? @ios_responses << ios_session.notify(@ios_devices, @msg.to_ios) end end |
#update_devices(devices) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pntfr/notifier.rb', line 35 def update_devices(devices) devices= [devices] unless devices.kind_of?(Array) # the list of ANDROID push_id to send the notification to @andr_ids= [] @ios_devices= [] devices.each do |device| if Platforms.android? device.platform @andr_ids << device.push_id elsif Platforms.ios? device.platform @ios_devices << device end end self end |