Sha256: cb6beee2e5114ebf588b1c1c71fb88e2fb9f2af51255e60a5df73deb99a551ac

Contents?: true

Size: 1.86 KB

Versions: 16

Compression:

Stored size: 1.86 KB

Contents

require 'net/http'
require 'uri'
module Rhoconnect
  class Blackberry
    def self.ping(params)
      begin
        settings = get_config(Rhoconnect.base_directory)[Rhoconnect.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

16 entries across 16 versions & 1 rubygems

Version Path
rhoconnect-4.0.0.beta.24 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.4.5 lib/rhoconnect/ping/blackberry.rb
rhoconnect-4.0.0.beta.10 lib/rhoconnect/ping/blackberry.rb
rhoconnect-4.0.0.beta.12 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.4.4 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.4.3 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.4.2 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.6 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.5 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.4 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.3 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.2 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.1 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.1.beta4 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.1.beta3 lib/rhoconnect/ping/blackberry.rb
rhoconnect-3.3.1.beta2 lib/rhoconnect/ping/blackberry.rb