rhoconnect 4.0.0.beta.24 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG.md +20 -0
  2. data/Gemfile.lock +22 -23
  3. data/README.md +0 -2
  4. data/bench/benchapp/spec/spec_helper.rb +2 -2
  5. data/bench/blobapp/spec/spec_helper.rb +2 -2
  6. data/commands/rhoconnect/start.rb +8 -1
  7. data/doc/bulk-sync.txt +1 -23
  8. data/doc/push-client-setup-ios.txt +3 -3
  9. data/doc/push-client-setup-rps.txt +7 -7
  10. data/doc/push-client-setup.txt +18 -30
  11. data/doc/push-server-setup.txt +0 -14
  12. data/doc/push.txt +3 -5
  13. data/doc/source-adapters.txt +3 -2
  14. data/doc/supported-platforms.txt +6 -6
  15. data/generators/templates/application/spec/spec_helper.rb +2 -2
  16. data/install.sh +7 -2
  17. data/installer/unix-like/rho_connect_install_constants.rb +3 -3
  18. data/installer/utils/nix_install_test.rb +12 -4
  19. data/js-adapters/node.rb +1 -1
  20. data/lib/rhoconnect/bulk_data/bulk_data.rb +0 -5
  21. data/lib/rhoconnect/controller/js_base.rb +1 -0
  22. data/lib/rhoconnect/jobs/bulk_data_job.rb +0 -18
  23. data/lib/rhoconnect/ping/apple.rb +9 -6
  24. data/lib/rhoconnect/ping.rb +0 -2
  25. data/lib/rhoconnect/version.rb +1 -1
  26. data/lib/rhoconnect.rb +1 -14
  27. data/spec/controllers/js_base_spec.rb +20 -0
  28. data/spec/jobs/bulk_data_job_spec.rb +0 -42
  29. data/spec/jobs/ping_job_spec.rb +6 -30
  30. data/spec/rhoconnect_spec.rb +0 -1
  31. data/spec/server/server_spec.rb +4 -11
  32. data/spec/spec_helper.rb +4 -0
  33. data/spec/support/shared_examples.rb +2 -1
  34. metadata +4 -11
  35. data/doc/push-client-setup-bb.txt +0 -81
  36. data/lib/rhoconnect/ping/android.rb +0 -116
  37. data/lib/rhoconnect/ping/blackberry.rb +0 -56
  38. data/spec/ping/android_spec.rb +0 -121
  39. data/spec/ping/blackberry_spec.rb +0 -71
