qoobaa-opensocial 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,140 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright (c) 2008 Google Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require File.dirname(__FILE__) + "/helper.rb"
18
+
19
+ class TestPerson < OpenSocialTestCase
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
+
110
+ def test_sends_extra_parameter
111
+
112
+ c = OpenSocial::Connection.new(NO_AUTH)
113
+ json = load_json("people.json")
114
+
115
+ request = OpenSocial::FetchPeopleRequest.new(c, "@me", "@friends", :count => 500)
116
+ request.expects(:send_request).with(
117
+ "people",
118
+ "@me",
119
+ "@friends",
120
+ nil,
121
+ false,
122
+ {
123
+ :count => 500,
124
+ :fields => OpenSocial::FetchPersonRequest::DEFAULT_FIELDS.join(",")
125
+ }
126
+ ).returns(json)
127
+ people = request.send
128
+ end
129
+
130
+ # Tests construction of a person from a stubbed HTTP request
131
+ def test_fetch_person_request_asks_for_display_name
132
+ c = OpenSocial::Connection.new(NO_AUTH)
133
+ json = load_json("person.json")
134
+
135
+ request = OpenSocial::FetchPersonRequest.new(c)
136
+ expected_fields_requested = "id,dateOfBirth,name,emails,gender,state,postalCode,ethnicity,relationshipStatus,thumbnailUrl,displayName"
137
+ request.expects(:send_request).with("people", "@me", "@self", nil, false, :fields => expected_fields_requested).returns(json)
138
+ people = request.send
139
+ end
140
+ end
@@ -0,0 +1,49 @@
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__) + "/helper.rb"
16
+
17
+ class TestRequest < OpenSocialTestCase
18
+ # Tests that a request properly throws an exception when a valid connection
19
+ # doesn"t exist
20
+ def test_invalid_connection
21
+ request = OpenSocial::FetchPersonRequest.new
22
+ assert_raise OpenSocial::RequestException do
23
+ request.send
24
+ end
25
+ end
26
+
27
+ # Tests that send_request returns proper JSON
28
+ def test_json_parsing
29
+ # Test without unescaping data
30
+ json = load_file("person.json")
31
+
32
+ c = OpenSocial::Connection.new(NO_AUTH)
33
+ request = OpenSocial::FetchPersonRequest.new(c)
34
+ request.stubs(:dispatch).returns(json)
35
+ person = request.send
36
+
37
+ assert_equal OpenSocial::Person, person.class
38
+
39
+ # Test with unescaping data
40
+ json = load_file("appdata.json")
41
+
42
+ c = OpenSocial::Connection.new(NO_AUTH)
43
+ request = OpenSocial::FetchAppDataRequest.new(c)
44
+ request.stubs(:dispatch).returns(json)
45
+ appdata = request.send
46
+
47
+ assert_equal OpenSocial::Collection, appdata.class
48
+ end
49
+ end
@@ -0,0 +1,93 @@
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__) + "/helper.rb"
16
+
17
+ class TestRpcRequest < OpenSocialTestCase
18
+ # Tests that a request properly throws an exception when an empty list of
19
+ # requests is specified
20
+ def test_empty_requests
21
+ c = OpenSocial::Connection.new(NO_AUTH)
22
+ request = OpenSocial::RpcRequest.new(c)
23
+ assert_raise OpenSocial::RequestException do
24
+ request.send
25
+ end
26
+ end
27
+
28
+ # Tests object generation from a single (non-batched) stubbed HTTP request
29
+ # using RPC
30
+ def test_fetch_person_rpc_request
31
+ json = load_file("person_rpc.json")
32
+
33
+ c = OpenSocial::Connection.new(NO_AUTH)
34
+ request = OpenSocial::RpcRequest.new(c)
35
+ request.add(:me => OpenSocial::FetchPersonRequest.new)
36
+ request.stubs(:dispatch).returns(json)
37
+ response = request.send
38
+
39
+ assert_equal Hash, response.class
40
+ assert_equal 1, response.length
41
+ assert response.has_key?(:me)
42
+
43
+ compare_person(response[:me])
44
+ end
45
+
46
+ # Tests object generation from a batch stubbed HTTP request using RPC
47
+ def test_fetch_person_and_appdata_request
48
+ json = load_file("person_appdata_rpc.json")
49
+
50
+ c = OpenSocial::Connection.new(NO_AUTH)
51
+ request = OpenSocial::RpcRequest.new(c)
52
+ request.add(:me => OpenSocial::FetchPersonRequest.new)
53
+ request.add(:data => OpenSocial::FetchAppDataRequest.new)
54
+ request.stubs(:dispatch).returns(json)
55
+ response = request.send
56
+
57
+ assert_equal Hash, response.class
58
+ assert_equal 2, response.length
59
+ assert response.has_key?(:me)
60
+ assert response.has_key?(:data)
61
+
62
+ compare_person(response[:me])
63
+
64
+ appdata = response[:data]
65
+ assert_equal OpenSocial::Collection, appdata.class
66
+ assert_equal 1, appdata.length
67
+
68
+ entry = appdata["orkut.com:242412"]
69
+ assert_equal Hash, entry.token.class
70
+ assert_equal Hash, entry.token["hash"].class
71
+ assert_equal String, entry.token["hash"]["key"].class
72
+ assert_equal "value", entry.token["hash"]["key"]
73
+ assert_equal Fixnum, entry.token["integer"].class
74
+ assert_equal 1241, entry.token["integer"]
75
+ end
76
+
77
+ private
78
+
79
+ def compare_person(person)
80
+ assert_equal "orkut.com:242412", person.id
81
+ assert_equal String, person.id.class
82
+
83
+ assert_equal Hash, person.name.class
84
+ assert_equal "Sample Testington", person.long_name
85
+ assert_equal "Sample", person.short_name
86
+
87
+ assert_equal String, person.thumbnail_url.class
88
+ assert_equal "http://www.orkut.com/img/i_nophoto64.gif", person.thumbnail_url
89
+
90
+ assert !person.is_owner
91
+ assert person.is_viewer
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qoobaa-opensocial
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - "Jakub Ku\xC5\xBAma"
13
+ - Piotr Sarnacki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-24 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: oauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: test-unit
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 2
42
+ version: "2"
43
+ type: :development
44
+ version_requirements: *id002
45
+ - !ruby/object:Gem::Dependency
46
+ name: json_pure
47
+ prerelease: false
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ type: :development
56
+ version_requirements: *id003
57
+ - !ruby/object:Gem::Dependency
58
+ name: mocha
59
+ prerelease: false
60
+ requirement: &id004 !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ type: :development
68
+ version_requirements: *id004
69
+ description: OpenSocial Google Gem
70
+ email: qoobaa@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - .gitignore
81
+ - LICENSE
82
+ - NOTICE
83
+ - README.rdoc
84
+ - Rakefile
85
+ - VERSION
86
+ - lib/opensocial.rb
87
+ - lib/opensocial/activity.rb
88
+ - lib/opensocial/appdata.rb
89
+ - lib/opensocial/auth/action_controller_request.rb
90
+ - lib/opensocial/auth/base.rb
91
+ - lib/opensocial/base.rb
92
+ - lib/opensocial/connection.rb
93
+ - lib/opensocial/group.rb
94
+ - lib/opensocial/person.rb
95
+ - lib/opensocial/request.rb
96
+ - lib/opensocial/string/merb_string.rb
97
+ - lib/opensocial/string/os_string.rb
98
+ - qoobaa-opensocial.gemspec
99
+ - test/fixtures/activities.json
100
+ - test/fixtures/activity.json
101
+ - test/fixtures/appdata.json
102
+ - test/fixtures/appdatum.json
103
+ - test/fixtures/group.json
104
+ - test/fixtures/groups.json
105
+ - test/fixtures/people.json
106
+ - test/fixtures/person.json
107
+ - test/fixtures/person_appdata_rpc.json
108
+ - test/fixtures/person_rpc.json
109
+ - test/helper.rb
110
+ - test/test_activity.rb
111
+ - test/test_appdata.rb
112
+ - test/test_connection.rb
113
+ - test/test_group.rb
114
+ - test/test_online.rb
115
+ - test/test_person.rb
116
+ - test/test_request.rb
117
+ - test/test_rpcrequest.rb
118
+ has_rdoc: true
119
+ homepage: http://github.com/qoobaa/opensocial
120
+ licenses: []
121
+
122
+ post_install_message:
123
+ rdoc_options:
124
+ - --charset=UTF-8
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.3.6
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: OpenSocial Google Gem
148
+ test_files:
149
+ - test/test_request.rb
150
+ - test/test_rpcrequest.rb
151
+ - test/test_connection.rb
152
+ - test/test_appdata.rb
153
+ - test/test_person.rb
154
+ - test/test_activity.rb
155
+ - test/helper.rb
156
+ - test/test_group.rb
157
+ - test/test_online.rb