Class: BBPush::Client
- Inherits:
-
Object
- Object
- BBPush::Client
- Defined in:
- lib/bbpush/client.rb
Constant Summary collapse
- BOUNDARY =
"8d5588928a90afd3009d"
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#push_server_url ⇒ Object
Returns the value of attribute push_server_url.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #send_notification(bb_pins, message, deliver_within) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 |
# File 'lib/bbpush/client.rb', line 6 def initialize(={}) @app_id = [:app_id] @password = [:password] @push_server_url = [:push_server_url] || "https://pushapi.eval.blackberry.com/mss/PD_pushRequest" end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
4 5 6 |
# File 'lib/bbpush/client.rb', line 4 def app_id @app_id end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/bbpush/client.rb', line 4 def password @password end |
#push_server_url ⇒ Object
Returns the value of attribute push_server_url.
4 5 6 |
# File 'lib/bbpush/client.rb', line 4 def push_server_url @push_server_url end |
Instance Method Details
#send_notification(bb_pins, message, deliver_within) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bbpush/client.rb', line 12 def send_notification(bb_pins, , deliver_within) http = Net::HTTP.new(URI.parse(self.push_server_url).host, 443) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE addresses = [] bb_pins.each do |a| addresses << "<address address-value=\"#{a}\"/>\n" end push_id = ((Time.now.to_i * rand) + Time.now.to_i).round path = URI.parse(self.push_server_url).path headers = { "User-Agent" => "BBPush Ruby Library/0.1.0", "Authorization" => "Basic #{Base64.encode64(self.app_id+':'+self.password)}", "Content-Type" => "multipart/related; boundary=#{BBPush::Client::BOUNDARY}; type=application/xml"} data = "--\#{BBPush::Client::BOUNDARY}\nContent-Type: application/xml; charset=UTF-8\n \n<?xml version=\"1.0\"?>\n<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">\n<pap>\n<push-message push-id=\"\#{push_id}\" deliver-before-timestamp=\"\#{(Time.now.utc + (deliver_within * 60)).strftime(\"%Y-%m-%dT%H:%M:%S\")}Z\" source-reference=\"\#{self.app_id}\">\n\#{addresses.join(\"\\n\")}<quality-of-service delivery-method=\"unconfirmed\"/>\n</push-message>\n</pap>\n--\#{BBPush::Client::BOUNDARY}\nContent-Type: text/plain\n\n\#{message}\n--\#{BBPush::Client::BOUNDARY}\n" resp, data = http.post(path, data.gsub(/\n/,"\r\n"), headers) return data end |