@@ -1,116 +0,0 @@
1
- require 'rest_client'
2
- require 'rhoconnect/store'
3
-
4
- module Rhoconnect
5
- class Android
6
- C2DM_AUTHTOKEN_KEY = 'app:application:c2dm_auth_token'
7
- class InvalidAuthToken < Exception; end
8
- class AndroidPingError < Exception; end
9
-
10
- def self.ping(params)
11
- already_retried = false
12
- begin
13
- settings = get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
14
- authtoken = settings[:authtoken]
15
-
16
- # obtain C2DM auth token
17
- if not authtoken
18
- authtoken = get_c2dm_token
19
- if not already_retried
20
- authtoken = "BadToken"
21
- end
22
- end
23
-
24
- send_ping_to_device(authtoken, params)
25
- rescue InvalidAuthToken => error
26
- if not already_retried
27
- Store.flush_data(C2DM_AUTHTOKEN_KEY)
28
- already_retried = true
29
- retry
30
- end
31
- log error
32
- log error.backtrace.join("\n")
33
- raise error
34
- rescue Exception => error
35
- log error
36
- log error.backtrace.join("\n")
37
- raise error
38
- end
39
- end
40
-
41
- def self.send_ping_to_device(authtoken,params)
42
- RestClient.post(
43
- 'https://android.apis.google.com/c2dm/send', c2d_message(params),
44
- :authorization => "GoogleLogin auth=#{authtoken}"
45
- ) do |response, request, result, &block|
46
- # return exceptions based on response code & body
47
- case response.code
48
- when 200
49
- if response.body =~ /^Error=(.*)$/
50
- raise AndroidPingError.new("Android ping error: #{$1 || ''}")
51
- else
52
- # store new token in redis for future calls
53
- if response.headers[:update_client_auth]
54
- Store.put_value(C2DM_AUTHTOKEN_KEY, response.headers[:update_client_auth])
55
- end
56
- response.return!(request, result, &block)
57
- end
58
- when 401, 403
59
- raise InvalidAuthToken.new("Invalid or expired auth token. Obtain new authtoken from C2DM service.")
60
- end
61
- end
62
- end
63
-
64
- def self.c2d_message(params)
65
- params.reject! {|k,v| v.nil? || v.length == 0}
66
- data = {}
67
- data['registration_id'] = params['device_pin']
68
- data['collapse_key'] = (rand * 100000000).to_i.to_s
69
- data['data.do_sync'] = params['sources'] ? params['sources'].join(',') : ''
70
- data['data.alert'] = params['message'] if params['message']
71
- data['data.vibrate'] = params['vibrate'] if params['vibrate']
72
- data['data.sound'] = params['sound'] if params['sound']
73
- data['data.phone_id'] = params['phone_id'] if params['phone_id']
74
- data
75
- end
76
-
77
- def self.get_c2dm_token
78
- if Store.exists? C2DM_AUTHTOKEN_KEY
79
- return Store.get_value(C2DM_AUTHTOKEN_KEY)
80
- end
81
-
82
- settings = get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
83
- data = {}
84
- data['accountType'] = 'HOSTED_OR_GOOGLE'
85
- data['Email'] = settings[:c2dm_username]
86
- data['Passwd'] = settings[:c2dm_passwd]
87
- data['service'] = 'ac2dm'
88
-
89
- urldata = ''
90
- data.each do |key,value|
91
- urldata += '&' + key.to_s + '=' + value.to_s
92
- end
93
- urldata[0,1] = ''
94
-
95
- RestClient.post(
96
- 'https://www.google.com/accounts/ClientLogin', urldata,
97
- :content_type => "application/x-www-form-urlencoded"
98
- ) do |response, request, result, &block|
99
- # return exceptions based on response code & body
100
- case response.code
101
- when 200
102
- authdata = /.*Auth=(.*)\n.*/.match(response.body)
103
- Store.put_value(C2DM_AUTHTOKEN_KEY, authdata[1])
104
- return authdata[1]
105
- else
106
- error_code = "Can not obtain auth token from C2DM service. Make sure that your C2DM credentials are valid."
107
- if response.body =~ /^Error=(.*)$/
108
- error_code += ': ' + response.body.to_s
109
- end
110
- raise InvalidAuthToken.new(error_code)
111
- end
112
- end
113
- nil
114
- end
115
- end
116
- end
@@ -1,56 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
- module Rhoconnect
4
- class Blackberry
5
- def self.ping(params)
6
- begin
7
- settings = get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
8
- host = settings[:mdsserver]
9
- port = settings[:mdsserverport]
10
- if (host and port)
11
- headers = { "X-WAP-APPLICATION-ID" => "/",
12
- "X-RIM-PUSH-DEST-PORT" => params['device_port'],
13
- "CONTENT-TYPE" => 'multipart/related; type="application/xml"; boundary=asdlfkjiurwghasf'}
14
-
15
- Net::HTTP.new(host,port).start do |http|
16
- request = Net::HTTP::Post.new('/pap',headers)
17
- request.body = pap_message(params)
18
- http.request(request)
19
- end
20
- end
21
- rescue Exception => error
22
- log "Error while sending ping: #{error}"
23
- raise error
24
- end
25
- end
26
-
27
- def self.pap_message(params)
28
- data = "do_sync=" + (params['sources'] ? params['sources'].join(',') : "") + "\r\n"
29
- data << "alert=#{params['message']}\r\n" if params['message']
30
- data << "vibrate=#{params['vibrate']}\r\n" if params['vibrate']
31
- data << "sound=#{params['sound']}\r\n" if params['sound']
32
- post_body = <<-DESC
33
- --asdlfkjiurwghasf
34
- Content-Type: application/xml; charset=UTF-8
35
-
36
- <?xml version="1.0"?>
37
- <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
38
- "http://www.wapforum.org/DTD/pap_2.0.dtd"
39
- [<?wap-pap-ver supported-versions="2.0"?>]>
40
- <pap>
41
- <push-message push-id="pushID:#{(rand * 100000000).to_i.to_s}" ppg-notify-requested-to="http://localhost:7778">
42
-
43
- <address address-value="WAPPUSH=#{params['device_pin'].to_i.to_s(base=16).upcase}%3A100/TYPE=USER@rim.net"/>
44
- <quality-of-service delivery-method="preferconfirmed"/>
45
- </push-message>
46
- </pap>
47
- --asdlfkjiurwghasf
48
- Content-Type: text/plain
49
-
50
- #{data}
51
- --asdlfkjiurwghasf--
52
- DESC
53
- post_body.gsub!(/\n/,"\r\n")
54
- end
55
- end
56
- end
@@ -1,121 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'..','spec_helper')
2
-
3
- describe "Ping Android" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
5
-
6
- before do
7
- @params = {"device_pin" => @c.device_pin,
8
- "sources" => [@s.name], "message" => 'hello world',
9
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
10
- @response = mock('response')
11
- end
12
-
13
- it "should ping android successfully" do
14
- Store.put_value(Android::C2DM_AUTHTOKEN_KEY, 'ValidAuthToken')
15
- result = 'id=0:34234234134254%abc123\n'
16
- @response.stub!(:code).and_return(200)
17
- @response.stub!(:body).and_return(result)
18
- @response.stub!(:headers).and_return({})
19
- @response.stub!(:return!).and_return(@response)
20
- setup_post_yield(@response)
21
- Android.ping(@params).body.should == result
22
- end
23
-
24
- it "should ping android with 503 connection error" do
25
- error = 'Connection refused'
26
- @response.stub!(:body).and_return(error)
27
- RestClient.stub!(:post).and_return { raise RestClient::Exception.new(@response,503) }
28
- Android.should_receive(:log).twice
29
- lambda { Android.ping(@params) }.should raise_error(RestClient::Exception)
30
- end
31
-
32
- it "should ping android with 200 error message" do
33
- Store.put_value(Android::C2DM_AUTHTOKEN_KEY, 'ValidAuthToken')
34
- error = 'Error=QuotaExceeded'
35
- @response.stub!(:code).and_return(200)
36
- @response.stub!(:body).and_return(error)
37
- @response.stub!(:headers).and_return(nil)
38
- setup_post_yield(@response)
39
- Android.should_receive(:log).twice
40
- lambda { Android.ping(@params) }.should raise_error(Android::AndroidPingError, "Android ping error: QuotaExceeded")
41
- end
42
-
43
- it "should fail to obtain auth token from C2DM without creds" do
44
- error = 'Error=BadAuthentication'
45
- @response.stub!(:code).and_return(403)
46
- @response.stub!(:body).and_return(error)
47
- @response.stub!(:headers).and_return({})
48
- setup_post_yield(@response)
49
- Android.should_receive(:log).twice
50
- lambda { Android.ping(@params) }.should raise_error(Android::InvalidAuthToken, "Can not obtain auth token from C2DM service. Make sure that your C2DM credentials are valid.: Error=BadAuthentication")
51
- end
52
-
53
- it "should pass to obtain auth token from C2DM" do
54
- result = "SID=somesid\nAuth=myauthtoken\n"
55
- @response.stub!(:code).and_return(200)
56
- @response.stub!(:body).and_return(result)
57
- @response.stub!(:headers).and_return({})
58
- setup_post_yield(@response)
59
-
60
- Android.get_c2dm_token
61
- Store.get_value(Android::C2DM_AUTHTOKEN_KEY).should == 'myauthtoken'
62
- end
63
-
64
- it "should fail with invalid C2DM token and call retry" do
65
- Store.put_value(Android::C2DM_AUTHTOKEN_KEY, 'BadToken')
66
- error = 'Error=BadAuthentication'
67
- @response.stub!(:code).and_return(403)
68
- @response.stub!(:body).and_return(error)
69
- @response.stub!(:[]).and_return(nil)
70
- setup_post_yield(@response)
71
-
72
- Store.should_receive(:flush_data).once
73
- Android.should_receive(:get_c2dm_token).twice.and_return('BadToken')
74
- Android.should_receive(:log).twice
75
- lambda { Android.ping(@params) }.should raise_error(Android::InvalidAuthToken, "Invalid or expired auth token. Obtain new authtoken from C2DM service.")
76
- end
77
-
78
- it "should ping android and receive Update-Client-Auth header" do
79
- Store.put_value(Android::C2DM_AUTHTOKEN_KEY, 'ValidAuthToken')
80
- @response.stub!(:code).and_return(200)
81
- @response.stub!(:body).and_return('')
82
- @response.stub!(:headers).and_return(:update_client_auth => 'abc123')
83
- @response.stub!(:return!).and_return(@response)
84
- setup_post_yield(@response)
85
- Android.ping(@params)
86
- Store.get_value(Android::C2DM_AUTHTOKEN_KEY).should_not == 'ValidAuthToken'
87
- end
88
-
89
- it "should ping android with 401 error message" do
90
- @response.stub!(:code).and_return(401)
91
- @response.stub!(:body).and_return('')
92
- setup_post_yield(@response)
93
- Android.should_receive(:get_c2dm_token).twice.and_return("ValidAuthToken")
94
- Android.should_receive(:log).twice
95
- lambda { Android.ping(@params) }.should raise_error(
96
- Android::InvalidAuthToken, "Invalid or expired auth token. Obtain new authtoken from C2DM service."
97
- )
98
- end
99
-
100
- it "should compute c2d_message" do
101
- expected = {'registration_id' => @c.device_pin, 'collapse_key' => "RAND_KEY",
102
- 'data.do_sync' => @s.name,
103
- 'data.alert' => "hello world",
104
- 'data.vibrate' => '5',
105
- 'data.sound' => "hello.mp3"}
106
- actual = Android.c2d_message(@params)
107
- actual['collapse_key'] = "RAND_KEY" unless actual['collapse_key'].nil?
108
- actual.should == expected
109
- end
110
-
111
- it "should trim empty or nil params from c2d_message" do
112
- expected = {'registration_id' => @c.device_pin, 'collapse_key' => "RAND_KEY",
113
- 'data.vibrate' => '5', 'data.do_sync' => '', 'data.sound' => "hello.mp3"}
114
- params = {"device_pin" => @c.device_pin,
115
- "sources" => [], "message" => '', "vibrate" => '5', "sound" => 'hello.mp3'}
116
- actual = Android.c2d_message(params)
117
- actual['collapse_key'] = "RAND_KEY" unless actual['collapse_key'].nil?
118
- actual.should == expected
119
- end
120
- end
121
- end
@@ -1,71 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'..','spec_helper')
2
-
3
- describe "Ping Blackberry" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
5
- before do
6
- @params = {"user_id" => @u.id, "api_token" => @api_token,
7
- "sources" => [@s.name], "message" => 'hello world',
8
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
9
- "device_pin" => @c.device_pin, "device_port" => @c.device_port}
10
- post = mock('post')
11
- post.stub!(:new).and_return(post)
12
- post.stub!(:body=)
13
- Net::HTTP::Post.stub!(:new).and_return(post)
14
-
15
- @http = mock('http')
16
- @http.stub!(:request)
17
- @http.stub!(:start).and_yield(@http)
18
- Net::HTTP.stub!(:new).and_return(@http)
19
- end
20
-
21
- it "should ping blackberry" do
22
- Blackberry.ping(@params)
23
- end
24
-
25
- it "should ping blackberry with connection error" do
26
- error = 'Connection refused'
27
- Rhoconnect::Blackberry.stub!(:get_config).and_return({:test => {:mdsserver=>'testserver',:mdsserverport=>'testport'}})
28
- Rhoconnect::Blackberry.should_receive(:get_config).once
29
- @http.stub!(:request).and_return { raise SocketError.new(error) }
30
- Blackberry.should_receive(:log).once.with("Error while sending ping: #{error}")
31
- lambda { Blackberry.ping(@params) }.should raise_error(SocketError,error)
32
- end
33
-
34
- it "should do nothing if no host and port" do
35
- error = 'Connection refused'
36
- Rhoconnect::Blackberry.stub!(:get_config).and_return({:test => {}})
37
- Rhoconnect::Blackberry.should_receive(:get_config).once
38
- Net::HTTP.should_receive(:new).exactly(0).times
39
- Blackberry.ping(@params)
40
- end
41
-
42
- it "should compute pap_message" do
43
- expected = <<PAP
44
- --asdlfkjiurwghasf
45
- Content-Type: application/xml; charset=UTF-8
46
-
47
- <?xml version="1.0"?>
48
- <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
49
- "http://www.wapforum.org/DTD/pap_2.0.dtd"
50
- [<?wap-pap-ver supported-versions="2.0"?>]>
51
- <pap>
52
- <push-message push-id="pushID:RAND_ID" ppg-notify-requested-to="http://localhost:7778">
53
-
54
- <address address-value="WAPPUSH=0%3A100/TYPE=USER@rim.net"/>
55
- <quality-of-service delivery-method="preferconfirmed"/>
56
- </push-message>
57
- </pap>
58
- --asdlfkjiurwghasf
59
- Content-Type: text/plain
60
-
61
- do_sync=SampleAdapter
62
- alert=hello world
63
- vibrate=5
64
- sound=hello.mp3
65
- --asdlfkjiurwghasf--
66
- PAP
67
- actual = Blackberry.pap_message(@params).gsub!(/pushID\:\d+/,'pushID:RAND_ID')
68
- actual.gsub!(/\r|\n|\s/,"").should == expected.gsub!(/\r|\n|\s/,"")
69
- end
70
- end
71
- end