Sha256: 2bcbe4860b85c109ac9b2102741ec137d2e9485d56b3790456c51c7458799090

Contents?: true

Size: 1.81 KB

Versions: 22

Compression:

Stored size: 1.81 KB

Contents

require 'net/http'
require 'uri'
module Rhosync
  class Blackberry
    def self.ping(params)
      begin
        settings = get_config(Rhosync.base_directory)[Rhosync.environment]
        host = settings[:mdsserver]
      	port = settings[:mdsserverport]
        
        headers = { "X-WAP-APPLICATION-ID" => "/",
                    "X-RIM-PUSH-DEST-PORT" => params['device_port'],
                    "CONTENT-TYPE" => 'multipart/related; type="application/xml"; boundary=asdlfkjiurwghasf'}
                    
        Net::HTTP.new(host,port).start do |http|
          request = Net::HTTP::Post.new('/pap',headers)
          request.body = pap_message(params)
          http.request(request)
        end

      rescue Exception => error
        log "Error while sending ping: #{error}"
        raise error
      end
    end
    
    def self.pap_message(params)
      data = "do_sync=" + (params['sources'] ? params['sources'].join(',') : "") + "\r\n"
      data << "alert=#{params['message']}\r\n" if params['message']
      data << "vibrate=#{params['vibrate']}\r\n" if params['vibrate']
      data << "sound=#{params['sound']}\r\n" if params['sound']
      post_body = <<-DESC
--asdlfkjiurwghasf
Content-Type: application/xml; charset=UTF-8

<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN" 
  "http://www.wapforum.org/DTD/pap_2.0.dtd" 
  [<?wap-pap-ver supported-versions="2.0"?>]>
<pap>
<push-message push-id="pushID:#{(rand * 100000000).to_i.to_s}" ppg-notify-requested-to="http://localhost:7778">

<address address-value="WAPPUSH=#{params['device_pin'].to_i.to_s(base=16).upcase}%3A100/TYPE=USER@rim.net"/>
<quality-of-service delivery-method="preferconfirmed"/>
</push-message>
</pap>
--asdlfkjiurwghasf
Content-Type: text/plain

#{data}
--asdlfkjiurwghasf--
DESC
      post_body.gsub!(/\n/,"\r\n")
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rhosync-2.1.17.beta3 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17.beta2 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17.beta1 lib/rhosync/ping/blackberry.rb
rhosync-2.1.16 lib/rhosync/ping/blackberry.rb
rhosync-2.1.15 lib/rhosync/ping/blackberry.rb
rhosync-2.1.14 lib/rhosync/ping/blackberry.rb
rhosync-2.1.13 lib/rhosync/ping/blackberry.rb
rhosync-2.1.12 lib/rhosync/ping/blackberry.rb
rhosync-2.1.11 lib/rhosync/ping/blackberry.rb
rhosync-2.1.10 lib/rhosync/ping/blackberry.rb
rhosync-2.1.7 lib/rhosync/ping/blackberry.rb
rhosync-2.1.6 lib/rhosync/ping/blackberry.rb
rhosync-2.1.3 lib/rhosync/ping/blackberry.rb
rhosync-2.1.2 lib/rhosync/ping/blackberry.rb
rhosync-2.1.1 lib/rhosync/ping/blackberry.rb
rhosync-2.1.0 lib/rhosync/ping/blackberry.rb
rhosync-2.1.0.beta.2 lib/rhosync/ping/blackberry.rb
rhosync-2.1.0.beta.1 lib/rhosync/ping/blackberry.rb
rhosync-2.0.9 lib/rhosync/ping/blackberry.rb
rhosync-2.0.8 lib/rhosync/ping/blackberry.rb