Class: Rpush::Daemon::Wns::ToastRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rpush/daemon/wns/toast_request.rb

Class Method Summary collapse

Class Method Details

.create(notification, access_token) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rpush/daemon/wns/toast_request.rb', line 5

def self.create(notification, access_token)
  body = ToastRequestPayload.new(notification).to_xml
  uri  = URI.parse(notification.uri)
  headers = {
    "Content-Length" => body.length.to_s,
    "Content-Type" => "text/xml",
    "X-WNS-Type" => "wns/toast",
    "X-WNS-RequestForStatus" => "true",
    "Authorization" => "Bearer #{access_token}"
  }
  headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
  post = Net::HTTP::Post.new(
    uri.request_uri,
    headers
  )
  post.body = body
  post
end