bbpush 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +98 -0
- data/VERSION +1 -0
- data/lib/bbpush.rb +8 -0
- data/lib/bbpush/client.rb +53 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Nicholas Brochu
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
h1. BBPush
|
2
|
+
|
3
|
+
"http://github.com/nbrochu/bbpush":http://github.com/nbrochu/bbpush
|
4
|
+
|
5
|
+
h2. Summary
|
6
|
+
|
7
|
+
A simple server-side Blackberry push notification client that works with BIS applications.
|
8
|
+
|
9
|
+
h2. Description
|
10
|
+
|
11
|
+
BBPush is a simple server-side Blackberry push notification client that works with any BIS applications, regardless of it is in development or in production. All you need to use it are the Blackberry PINS of the devices you want to reach and a few configuration properties that you can get from the BB app developer. The library makes it trivial to send push notifications, be it for one PIN, multiple PINs or even all devices that have your app installed. Save yourself the headaches and frustrations of dealing with RIM. Install BBPush! ;)
|
12
|
+
|
13
|
+
Note that it only supports the BB Push Essentials service type (the free tier) at the moment since I have never needed to upgrade to Plus for any app (even some pretty large ones!). Feel free to fork and add support for the Plus service type if you feel like it. I'll gladly accept your pull request!
|
14
|
+
|
15
|
+
h2. Installation
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
gem install bbpush
|
19
|
+
</pre>
|
20
|
+
|
21
|
+
h2. How to use
|
22
|
+
|
23
|
+
*Require the library (and RubyGems if needed).*
|
24
|
+
<pre>
|
25
|
+
require 'rubygems'
|
26
|
+
require 'bbpush'
|
27
|
+
</pre>
|
28
|
+
|
29
|
+
*Initialize the Blackberry Push Client*
|
30
|
+
|
31
|
+
* "app_id" is the App ID listed in your Push Initiator configuration properties.
|
32
|
+
* "password" is the Password listed in your Push Initiator configuration properties.
|
33
|
+
* "push_server_url" is the Base URL listed in your Push Initiator configuration properties, followed by "/mss/PD_pushRequest". Defaults to "https://pushapi.eval.blackberry.com/mss/PD_pushRequest" if nothing is provided.
|
34
|
+
|
35
|
+
You can find these properties along with your credentials for the Content Provider Admin Portal (usually in an email).
|
36
|
+
<pre>
|
37
|
+
@bbpc = BBPush::Client.new(:app_id=>"yourappidhere",
|
38
|
+
:password=>"yourpasswordhere",
|
39
|
+
:push_server_url=>"https://cp123.pushapi.na.blackberry.com/mss/PD_pushRequest")
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
*Send push notifications*
|
43
|
+
|
44
|
+
* First parameter is an array of one or multiple device PINs as strings. It can also be an array containing only "push_all".
|
45
|
+
* Second parameter is a string containing the plain text message you would like to send to the device(s).
|
46
|
+
* Third parameter is an integer is the maximum number of minutes the notifications should be delivered within (5 is a good value!).
|
47
|
+
<pre>
|
48
|
+
@bbpc.send_notification(["12345678"], "Hello to the device with PIN 12345678!", 5)
|
49
|
+
@bbpc.send_notification(["12345678", "23456789", "34567890"], "Hello to 3 different devices!", 5)
|
50
|
+
@bbpc.send_notification(["push_all"], "Hello to all devices with the app installed!", 5)
|
51
|
+
</pre>
|
52
|
+
|
53
|
+
That's it! As long as your Blackberry client-side app is programmed to properly handle push notifications, the device(s) will receive it! If you would like to take a look at the PAP response provided by the Blackberry servers you can assign "BBPush::Client.send_notification" to a variable and the response will be stored like so:
|
54
|
+
|
55
|
+
<pre>
|
56
|
+
response = @bbpc.send_notification(["12345678"], "Hello to the device with PIN 12345678!", 5)
|
57
|
+
</pre>
|
58
|
+
|
59
|
+
If you then inspect "response" you should see a PAP response similar to this:
|
60
|
+
<pre>
|
61
|
+
<?xml version="1.0"?>
|
62
|
+
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
|
63
|
+
<pap>
|
64
|
+
<push-response push-id="2237803423" sender-address="http://cp123.pushapi.na.blackberry.com/mss/PD_pushRequest" sender-name="RIM Push-Data Service" reply-time="2010-12-14T21:32:46Z">
|
65
|
+
<response-result code="1001" desc="The request has been accepted for processing."></response-result>
|
66
|
+
</push-response>
|
67
|
+
</pap>
|
68
|
+
</pre>
|
69
|
+
|
70
|
+
Getting a 1001 Response Result Code indicates that everything is working perfectly on the server-side. If you still don't get the notifications, the problem resides on your client-side app!
|
71
|
+
|
72
|
+
h2. Credits
|
73
|
+
|
74
|
+
* Kudos to the guy on the BB Developer Forums that did the packet sniffing to figure out how it all works at the protocol level so we can keep our web apps and APIs lightweight and free of RIM code.
|
75
|
+
* Nega-Kudos to RIM for having the absolute worst documentation in the industry. Having to download an entire IDE (no Mac version available!) for a few bloated samples of Java code is plain retarded and doesn't count as documentation.
|
76
|
+
|
77
|
+
h2. LICENSE
|
78
|
+
|
79
|
+
Copyright (c) 2010 - Nicholas Brochu
|
80
|
+
|
81
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
82
|
+
a copy of this software and associated documentation files (the
|
83
|
+
'Software'), to deal in the Software without restriction, including
|
84
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
85
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
86
|
+
permit persons to whom the Software is furnished to do so, subject to
|
87
|
+
the following conditions:
|
88
|
+
|
89
|
+
The above copyright notice and this permission notice shall be
|
90
|
+
included in all copies or substantial portions of the Software.
|
91
|
+
|
92
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
93
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
94
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
95
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
96
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
97
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
98
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/bbpush.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module BBPush
|
2
|
+
class Client
|
3
|
+
BOUNDARY = "8d5588928a90afd3009d"
|
4
|
+
attr_accessor :app_id, :password, :push_server_url
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@app_id = options[:app_id]
|
8
|
+
@password = options[:password]
|
9
|
+
@push_server_url = options[:push_server_url] || "https://pushapi.eval.blackberry.com/mss/PD_pushRequest"
|
10
|
+
end
|
11
|
+
|
12
|
+
def send_notification(bb_pins, message, deliver_within)
|
13
|
+
http = Net::HTTP.new(URI.parse(self.push_server_url).host, 443)
|
14
|
+
|
15
|
+
http.use_ssl = true
|
16
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
17
|
+
|
18
|
+
addresses = []
|
19
|
+
bb_pins.each do |a|
|
20
|
+
addresses << "<address address-value=\"#{a}\"/>\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
push_id = ((Time.now.to_i * rand) + Time.now.to_i).round
|
24
|
+
|
25
|
+
path = URI.parse(self.push_server_url).path
|
26
|
+
|
27
|
+
headers = { "User-Agent" => "BBPush Ruby Library/0.1.0",
|
28
|
+
"Authorization" => "Basic #{Base64.encode64(self.app_id+':'+self.password)}",
|
29
|
+
"Content-Type" => "multipart/related; boundary=#{BBPush::Client::BOUNDARY}; type=application/xml"}
|
30
|
+
|
31
|
+
data = <<-BBPUSH
|
32
|
+
--#{BBPush::Client::BOUNDARY}
|
33
|
+
Content-Type: application/xml; charset=UTF-8
|
34
|
+
|
35
|
+
<?xml version="1.0"?>
|
36
|
+
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
|
37
|
+
<pap>
|
38
|
+
<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}">
|
39
|
+
#{addresses.join("\n")}<quality-of-service delivery-method="unconfirmed"/>
|
40
|
+
</push-message>
|
41
|
+
</pap>
|
42
|
+
--#{BBPush::Client::BOUNDARY}
|
43
|
+
Content-Type: text/plain
|
44
|
+
|
45
|
+
#{message}
|
46
|
+
--#{BBPush::Client::BOUNDARY}
|
47
|
+
BBPUSH
|
48
|
+
|
49
|
+
resp, data = http.post(path, data.gsub(/\n/,"\r\n"), headers)
|
50
|
+
return data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bbpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nicholas Brochu
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-14 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: BBPush is a simple server-side Blackberry push notification client that works with any BIS applications, regardless of it is in development or in production. All you need to use it are the Blackberry PINS of the devices you want to reach and a few configuration properties that you can get from the BB app developer. The library makes it trivial to send push notifications, be it for one PIN, multiple PINs or even all devices that have your app installed.
|
23
|
+
email: info@nicholasbrochu.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.textile
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- README.textile
|
34
|
+
- VERSION
|
35
|
+
- lib/bbpush.rb
|
36
|
+
- lib/bbpush/client.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/nbrochu/bbpush
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: A simple server-side Blackberry push notification client that works with BIS applications.
|
71
|
+
test_files: []
|
72
|
+
|