Class: RubyPushNotifications::MPNS::MPNSNotification
- Inherits:
-
Object
- Object
- RubyPushNotifications::MPNS::MPNSNotification
- Includes:
- NotificationResultsManager
- Defined in:
- lib/ruby-push-notifications/mpns/mpns_notification.rb
Overview
Encapsulates a MPNS Notification. Actually support for raw, toast, tiles notifications (msdn.microsoft.com/en-us/library/windowsphone/develop/hh202945)
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
. Payload to send. Toast :title => a bold message :message => the small message :param => a string parameter that is passed to the app Tile :image => a new image for the tile :count => a number to show on the tile :title => the new title of the tile :back_image => an image for the back of the tile :back_title => a title on the back of the tile :back_content => some content (text) for the back Raw :message => the full Hash message body.
-
#device_urls ⇒ Array
readonly
. Array with the receiver’s MPNS device URLs..
Attributes included from NotificationResultsManager
Instance Method Summary collapse
- #as_mpns_xml ⇒ String
- #build_hash(xml, options) ⇒ Object
- #each_device ⇒ Object
-
#initialize(device_urls, data) ⇒ MPNSNotification
constructor
Initializes the notification.
Constructor Details
#initialize(device_urls, data) ⇒ MPNSNotification
Initializes the notification
42 43 44 45 46 |
# File 'lib/ruby-push-notifications/mpns/mpns_notification.rb', line 42 def initialize(device_urls, data) @device_urls = device_urls @data = data @data[:type] ||= :raw end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns . Payload to send. Toast :title => a bold message
:message => the small message
:param => a string parameter that is passed to the app
Tile :image => a new image for the tile
:count => a number to show on the tile
:title => the new title of the tile
:back_image => an image for the back of the tile
:back_title => a title on the back of the tile
:back_content => some content (text) for the back
Raw :message => the full Hash message body.
23 24 25 |
# File 'lib/ruby-push-notifications/mpns/mpns_notification.rb', line 23 def data @data end |
#device_urls ⇒ Array (readonly)
Returns . Array with the receiver’s MPNS device URLs.
26 27 28 |
# File 'lib/ruby-push-notifications/mpns/mpns_notification.rb', line 26 def device_urls @device_urls end |
Instance Method Details
#as_mpns_xml ⇒ String
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby-push-notifications/mpns/mpns_notification.rb', line 51 def as_mpns_xml xml = Builder::XmlMarkup.new xml.instruct! if data[:type] != :raw xml.tag!('wp:Notification', 'xmlns:wp' => 'WPNotification') do case data[:type] when :toast xml.tag!('wp:Toast') do xml.tag!('wp:Text1') { xml.text!(data[:title]) } xml.tag!('wp:Text2') { xml.text!(data[:message]) } xml.tag!('wp:Param') { xml.text!(data[:param]) } if data[:param] end when :tile xml.tag!('wp:Tile') do xml.tag!('wp:BackgroundImage') { xml.text!(data[:image]) } if data[:image] xml.tag!('wp:Count') { xml.text!(data[:count].to_s) } if data[:count] xml.tag!('wp:Title') { xml.text!(data[:title]) } if data[:title] xml.tag!('wp:BackBackgroundImage') { xml.text!(data[:back_image]) } if data[:back_image] xml.tag!('wp:BackTitle') { xml.text!(data[:back_title]) } if data[:back_title] xml.tag!('wp:BackContent') { xml.text!(data[:back_content]) } if data[:back_content] end end end else xml.root { build_hash(xml, data[:message]) } end xml.target! end |
#build_hash(xml, options) ⇒ Object
86 87 88 89 90 |
# File 'lib/ruby-push-notifications/mpns/mpns_notification.rb', line 86 def build_hash(xml, ) .each do |k, v| xml.tag!(k.to_s) { v.is_a?(Hash) ? build_hash(xml, v) : xml.text!(v.to_s) } end end |
#each_device ⇒ Object
80 81 82 83 84 |
# File 'lib/ruby-push-notifications/mpns/mpns_notification.rb', line 80 def each_device @device_urls.each do |url| yield(URI.parse url) end end |