opensocial 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2008 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.dirname(__FILE__) + '/test_helper.rb'
16
+
17
+ class OnlineTest < Test::Unit::TestCase #:nodoc:
18
+ include TestHelper
19
+
20
+ # Tests a simple REST request
21
+ def test_online_rest
22
+ consumer_key = 'orkut.com:623061448914'
23
+ consumer_secret = 'uynAeXiWTisflWX99KU1D2q5'
24
+ requestor = '03067092798963641994'
25
+ c = OpenSocial::Connection.new(:consumer_key => consumer_key, :consumer_secret => consumer_secret, :xoauth_requestor_id => requestor)
26
+ r = OpenSocial::FetchPersonRequest.new(c)
27
+ person = r.send
28
+
29
+ assert_equal OpenSocial::Person, person.class
30
+ end
31
+
32
+ # Tests a simple RPC request
33
+ def test_online_rpc
34
+ consumer_key = 'orkut.com:623061448914'
35
+ consumer_secret = 'uynAeXiWTisflWX99KU1D2q5'
36
+ requestor = '03067092798963641994'
37
+ c = OpenSocial::Connection.new(:consumer_key => consumer_key, :consumer_secret => consumer_secret, :xoauth_requestor_id => requestor)
38
+ r = OpenSocial::RpcRequest.new(c)
39
+ r.add(:data => OpenSocial::FetchAppDataRequest.new)
40
+ data = r.send[:data]
41
+
42
+ assert_equal OpenSocial::Collection, data.class
43
+ end
44
+
45
+ # Test an unauthorized REST request
46
+ def test_unauthorized_rest_request
47
+ consumer_key = 'foo'
48
+ consumer_secret = 'bar'
49
+ requestor = 'baz'
50
+ c = OpenSocial::Connection.new(:consumer_key => consumer_key, :consumer_secret => consumer_secret, :xoauth_requestor_id => requestor)
51
+ r = OpenSocial::FetchPersonRequest.new(c)
52
+ assert_raise OpenSocial::AuthException do
53
+ person = r.send
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright (c) 2008 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.dirname(__FILE__) + '/test_helper.rb'
16
+
17
+ class PersonTest < Test::Unit::TestCase #:nodoc:
18
+ include TestHelper
19
+
20
+ # Tests construction of a person from a JSON entry
21
+ def test_initialization
22
+ json = load_json('person.json')
23
+ person = OpenSocial::Person.new(json['entry'])
24
+
25
+ assert_equal 'example.org:34KJDCSKJN2HHF0DW20394', person.id
26
+ assert_equal String, person.id.class
27
+
28
+ assert_equal Hash, person.name.class
29
+ assert_equal 'Jane Doe', person.name['unstructured']
30
+ assert_equal '', person.long_name
31
+
32
+ assert_equal Hash, person.gender.class
33
+ assert_equal '女性', person.gender['displayvalue']
34
+ assert_equal 'FEMALE', person.gender['key']
35
+
36
+ assert person.is_owner
37
+ assert person.is_viewer
38
+ end
39
+
40
+ # Tests construction of a person from a stubbed HTTP request
41
+ def test_fetch_person_request
42
+ json = load_json('person.json')
43
+
44
+ c = OpenSocial::Connection.new(NO_AUTH)
45
+ request = OpenSocial::FetchPersonRequest.new(c)
46
+ request.stubs(:send_request).returns(json)
47
+ person = request.send
48
+
49
+ assert_equal 'example.org:34KJDCSKJN2HHF0DW20394', person.id
50
+ assert_equal String, person.id.class
51
+
52
+ assert_equal Hash, person.name.class
53
+ assert_equal 'Jane Doe', person.name['unstructured']
54
+ assert_equal '', person.long_name
55
+
56
+ assert_equal Hash, person.gender.class
57
+ assert_equal '女性', person.gender['displayvalue']
58
+ assert_equal 'FEMALE', person.gender['key']
59
+
60
+ assert person.is_owner
61
+ assert person.is_viewer
62
+ end
63
+
64
+ # Tests construction of a collection of people from a stubbed HTTP request
65
+ def test_fetch_people_request
66
+ json = load_json('people.json')
67
+
68
+ c = OpenSocial::Connection.new(NO_AUTH)
69
+ request = OpenSocial::FetchPeopleRequest.new(c)
70
+ request.stubs(:send_request).returns(json)
71
+ people = request.send
72
+
73
+ # Check properties of the collection
74
+ assert_equal OpenSocial::Collection, people.class
75
+ assert_equal 2, people.length
76
+
77
+ # Check properties of the first person
78
+ first = people['example.org:34KJDCSKJN2HHF0DW20394']
79
+ assert_equal 'example.org:34KJDCSKJN2HHF0DW20394', first.id
80
+ assert_equal String, first.id.class
81
+
82
+ assert_equal Hash, first.name.class
83
+ assert_equal 'Jane Doe', first.name['unstructured']
84
+ assert_equal '', first.long_name
85
+
86
+ assert_equal Hash, first.gender.class
87
+ assert_equal '女性', first.gender['displayvalue']
88
+ assert_equal 'FEMALE', first.gender['key']
89
+
90
+ assert first.is_owner
91
+ assert first.is_viewer
92
+
93
+ # Check properties of the second person
94
+ second = people['example.org:34KJDCSKJN2HHF0DW20395']
95
+ assert_equal 'example.org:34KJDCSKJN2HHF0DW20395', second.id
96
+ assert_equal String, second.id.class
97
+
98
+ assert_equal Hash, second.name.class
99
+ assert_equal 'Jane Doe2', second.name['unstructured']
100
+ assert_equal '', second.long_name
101
+
102
+ assert_equal Hash, second.gender.class
103
+ assert_equal '女性', second.gender['displayvalue']
104
+ assert_equal 'FEMALE', second.gender['key']
105
+
106
+ assert !second.is_owner
107
+ assert !second.is_viewer
108
+ end
109
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright (c) 2008 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.dirname(__FILE__) + '/test_helper.rb'
16
+
17
+ class RequestTest < Test::Unit::TestCase #:nodoc:
18
+ include TestHelper
19
+
20
+ # Tests that a request properly throws an exception when a valid connection
21
+ # doesn't exist
22
+ def test_invalid_connection
23
+ request = OpenSocial::FetchPersonRequest.new
24
+ assert_raise OpenSocial::RequestException do
25
+ request.send
26
+ end
27
+ end
28
+
29
+ # Tests that send_request returns proper JSON
30
+ def test_json_parsing
31
+ # Test without unescaping data
32
+ json = load_file('person.json')
33
+
34
+ c = OpenSocial::Connection.new(NO_AUTH)
35
+ request = OpenSocial::FetchPersonRequest.new(c)
36
+ request.stubs(:dispatch).returns(json)
37
+ person = request.send
38
+
39
+ assert_equal OpenSocial::Person, person.class
40
+
41
+ # Test with unescaping data
42
+ json = load_file('appdata.json')
43
+
44
+ c = OpenSocial::Connection.new(NO_AUTH)
45
+ request = OpenSocial::FetchAppDataRequest.new(c)
46
+ request.stubs(:dispatch).returns(json)
47
+ appdata = request.send
48
+
49
+ assert_equal OpenSocial::Collection, appdata.class
50
+ end
51
+ end
@@ -0,0 +1,95 @@
1
+ # Copyright (c) 2008 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.dirname(__FILE__) + '/test_helper.rb'
16
+
17
+ class RpcRequestTest < Test::Unit::TestCase #:nodoc:
18
+ include TestHelper
19
+
20
+ # Tests that a request properly throws an exception when an empty list of
21
+ # requests is specified
22
+ def test_empty_requests
23
+ c = OpenSocial::Connection.new(NO_AUTH)
24
+ request = OpenSocial::RpcRequest.new(c)
25
+ assert_raise OpenSocial::RequestException do
26
+ request.send
27
+ end
28
+ end
29
+
30
+ # Tests object generation from a single (non-batched) stubbed HTTP request
31
+ # using RPC
32
+ def test_fetch_person_rpc_request
33
+ json = load_file('person_rpc.json')
34
+
35
+ c = OpenSocial::Connection.new(NO_AUTH)
36
+ request = OpenSocial::RpcRequest.new(c)
37
+ request.add(:me => OpenSocial::FetchPersonRequest.new)
38
+ request.stubs(:dispatch).returns(json)
39
+ response = request.send
40
+
41
+ assert_equal Hash, response.class
42
+ assert_equal 1, response.length
43
+ assert response.has_key?(:me)
44
+
45
+ compare_person(response[:me])
46
+ end
47
+
48
+ # Tests object generation from a batch stubbed HTTP request using RPC
49
+ def test_fetch_person_and_appdata_request
50
+ json = load_file('person_appdata_rpc.json')
51
+
52
+ c = OpenSocial::Connection.new(NO_AUTH)
53
+ request = OpenSocial::RpcRequest.new(c)
54
+ request.add(:me => OpenSocial::FetchPersonRequest.new)
55
+ request.add(:data => OpenSocial::FetchAppDataRequest.new)
56
+ request.stubs(:dispatch).returns(json)
57
+ response = request.send
58
+
59
+ assert_equal Hash, response.class
60
+ assert_equal 2, response.length
61
+ assert response.has_key?(:me)
62
+ assert response.has_key?(:data)
63
+
64
+ compare_person(response[:me])
65
+
66
+ appdata = response[:data]
67
+ assert_equal OpenSocial::Collection, appdata.class
68
+ assert_equal 1, appdata.length
69
+
70
+ entry = appdata['orkut.com:242412']
71
+ assert_equal Hash, entry.token.class
72
+ assert_equal Hash, entry.token["hash"].class
73
+ assert_equal String, entry.token["hash"]["key"].class
74
+ assert_equal "value", entry.token["hash"]["key"]
75
+ assert_equal Fixnum, entry.token["integer"].class
76
+ assert_equal 1241, entry.token["integer"]
77
+ end
78
+
79
+ private
80
+
81
+ def compare_person(person)
82
+ assert_equal 'orkut.com:242412', person.id
83
+ assert_equal String, person.id.class
84
+
85
+ assert_equal Hash, person.name.class
86
+ assert_equal 'Sample Testington', person.long_name
87
+ assert_equal 'Sample', person.short_name
88
+
89
+ assert_equal String, person.thumbnail_url.class
90
+ assert_equal 'http://www.orkut.com/img/i_nophoto64.gif', person.thumbnail_url
91
+
92
+ assert !person.is_owner
93
+ assert person.is_viewer
94
+ end
95
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2008 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test/unit'
16
+ require 'test/unit/ui/console/testrunner'
17
+ require 'test/unit/testsuite'
18
+
19
+ require File.dirname(__FILE__) + '/person_test'
20
+ require File.dirname(__FILE__) + '/group_test'
21
+ require File.dirname(__FILE__) + '/activity_test'
22
+ require File.dirname(__FILE__) + '/appdata_test'
23
+ require File.dirname(__FILE__) + '/rpcrequest_test'
24
+ require File.dirname(__FILE__) + '/request_test'
25
+ require File.dirname(__FILE__) + '/connection_test'
26
+ require File.dirname(__FILE__) + '/online_test'
27
+
28
+ class TS_AllTests #:nodoc:
29
+ def self.suite
30
+ suite = Test::Unit::TestSuite.new name
31
+ suite << ActivityTest.suite
32
+ suite << AppDataTest.suite
33
+ suite << GroupTest.suite
34
+ suite << PersonTest.suite
35
+ suite << RpcRequestTest.suite
36
+ suite << RequestTest.suite
37
+ suite << ConnectionTest.suite
38
+ suite << OnlineTest.suite
39
+ end
40
+ end
41
+ Test::Unit::UI::Console::TestRunner.run(TS_AllTests)
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2008 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test/unit'
16
+ require 'rubygems'
17
+ require 'mocha'
18
+ require 'json/pure'
19
+
20
+ require File.dirname(__FILE__) + '/../lib/opensocial.rb'
21
+
22
+ module TestHelper #:nodoc:
23
+ NO_AUTH = { :auth => OpenSocial::Connection::AUTH_ST, :st => 'some_value' }
24
+
25
+ def load_file(file, join = '')
26
+ lines = []
27
+ open(File.dirname(__FILE__) + "/fixtures/" + file) do |f|
28
+ f.each_line do |line|
29
+ lines << line
30
+ end
31
+ end
32
+
33
+ return lines.join(join)
34
+ end
35
+
36
+ def load_json(file)
37
+ JSON.parse(load_file(file))
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opensocial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Dan Holevoet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: mocha
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rails
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.1.0
54
+ version:
55
+ description:
56
+ email: api.dwh@google.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - README
63
+ - LICENSE
64
+ - NOTICE
65
+ files:
66
+ - lib/opensocial.rb
67
+ - lib/opensocial/activity.rb
68
+ - lib/opensocial/appdata.rb
69
+ - lib/opensocial/auth/action_controller_request.rb
70
+ - lib/opensocial/auth/base.rb
71
+ - lib/opensocial/base.rb
72
+ - lib/opensocial/connection.rb
73
+ - lib/opensocial/group.rb
74
+ - lib/opensocial/person.rb
75
+ - lib/opensocial/request.rb
76
+ - lib/opensocial/string/merb_string.rb
77
+ - lib/opensocial/string/os_string.rb
78
+ - tests/activity_test.rb
79
+ - tests/appdata_test.rb
80
+ - tests/connection_test.rb
81
+ - tests/group_test.rb
82
+ - tests/online_test.rb
83
+ - tests/person_test.rb
84
+ - tests/request_test.rb
85
+ - tests/rpcrequest_test.rb
86
+ - tests/test.rb
87
+ - tests/test_helper.rb
88
+ - tests/fixtures/activities.json
89
+ - tests/fixtures/activity.json
90
+ - tests/fixtures/appdata.json
91
+ - tests/fixtures/appdatum.json
92
+ - tests/fixtures/group.json
93
+ - tests/fixtures/groups.json
94
+ - tests/fixtures/people.json
95
+ - tests/fixtures/person.json
96
+ - tests/fixtures/person_appdata_rpc.json
97
+ - tests/fixtures/person_rpc.json
98
+ - README
99
+ - LICENSE
100
+ - NOTICE
101
+ has_rdoc: true
102
+ homepage: http://code.google.com/p/opensocial-ruby-client/
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --main
106
+ - README
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: "0"
120
+ version:
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.2.0
125
+ signing_key:
126
+ specification_version: 2
127
+ summary: Provides wrapper functionality and authentication for REST and RPC HTTP requests to OpenSocial-compliant endpoints, along with validation of incoming signed makeRequest calls.
128
+ test_files:
129
+ - tests/test.rb