Sha256: 2a3d3ac73a5786fafcbdb38eb137c7c56fd17248d7b37bbb235e5a98e8873b07

Contents?: true

Size: 1.85 KB

Versions: 7

Compression:

Stored size: 1.85 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]
        if (host and port)
          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
        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

7 entries across 7 versions & 1 rubygems

Version Path
rhosync-2.1.18.beta2 lib/rhosync/ping/blackberry.rb
rhosync-2.1.18.beta1 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17.beta7 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17.beta6 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17.beta5 lib/rhosync/ping/blackberry.rb
rhosync-2.1.17.beta4 lib/rhosync/ping/blackberry.rb