koala 0.10.0 → 1.0.0.rc
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.
- data/.gitignore +3 -0
- data/CHANGELOG +39 -7
- data/Gemfile +3 -0
- data/Manifest +8 -1
- data/Rakefile +13 -14
- data/koala.gemspec +36 -19
- data/lib/koala/graph_api.rb +188 -123
- data/lib/koala/http_services.rb +93 -18
- data/lib/koala/rest_api.rb +73 -6
- data/lib/koala/test_users.rb +21 -8
- data/lib/koala/uploadable_io.rb +115 -0
- data/lib/koala.rb +86 -86
- data/readme.md +18 -12
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/graph_and_rest_api_spec.rb +31 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/cases/http_services/http_service_spec.rb +54 -0
- data/spec/cases/http_services/net_http_service_spec.rb +350 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
- data/spec/cases/oauth_spec.rb +374 -0
- data/spec/cases/realtime_updates_spec.rb +184 -0
- data/spec/cases/rest_api_spec.rb +25 -0
- data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +78 -72
- data/spec/cases/uploadable_io_spec.rb +151 -0
- data/spec/fixtures/beach.jpg +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +13 -9
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +312 -289
- data/spec/spec_helper.rb +18 -0
- data/spec/support/graph_api_shared_examples.rb +424 -0
- data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
- data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -81
- data/spec/support/rest_api_shared_examples.rb +161 -0
- data/spec/support/setup_mocks_or_live.rb +52 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +130 -43
- data/init.rb +0 -2
- data/spec/koala/api_base_tests.rb +0 -102
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -10
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/net_http_service_tests.rb +0 -186
- data/spec/koala/oauth/oauth_tests.rb +0 -438
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -48
- data/spec/koala_spec_without_mocks.rb +0 -19
metadata
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: koala
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 7712010
|
|
5
|
+
prerelease: 6
|
|
5
6
|
segments:
|
|
7
|
+
- 1
|
|
6
8
|
- 0
|
|
7
|
-
- 10
|
|
8
9
|
- 0
|
|
9
|
-
|
|
10
|
+
- rc
|
|
11
|
+
version: 1.0.0.rc
|
|
10
12
|
platform: ruby
|
|
11
13
|
authors:
|
|
12
14
|
- Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
|
|
@@ -14,43 +16,103 @@ autorequire:
|
|
|
14
16
|
bindir: bin
|
|
15
17
|
cert_chain: []
|
|
16
18
|
|
|
17
|
-
date:
|
|
19
|
+
date: 2011-04-18 00:00:00 +02:00
|
|
18
20
|
default_executable:
|
|
19
21
|
dependencies:
|
|
20
22
|
- !ruby/object:Gem::Dependency
|
|
21
|
-
name: json
|
|
22
|
-
prerelease: false
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
24
25
|
requirements:
|
|
25
|
-
- -
|
|
26
|
+
- - ~>
|
|
26
27
|
- !ruby/object:Gem::Version
|
|
28
|
+
hash: 15
|
|
27
29
|
segments:
|
|
28
30
|
- 1
|
|
29
31
|
- 0
|
|
30
32
|
version: "1.0"
|
|
31
|
-
|
|
33
|
+
prerelease: false
|
|
32
34
|
version_requirements: *id001
|
|
33
|
-
|
|
35
|
+
type: :runtime
|
|
36
|
+
name: json
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ~>
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
hash: 15
|
|
44
|
+
segments:
|
|
45
|
+
- 1
|
|
46
|
+
- 0
|
|
47
|
+
version: "1.0"
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: *id002
|
|
50
|
+
type: :runtime
|
|
51
|
+
name: multipart-post
|
|
52
|
+
- !ruby/object:Gem::Dependency
|
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
54
|
+
none: false
|
|
55
|
+
requirements:
|
|
56
|
+
- - ~>
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
hash: 27
|
|
59
|
+
segments:
|
|
60
|
+
- 2
|
|
61
|
+
- 5
|
|
62
|
+
- 0
|
|
63
|
+
version: 2.5.0
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: *id003
|
|
66
|
+
type: :development
|
|
67
|
+
name: rspec
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
70
|
+
none: false
|
|
71
|
+
requirements:
|
|
72
|
+
- - ~>
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
hash: 49
|
|
75
|
+
segments:
|
|
76
|
+
- 0
|
|
77
|
+
- 8
|
|
78
|
+
- 7
|
|
79
|
+
version: 0.8.7
|
|
80
|
+
prerelease: false
|
|
81
|
+
version_requirements: *id004
|
|
82
|
+
type: :development
|
|
83
|
+
name: rake
|
|
84
|
+
- !ruby/object:Gem::Dependency
|
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
86
|
+
none: false
|
|
87
|
+
requirements:
|
|
88
|
+
- - ~>
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
hash: 31
|
|
91
|
+
segments:
|
|
92
|
+
- 0
|
|
93
|
+
- 2
|
|
94
|
+
- 4
|
|
95
|
+
version: 0.2.4
|
|
96
|
+
prerelease: false
|
|
97
|
+
version_requirements: *id005
|
|
98
|
+
type: :development
|
|
99
|
+
name: typhoeus
|
|
100
|
+
description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.
|
|
34
101
|
email: alex@alexkoppel.com
|
|
35
102
|
executables: []
|
|
36
103
|
|
|
37
104
|
extensions: []
|
|
38
105
|
|
|
39
106
|
extra_rdoc_files:
|
|
107
|
+
- readme.md
|
|
40
108
|
- CHANGELOG
|
|
41
|
-
- LICENSE
|
|
42
|
-
- lib/koala.rb
|
|
43
|
-
- lib/koala/graph_api.rb
|
|
44
|
-
- lib/koala/http_services.rb
|
|
45
|
-
- lib/koala/realtime_updates.rb
|
|
46
|
-
- lib/koala/rest_api.rb
|
|
47
|
-
- lib/koala/test_users.rb
|
|
48
109
|
files:
|
|
110
|
+
- .gitignore
|
|
49
111
|
- CHANGELOG
|
|
112
|
+
- Gemfile
|
|
50
113
|
- LICENSE
|
|
51
114
|
- Manifest
|
|
52
115
|
- Rakefile
|
|
53
|
-
- init.rb
|
|
54
116
|
- koala.gemspec
|
|
55
117
|
- lib/koala.rb
|
|
56
118
|
- lib/koala/graph_api.rb
|
|
@@ -58,26 +120,29 @@ files:
|
|
|
58
120
|
- lib/koala/realtime_updates.rb
|
|
59
121
|
- lib/koala/rest_api.rb
|
|
60
122
|
- lib/koala/test_users.rb
|
|
123
|
+
- lib/koala/uploadable_io.rb
|
|
61
124
|
- readme.md
|
|
62
|
-
- spec/
|
|
63
|
-
- spec/
|
|
64
|
-
- spec/
|
|
65
|
-
- spec/
|
|
66
|
-
- spec/
|
|
67
|
-
- spec/
|
|
68
|
-
- spec/
|
|
69
|
-
- spec/
|
|
70
|
-
- spec/
|
|
71
|
-
- spec/
|
|
72
|
-
- spec/
|
|
73
|
-
- spec/
|
|
74
|
-
- spec/
|
|
75
|
-
- spec/
|
|
76
|
-
- spec/
|
|
77
|
-
- spec/
|
|
78
|
-
- spec/
|
|
79
|
-
- spec/
|
|
80
|
-
- spec/
|
|
125
|
+
- spec/cases/api_base_spec.rb
|
|
126
|
+
- spec/cases/graph_and_rest_api_spec.rb
|
|
127
|
+
- spec/cases/graph_api_spec.rb
|
|
128
|
+
- spec/cases/http_services/http_service_spec.rb
|
|
129
|
+
- spec/cases/http_services/net_http_service_spec.rb
|
|
130
|
+
- spec/cases/http_services/typhoeus_service_spec.rb
|
|
131
|
+
- spec/cases/oauth_spec.rb
|
|
132
|
+
- spec/cases/realtime_updates_spec.rb
|
|
133
|
+
- spec/cases/rest_api_spec.rb
|
|
134
|
+
- spec/cases/test_users_spec.rb
|
|
135
|
+
- spec/cases/uploadable_io_spec.rb
|
|
136
|
+
- spec/fixtures/beach.jpg
|
|
137
|
+
- spec/fixtures/facebook_data.yml
|
|
138
|
+
- spec/fixtures/mock_facebook_responses.yml
|
|
139
|
+
- spec/spec_helper.rb
|
|
140
|
+
- spec/support/graph_api_shared_examples.rb
|
|
141
|
+
- spec/support/live_testing_data_helper.rb
|
|
142
|
+
- spec/support/mock_http_service.rb
|
|
143
|
+
- spec/support/rest_api_shared_examples.rb
|
|
144
|
+
- spec/support/setup_mocks_or_live.rb
|
|
145
|
+
- spec/support/uploadable_io_shared_examples.rb
|
|
81
146
|
has_rdoc: true
|
|
82
147
|
homepage: http://github.com/arsduo/koala
|
|
83
148
|
licenses: []
|
|
@@ -88,31 +153,53 @@ rdoc_options:
|
|
|
88
153
|
- --inline-source
|
|
89
154
|
- --title
|
|
90
155
|
- Koala
|
|
91
|
-
- --main
|
|
92
|
-
- readme.md
|
|
93
156
|
require_paths:
|
|
94
157
|
- lib
|
|
95
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
|
+
none: false
|
|
96
160
|
requirements:
|
|
97
161
|
- - ">="
|
|
98
162
|
- !ruby/object:Gem::Version
|
|
163
|
+
hash: 3
|
|
99
164
|
segments:
|
|
100
165
|
- 0
|
|
101
166
|
version: "0"
|
|
102
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
|
+
none: false
|
|
103
169
|
requirements:
|
|
104
170
|
- - ">="
|
|
105
171
|
- !ruby/object:Gem::Version
|
|
172
|
+
hash: 11
|
|
106
173
|
segments:
|
|
107
174
|
- 1
|
|
108
175
|
- 2
|
|
109
176
|
version: "1.2"
|
|
110
177
|
requirements: []
|
|
111
178
|
|
|
112
|
-
rubyforge_project:
|
|
113
|
-
rubygems_version: 1.
|
|
179
|
+
rubyforge_project:
|
|
180
|
+
rubygems_version: 1.4.2
|
|
114
181
|
signing_key:
|
|
115
182
|
specification_version: 3
|
|
116
|
-
summary: A lightweight, flexible library for Facebook with support for the Graph API, the
|
|
117
|
-
test_files:
|
|
118
|
-
|
|
183
|
+
summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.
|
|
184
|
+
test_files:
|
|
185
|
+
- spec/cases/api_base_spec.rb
|
|
186
|
+
- spec/cases/graph_and_rest_api_spec.rb
|
|
187
|
+
- spec/cases/graph_api_spec.rb
|
|
188
|
+
- spec/cases/http_services/http_service_spec.rb
|
|
189
|
+
- spec/cases/http_services/net_http_service_spec.rb
|
|
190
|
+
- spec/cases/http_services/typhoeus_service_spec.rb
|
|
191
|
+
- spec/cases/oauth_spec.rb
|
|
192
|
+
- spec/cases/realtime_updates_spec.rb
|
|
193
|
+
- spec/cases/rest_api_spec.rb
|
|
194
|
+
- spec/cases/test_users_spec.rb
|
|
195
|
+
- spec/cases/uploadable_io_spec.rb
|
|
196
|
+
- spec/fixtures/beach.jpg
|
|
197
|
+
- spec/fixtures/facebook_data.yml
|
|
198
|
+
- spec/fixtures/mock_facebook_responses.yml
|
|
199
|
+
- spec/spec_helper.rb
|
|
200
|
+
- spec/support/graph_api_shared_examples.rb
|
|
201
|
+
- spec/support/live_testing_data_helper.rb
|
|
202
|
+
- spec/support/mock_http_service.rb
|
|
203
|
+
- spec/support/rest_api_shared_examples.rb
|
|
204
|
+
- spec/support/setup_mocks_or_live.rb
|
|
205
|
+
- spec/support/uploadable_io_shared_examples.rb
|
data/init.rb
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
class ApiBaseTests < Test::Unit::TestCase
|
|
2
|
-
|
|
3
|
-
describe "Koala API base class" do
|
|
4
|
-
before(:each) do
|
|
5
|
-
@service = Koala::Facebook::API.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should not include an access token if none was given" do
|
|
9
|
-
Koala.should_receive(:make_request).with(
|
|
10
|
-
anything,
|
|
11
|
-
hash_not_including('access_token' => 1),
|
|
12
|
-
anything,
|
|
13
|
-
anything
|
|
14
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
15
|
-
|
|
16
|
-
@service.api('anything')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "should include an access token if given" do
|
|
20
|
-
token = 'adfadf'
|
|
21
|
-
service = Koala::Facebook::API.new token
|
|
22
|
-
|
|
23
|
-
Koala.should_receive(:make_request).with(
|
|
24
|
-
anything,
|
|
25
|
-
hash_including('access_token' => token),
|
|
26
|
-
anything,
|
|
27
|
-
anything
|
|
28
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
29
|
-
|
|
30
|
-
service.api('anything')
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should have an attr_reader for access token" do
|
|
34
|
-
token = 'adfadf'
|
|
35
|
-
service = Koala::Facebook::API.new token
|
|
36
|
-
service.access_token.should == token
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "should get the attribute of a Koala::Response given by the http_component parameter" do
|
|
40
|
-
http_component = :method_name
|
|
41
|
-
|
|
42
|
-
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
|
43
|
-
response.should_receive(http_component).and_return('')
|
|
44
|
-
|
|
45
|
-
Koala.stub(:make_request).and_return(response)
|
|
46
|
-
|
|
47
|
-
@service.api('anything', 'get', {}, :http_component => http_component)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should return the body of the request as JSON if no http_component is given" do
|
|
51
|
-
response = stub('response', :body => 'body', :status => 200)
|
|
52
|
-
Koala.stub(:make_request).and_return(response)
|
|
53
|
-
|
|
54
|
-
json_body = mock('JSON body')
|
|
55
|
-
JSON.stub(:parse).and_return([json_body])
|
|
56
|
-
|
|
57
|
-
@service.api('anything').should == json_body
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should execute a block with the response body if passed one" do
|
|
61
|
-
body = '{}'
|
|
62
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
|
|
63
|
-
|
|
64
|
-
yield_test = mock('Yield Tester')
|
|
65
|
-
yield_test.should_receive(:pass)
|
|
66
|
-
|
|
67
|
-
@service.api('anything') do |arg|
|
|
68
|
-
yield_test.pass
|
|
69
|
-
arg.should == JSON.parse(body)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should raise an API error if the HTTP response code is greater than or equal to 500" do
|
|
74
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
|
|
75
|
-
|
|
76
|
-
lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "should handle rogue true/false as responses" do
|
|
80
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
|
|
81
|
-
@service.api('anything').should be_true
|
|
82
|
-
|
|
83
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
|
|
84
|
-
@service.api('anything').should be_false
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
describe "with regard to leading slashes" do
|
|
88
|
-
it "should add a leading / to the path if not present" do
|
|
89
|
-
path = "anything"
|
|
90
|
-
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
91
|
-
@service.api(path)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "shouldn't change the path if a leading / is present" do
|
|
95
|
-
path = "/anything"
|
|
96
|
-
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
97
|
-
@service.api(path)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
end
|
|
102
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
class GraphAndRestAPINoTokenTests < Test::Unit::TestCase
|
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
|
3
|
-
before(:each) do
|
|
4
|
-
@api = Koala::Facebook::GraphAndRestAPI.new
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
it_should_behave_like "Koala RestAPI without an access token"
|
|
8
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
|
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
|
3
|
-
include LiveTestingDataHelper
|
|
4
|
-
it_should_behave_like "Koala RestAPI with an access token"
|
|
5
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
|
6
|
-
|
|
7
|
-
before(:each) do
|
|
8
|
-
@api = Koala::Facebook::GraphAndRestAPI.new(@token)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala GraphAPI without an access token" do
|
|
2
|
-
it "should get public data about a user" do
|
|
3
|
-
result = @api.get_object("koppel")
|
|
4
|
-
# the results should have an ID and a name, among other things
|
|
5
|
-
(result["id"] && result["name"]).should
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should not get private data about a user" do
|
|
9
|
-
result = @api.get_object("koppel")
|
|
10
|
-
# updated_time should be a pretty fixed test case
|
|
11
|
-
result["updated_time"].should be_nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should get public data about a Page" do
|
|
15
|
-
result = @api.get_object("contextoptional")
|
|
16
|
-
# the results should have an ID and a name, among other things
|
|
17
|
-
(result["id"] && result["name"]).should
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should not be able to get data about 'me'" do
|
|
21
|
-
lambda { @api.get_object("me") }.should raise_error(Koala::Facebook::APIError)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should be able to get multiple objects" do
|
|
25
|
-
results = @api.get_objects(["contextoptional", "naitik"])
|
|
26
|
-
results.length.should == 2
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "shouldn't be able to access connections from users" do
|
|
30
|
-
lambda { @api.get_connections("lukeshepard", "likes") }.should raise_error(Koala::Facebook::APIError)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should be able to access a user's picture" do
|
|
34
|
-
@api.get_picture("chris.baclig").should =~ /http\:\/\//
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should be able to access a user's picture, given a picture type" do
|
|
38
|
-
@api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should be able to access connections from public Pages" do
|
|
42
|
-
result = @api.get_connections("contextoptional", "photos")
|
|
43
|
-
result.should be_a(Array)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# paging
|
|
47
|
-
# see also graph_collection_tests
|
|
48
|
-
it "should make a request for a page when provided a specific set of page params" do
|
|
49
|
-
query = [1, 2]
|
|
50
|
-
@api.should_receive(:graph_call).with(*query)
|
|
51
|
-
@api.get_page(query)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should not be able to put an object" do
|
|
55
|
-
lambda { @result = @api.put_object("lukeshepard", "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
|
|
56
|
-
puts "Error! Object #{@result.inspect} somehow put onto Luke Shepard's wall!" if @result
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# these are not strictly necessary as the other put methods resolve to put_object, but are here for completeness
|
|
60
|
-
it "should not be able to post to a feed" do
|
|
61
|
-
(lambda do
|
|
62
|
-
attachment = {:name => "Context Optional", :link => "http://www.contextoptional.com/"}
|
|
63
|
-
@result = @api.put_wall_post("Hello, world", attachment, "contextoptional")
|
|
64
|
-
end).should raise_error(Koala::Facebook::APIError)
|
|
65
|
-
puts "Error! Object #{@result.inspect} somehow put onto Context Optional's wall!" if @result
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should not be able to comment on an object" do
|
|
69
|
-
# random public post on the ContextOptional wall
|
|
70
|
-
lambda { @result = @api.put_comment("7204941866_119776748033392", "The hackathon was great!") }.should raise_error(Koala::Facebook::APIError)
|
|
71
|
-
puts "Error! Object #{@result.inspect} somehow commented on post 7204941866_119776748033392!" if @result
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should not be able to like an object" do
|
|
75
|
-
lambda { @api.put_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# DELETE
|
|
79
|
-
it "should not be able to delete posts" do
|
|
80
|
-
# test post on the Ruby SDK Test application
|
|
81
|
-
lambda { @result = @api.delete_object("115349521819193_113815981982767") }.should raise_error(Koala::Facebook::APIError)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# SEARCH
|
|
85
|
-
it "should be able to search" do
|
|
86
|
-
result = @api.search("facebook")
|
|
87
|
-
result.length.should be_an(Integer)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
|
91
|
-
|
|
92
|
-
# API
|
|
93
|
-
it "should never use the rest api server" do
|
|
94
|
-
Koala.should_receive(:make_request).with(
|
|
95
|
-
anything,
|
|
96
|
-
anything,
|
|
97
|
-
anything,
|
|
98
|
-
hash_not_including(:rest_api => true)
|
|
99
|
-
).and_return(Koala::Response.new(200, "", {}))
|
|
100
|
-
|
|
101
|
-
@api.api("anything")
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class FacebookNoAccessTokenTests < Test::Unit::TestCase
|
|
106
|
-
describe "Koala GraphAPI without an access token" do
|
|
107
|
-
before :each do
|
|
108
|
-
@api = Koala::Facebook::GraphAPI.new
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala GraphAPI with an access token" do
|
|
2
|
-
it "should get public data about a user" do
|
|
3
|
-
result = @api.get_object("koppel")
|
|
4
|
-
# the results should have an ID and a name, among other things
|
|
5
|
-
(result["id"] && result["name"]).should_not be_nil
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should get private data about a user" do
|
|
9
|
-
result = @api.get_object("koppel")
|
|
10
|
-
# updated_time should be a pretty fixed test case
|
|
11
|
-
result["updated_time"].should_not be_nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should get public data about a Page" do
|
|
15
|
-
result = @api.get_object("contextoptional")
|
|
16
|
-
# the results should have an ID and a name, among other things
|
|
17
|
-
(result["id"] && result["name"]).should
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should get data about 'me'" do
|
|
21
|
-
result = @api.get_object("me")
|
|
22
|
-
result["updated_time"].should
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should be able to get multiple objects" do
|
|
26
|
-
result = @api.get_objects(["contextoptional", "naitik"])
|
|
27
|
-
result.length.should == 2
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should be able to access a user's picture" do
|
|
31
|
-
@api.get_picture("chris.baclig").should =~ /http\:\/\//
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "should be able to access a user's picture, given a picture type" do
|
|
35
|
-
@api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should be able to access connections from users" do
|
|
39
|
-
result = @api.get_connections("lukeshepard", "likes")
|
|
40
|
-
result.length.should > 0
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should be able to access connections from public Pages" do
|
|
44
|
-
result = @api.get_connections("contextoptional", "photos")
|
|
45
|
-
result.should be_a(Array)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# paging
|
|
49
|
-
# see also graph_collection_tests
|
|
50
|
-
it "should make a request for a page when provided a specific set of page params" do
|
|
51
|
-
query = [1, 2]
|
|
52
|
-
@api.should_receive(:graph_call).with(*query)
|
|
53
|
-
@api.get_page(query)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# PUT
|
|
58
|
-
it "should be able to write an object to the graph" do
|
|
59
|
-
result = @api.put_wall_post("Hello, world, from the test suite!")
|
|
60
|
-
@temporary_object_id = result["id"]
|
|
61
|
-
@temporary_object_id.should_not be_nil
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# DELETE
|
|
65
|
-
it "should be able to delete posts" do
|
|
66
|
-
result = @api.put_wall_post("Hello, world, from the test suite delete method!")
|
|
67
|
-
object_id_to_delete = result["id"]
|
|
68
|
-
delete_result = @api.delete_object(object_id_to_delete)
|
|
69
|
-
delete_result.should == true
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# additional put tests
|
|
73
|
-
it "should be able to verify messages posted to a wall" do
|
|
74
|
-
message = "the cats are asleep"
|
|
75
|
-
put_result = @api.put_wall_post(message)
|
|
76
|
-
@temporary_object_id = put_result["id"]
|
|
77
|
-
get_result = @api.get_object(@temporary_object_id)
|
|
78
|
-
|
|
79
|
-
# make sure the message we sent is the message that got posted
|
|
80
|
-
get_result["message"].should == message
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "should be able to post a message with an attachment to a feed" do
|
|
84
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", {:name => "Context Optional", :link => "http://www.contextoptional.com/"})
|
|
85
|
-
@temporary_object_id = result["id"]
|
|
86
|
-
@temporary_object_id.should_not be_nil
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "should be able to verify a message with an attachment posted to a feed" do
|
|
90
|
-
attachment = {"name" => "Context Optional", "link" => "http://www.contextoptional.com/"}
|
|
91
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", attachment)
|
|
92
|
-
@temporary_object_id = result["id"]
|
|
93
|
-
get_result = @api.get_object(@temporary_object_id)
|
|
94
|
-
|
|
95
|
-
# make sure the result we fetch includes all the parameters we sent
|
|
96
|
-
it_matches = attachment.inject(true) {|valid, param| valid && (get_result[param[0]] == attachment[param[0]])}
|
|
97
|
-
it_matches.should == true
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "should be able to comment on an object" do
|
|
101
|
-
result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
|
|
102
|
-
@temporary_object_id = result["id"]
|
|
103
|
-
|
|
104
|
-
# this will be deleted when the post gets deleted
|
|
105
|
-
comment_result = @api.put_comment(@temporary_object_id, "it's my comment!")
|
|
106
|
-
comment_result.should_not be_nil
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "should be able to verify a comment posted about an object" do
|
|
110
|
-
message_text = "Hello, world, from the test suite, testing comments!"
|
|
111
|
-
result = @api.put_wall_post(message_text)
|
|
112
|
-
@temporary_object_id = result["id"]
|
|
113
|
-
|
|
114
|
-
# this will be deleted when the post gets deleted
|
|
115
|
-
comment_text = "it's my comment!"
|
|
116
|
-
comment_result = @api.put_comment(@temporary_object_id, comment_text)
|
|
117
|
-
get_result = @api.get_object(comment_result["id"])
|
|
118
|
-
|
|
119
|
-
# make sure the text of the comment matches what we sent
|
|
120
|
-
get_result["message"].should == comment_text
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "should be able to like an object" do
|
|
124
|
-
result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
|
|
125
|
-
@temporary_object_id = result["id"]
|
|
126
|
-
like_result = @api.put_like(@temporary_object_id)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# SEARCH
|
|
130
|
-
it "should be able to search" do
|
|
131
|
-
result = @api.search("facebook")
|
|
132
|
-
result.length.should be_an(Integer)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# API
|
|
136
|
-
# the above tests test this already, but we should consider additional api tests
|
|
137
|
-
|
|
138
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
class FacebookWithAccessTokenTests < Test::Unit::TestCase
|
|
142
|
-
describe "Koala GraphAPI with an access token" do
|
|
143
|
-
include LiveTestingDataHelper
|
|
144
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
|
145
|
-
|
|
146
|
-
before :each do
|
|
147
|
-
@api = Koala::Facebook::GraphAPI.new(@token)
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|