Sha256: ba284ef611f95de7715dd03fda2ea8cab49b935ae94021b7fa5719a42eb49235

Contents?: true

Size: 834 Bytes

Versions: 21

Compression:

Stored size: 834 Bytes

Contents

module Rpush
  module Daemon
    module Wns
      class BadgeRequest
        def self.create(notification, access_token)
          body = BadgeRequestPayload.new(notification).to_xml
          uri  = URI.parse(notification.uri)
          post = Net::HTTP::Post.new(
            uri.request_uri,
            "Content-Length" => body.length.to_s,
            "Content-Type" => "text/xml",
            "X-WNS-Type" => "wns/badge",
            "X-WNS-RequestForStatus" => "true",
            "Authorization" => "Bearer #{access_token}"
          )
          post.body = body
          post
        end
      end

      class BadgeRequestPayload
        def initialize(notification)
          @badge = notification.badge || 0
        end

        def to_xml
          "<badge value=\"#{@badge}\"/>"
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
rpush-4.1.1 lib/rpush/daemon/wns/badge_request.rb
rpush-4.1.0 lib/rpush/daemon/wns/badge_request.rb
rpush-4.0.1 lib/rpush/daemon/wns/badge_request.rb
rpush-4.0.0 lib/rpush/daemon/wns/badge_request.rb
rpush-3.3.1 lib/rpush/daemon/wns/badge_request.rb
rpush-3.3.0 lib/rpush/daemon/wns/badge_request.rb
rpush_extended-3.2.6 lib/rpush/daemon/wns/badge_request.rb
rpush_extended-3.2.5 lib/rpush/daemon/wns/badge_request.rb
rpush-3.2.4 lib/rpush/daemon/wns/badge_request.rb
rpush-3.2.3 lib/rpush/daemon/wns/badge_request.rb
rpush-3.2.2 lib/rpush/daemon/wns/badge_request.rb
rpush-3.2.1 lib/rpush/daemon/wns/badge_request.rb
rpush-3.2.0 lib/rpush/daemon/wns/badge_request.rb
rpush-3.1.1 lib/rpush/daemon/wns/badge_request.rb
rpush-3.1.0 lib/rpush/daemon/wns/badge_request.rb
rpush-3.0.2 lib/rpush/daemon/wns/badge_request.rb
rpush-3.0.1 lib/rpush/daemon/wns/badge_request.rb
rpush-3.0.0 lib/rpush/daemon/wns/badge_request.rb
rpush-3.0.0.rc1 lib/rpush/daemon/wns/badge_request.rb
rpush-2.7.0-java lib/rpush/daemon/wns/badge_request.rb