Module: Wpns

Extended by:
Wpns
Included in:
Wpns
Defined in:
lib/wpns/version.rb,
lib/wpns/notifications.rb

Constant Summary collapse

VERSION =
"0.0.2"
BASEBATCH =
{ :tile => 1, :toast => 2, :raw => 3 }
BATCHADDS =
{ :delay450 => 10, :delay900 => 20 }
WP_TARGETS =
{ :toast => "toast", :tile => "token" }

Instance Method Summary collapse

Instance Method Details

#send_notification(uri, params, type = :raw, delay = nil) ⇒ Object

Send a WP7 notification to the given URI.

Parameters:

  • the (String)

    channel uri that the WP7 device generated

  • the (Hash)

    options for the following message types 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 XML message body



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wpns/notifications.rb', line 24

def send_notification(uri, params, type = :raw, delay = nil)
  msg = build_message params, type
  notification_class = calculate_delay type, delay

  uri = URI.parse uri
  http = Net::HTTP.new uri.host, uri.port
  headers = { 'Content-Type' => 'text/html',
    'Content-Length' => msg.bytesize.to_s,
    'X-NotificationClass' => notification_class.to_s }
  headers['X-WindowsPhone-Target'] = WP_TARGETS[type] unless type == :raw

  http.post(uri.path, msg, headers)
end