Skip to content

Instantly share code, notes, and snippets.

@goz
Created June 17, 2011 11:53
Show Gist options
  • Save goz/1031278 to your computer and use it in GitHub Desktop.
Save goz/1031278 to your computer and use it in GitHub Desktop.
Blackberry Push Messsages
require 'net/http'
require 'net/https'
require 'uri'
require 'rubygems'
require 'restclient'
DELIVERY_METHOD = 'unconfirmed'
BOUNDARY = 'fghjkklllmnggddcvjjkkm'
def push_message(pin, content, app_id, app_password, app_port)
delivery_before = (Time.now+(60*5)).strftime("%Y-%m-%dT%H:%M:%SZ ")
content_type = %w["Content-Type: application/xml; BOUNDARY=fghjkklllmnggddcvjjkkm;/xml" "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2, Connection: keep-alive", "User-Agent: Hallgren Networks BB Push Server/1.0"]
data="--#{BOUNDARY}
Content-Type: application/xml; charset=UTF-8
<?xml version='1.0'?>
<!DOCTYPE pap PUBLIC '-//WAPFORUM//DTD PAP 2.1//EN' 'http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd'>
<pap>
<push-message push-id='#{Time.now.to_i.to_s}' deliver-before-timestamp='#{delivery_before}' source-reference='#{app_id}'>
<address address-value='#{pin}'/>
<quality-of-service delivery-method='#{DELIVERY_METHOD}'/>
</push-message>
</pap>
--#{BOUNDARY}\n
Content-Type: text/html\n\n
Push-Message-ID:#{Time.now.to_i.to_s}\n\n#{content}\n\n--#{BOUNDARY}--"
response = RestClient::Request.execute(:method => :post,
:url => "https://pushapi.eval.blackberry.com/mss/PD_pushRequest",
:payload => data,
:headers => {
:content_type => content_type,
:user_agent => "User-Agent: Hallgren Networks BB Push Server/1.0"},
:user => app_id,
:password => app_password,
:port => app_port)
puts response.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment