koala 1.0.0.beta → 1.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.
- data/.autotest +12 -0
- data/.gitignore +5 -0
- data/.travis.yml +8 -0
- data/CHANGELOG +42 -4
- data/Gemfile +7 -0
- data/LICENSE +1 -1
- data/Manifest +5 -2
- data/Rakefile +13 -14
- data/autotest/discover.rb +1 -0
- data/koala.gemspec +35 -20
- data/lib/koala/batch_operation.rb +74 -0
- data/lib/koala/graph_api.rb +196 -143
- data/lib/koala/graph_batch_api.rb +87 -0
- data/lib/koala/graph_collection.rb +54 -0
- data/lib/koala/http_services/net_http_service.rb +92 -0
- data/lib/koala/http_services/typhoeus_service.rb +37 -0
- data/lib/koala/http_services.rb +15 -124
- data/lib/koala/oauth.rb +181 -0
- data/lib/koala/realtime_updates.rb +5 -14
- data/lib/koala/rest_api.rb +13 -8
- data/lib/koala/test_users.rb +21 -8
- data/lib/koala/uploadable_io.rb +175 -0
- data/lib/koala.rb +48 -240
- data/readme.md +60 -28
- 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_batch_spec.rb +609 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/cases/http_services/http_service_spec.rb +129 -0
- data/spec/cases/http_services/net_http_service_spec.rb +532 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +152 -0
- data/spec/cases/koala_spec.rb +55 -0
- data/spec/cases/oauth_spec.rb +409 -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} +47 -34
- data/spec/cases/uploadable_io_spec.rb +193 -0
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +12 -14
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +408 -306
- data/spec/spec_helper.rb +19 -0
- data/spec/support/graph_api_shared_examples.rb +495 -0
- data/spec/support/json_testing_fix.rb +18 -0
- data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
- data/spec/support/mock_http_service.rb +96 -0
- data/spec/support/rest_api_shared_examples.rb +285 -0
- data/spec/support/setup_mocks_or_live.rb +51 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +110 -64
- 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 -14
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -63
- data/spec/koala/graph_api/graph_api_tests.rb +0 -86
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -154
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/net_http_service_tests.rb +0 -430
- data/spec/koala/oauth/oauth_tests.rb +0 -409
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
- data/spec/koala/rest_api/rest_api_tests.rb +0 -118
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
- data/spec/koala/typhoeus_service_tests.rb +0 -156
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -70
- data/spec/koala_spec_without_mocks.rb +0 -19
- data/spec/mock_http_service.rb +0 -96
- /data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
metadata
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: koala
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
segments:
|
|
7
|
-
- 1
|
|
8
|
-
- 0
|
|
9
|
-
- 0
|
|
10
|
-
- beta
|
|
11
|
-
version: 1.0.0.beta
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 1.1.0
|
|
12
6
|
platform: ruby
|
|
13
7
|
authors:
|
|
14
8
|
- Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
|
|
@@ -16,91 +10,123 @@ autorequire:
|
|
|
16
10
|
bindir: bin
|
|
17
11
|
cert_chain: []
|
|
18
12
|
|
|
19
|
-
date: 2011-
|
|
13
|
+
date: 2011-07-18 00:00:00 +02:00
|
|
20
14
|
default_executable:
|
|
21
15
|
dependencies:
|
|
22
16
|
- !ruby/object:Gem::Dependency
|
|
23
|
-
name:
|
|
24
|
-
prerelease: false
|
|
17
|
+
name: multi_json
|
|
25
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
26
19
|
none: false
|
|
27
20
|
requirements:
|
|
28
|
-
- -
|
|
21
|
+
- - ~>
|
|
29
22
|
- !ruby/object:Gem::Version
|
|
30
|
-
hash: 15
|
|
31
|
-
segments:
|
|
32
|
-
- 1
|
|
33
|
-
- 0
|
|
34
23
|
version: "1.0"
|
|
35
24
|
type: :runtime
|
|
25
|
+
prerelease: false
|
|
36
26
|
version_requirements: *id001
|
|
37
27
|
- !ruby/object:Gem::Dependency
|
|
38
28
|
name: multipart-post
|
|
39
|
-
prerelease: false
|
|
40
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
30
|
none: false
|
|
42
31
|
requirements:
|
|
43
|
-
- -
|
|
32
|
+
- - ~>
|
|
44
33
|
- !ruby/object:Gem::Version
|
|
45
|
-
hash: 15
|
|
46
|
-
segments:
|
|
47
|
-
- 1
|
|
48
|
-
- 0
|
|
49
34
|
version: "1.0"
|
|
50
35
|
type: :runtime
|
|
36
|
+
prerelease: false
|
|
51
37
|
version_requirements: *id002
|
|
52
|
-
|
|
38
|
+
- !ruby/object:Gem::Dependency
|
|
39
|
+
name: rspec
|
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "2.5"
|
|
46
|
+
type: :development
|
|
47
|
+
prerelease: false
|
|
48
|
+
version_requirements: *id003
|
|
49
|
+
- !ruby/object:Gem::Dependency
|
|
50
|
+
name: rake
|
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
52
|
+
none: false
|
|
53
|
+
requirements:
|
|
54
|
+
- - ~>
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: 0.8.7
|
|
57
|
+
type: :development
|
|
58
|
+
prerelease: false
|
|
59
|
+
version_requirements: *id004
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: typhoeus
|
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
63
|
+
none: false
|
|
64
|
+
requirements:
|
|
65
|
+
- - ~>
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 0.2.4
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: *id005
|
|
71
|
+
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.
|
|
53
72
|
email: alex@alexkoppel.com
|
|
54
73
|
executables: []
|
|
55
74
|
|
|
56
75
|
extensions: []
|
|
57
76
|
|
|
58
77
|
extra_rdoc_files:
|
|
78
|
+
- readme.md
|
|
59
79
|
- CHANGELOG
|
|
60
|
-
- LICENSE
|
|
61
|
-
- lib/koala.rb
|
|
62
|
-
- lib/koala/graph_api.rb
|
|
63
|
-
- lib/koala/http_services.rb
|
|
64
|
-
- lib/koala/realtime_updates.rb
|
|
65
|
-
- lib/koala/rest_api.rb
|
|
66
|
-
- lib/koala/test_users.rb
|
|
67
80
|
files:
|
|
81
|
+
- .autotest
|
|
82
|
+
- .gitignore
|
|
83
|
+
- .travis.yml
|
|
68
84
|
- CHANGELOG
|
|
85
|
+
- Gemfile
|
|
69
86
|
- LICENSE
|
|
70
87
|
- Manifest
|
|
71
88
|
- Rakefile
|
|
72
|
-
-
|
|
89
|
+
- autotest/discover.rb
|
|
73
90
|
- koala.gemspec
|
|
74
91
|
- lib/koala.rb
|
|
92
|
+
- lib/koala/batch_operation.rb
|
|
75
93
|
- lib/koala/graph_api.rb
|
|
94
|
+
- lib/koala/graph_batch_api.rb
|
|
95
|
+
- lib/koala/graph_collection.rb
|
|
76
96
|
- lib/koala/http_services.rb
|
|
97
|
+
- lib/koala/http_services/net_http_service.rb
|
|
98
|
+
- lib/koala/http_services/typhoeus_service.rb
|
|
99
|
+
- lib/koala/oauth.rb
|
|
77
100
|
- lib/koala/realtime_updates.rb
|
|
78
101
|
- lib/koala/rest_api.rb
|
|
79
102
|
- lib/koala/test_users.rb
|
|
103
|
+
- lib/koala/uploadable_io.rb
|
|
80
104
|
- readme.md
|
|
81
|
-
- spec/
|
|
82
|
-
- spec/
|
|
83
|
-
- spec/
|
|
84
|
-
- spec/
|
|
85
|
-
- spec/
|
|
86
|
-
- spec/
|
|
87
|
-
- spec/
|
|
88
|
-
- spec/
|
|
89
|
-
- spec/
|
|
90
|
-
- spec/
|
|
91
|
-
- spec/
|
|
92
|
-
- spec/
|
|
93
|
-
- spec/
|
|
94
|
-
- spec/
|
|
95
|
-
- spec/
|
|
96
|
-
- spec/
|
|
97
|
-
- spec/
|
|
98
|
-
- spec/
|
|
99
|
-
- spec/
|
|
100
|
-
- spec/
|
|
101
|
-
- spec/
|
|
102
|
-
- spec/
|
|
103
|
-
- spec/
|
|
105
|
+
- spec/cases/api_base_spec.rb
|
|
106
|
+
- spec/cases/graph_and_rest_api_spec.rb
|
|
107
|
+
- spec/cases/graph_api_batch_spec.rb
|
|
108
|
+
- spec/cases/graph_api_spec.rb
|
|
109
|
+
- spec/cases/http_services/http_service_spec.rb
|
|
110
|
+
- spec/cases/http_services/net_http_service_spec.rb
|
|
111
|
+
- spec/cases/http_services/typhoeus_service_spec.rb
|
|
112
|
+
- spec/cases/koala_spec.rb
|
|
113
|
+
- spec/cases/oauth_spec.rb
|
|
114
|
+
- spec/cases/realtime_updates_spec.rb
|
|
115
|
+
- spec/cases/rest_api_spec.rb
|
|
116
|
+
- spec/cases/test_users_spec.rb
|
|
117
|
+
- spec/cases/uploadable_io_spec.rb
|
|
118
|
+
- spec/fixtures/beach.jpg
|
|
119
|
+
- spec/fixtures/cat.m4v
|
|
120
|
+
- spec/fixtures/facebook_data.yml
|
|
121
|
+
- spec/fixtures/mock_facebook_responses.yml
|
|
122
|
+
- spec/spec_helper.rb
|
|
123
|
+
- spec/support/graph_api_shared_examples.rb
|
|
124
|
+
- spec/support/json_testing_fix.rb
|
|
125
|
+
- spec/support/live_testing_data_helper.rb
|
|
126
|
+
- spec/support/mock_http_service.rb
|
|
127
|
+
- spec/support/rest_api_shared_examples.rb
|
|
128
|
+
- spec/support/setup_mocks_or_live.rb
|
|
129
|
+
- spec/support/uploadable_io_shared_examples.rb
|
|
104
130
|
has_rdoc: true
|
|
105
131
|
homepage: http://github.com/arsduo/koala
|
|
106
132
|
licenses: []
|
|
@@ -118,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
118
144
|
requirements:
|
|
119
145
|
- - ">="
|
|
120
146
|
- !ruby/object:Gem::Version
|
|
121
|
-
hash:
|
|
147
|
+
hash: -702788258280667645
|
|
122
148
|
segments:
|
|
123
149
|
- 0
|
|
124
150
|
version: "0"
|
|
@@ -127,17 +153,37 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
127
153
|
requirements:
|
|
128
154
|
- - ">="
|
|
129
155
|
- !ruby/object:Gem::Version
|
|
130
|
-
hash: 11
|
|
131
|
-
segments:
|
|
132
|
-
- 1
|
|
133
|
-
- 2
|
|
134
156
|
version: "1.2"
|
|
135
157
|
requirements: []
|
|
136
158
|
|
|
137
|
-
rubyforge_project:
|
|
138
|
-
rubygems_version: 1.
|
|
159
|
+
rubyforge_project:
|
|
160
|
+
rubygems_version: 1.6.2
|
|
139
161
|
signing_key:
|
|
140
162
|
specification_version: 3
|
|
141
|
-
summary: A lightweight, flexible library for Facebook with support for the Graph API, the
|
|
142
|
-
test_files:
|
|
143
|
-
|
|
163
|
+
summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.
|
|
164
|
+
test_files:
|
|
165
|
+
- spec/cases/api_base_spec.rb
|
|
166
|
+
- spec/cases/graph_and_rest_api_spec.rb
|
|
167
|
+
- spec/cases/graph_api_batch_spec.rb
|
|
168
|
+
- spec/cases/graph_api_spec.rb
|
|
169
|
+
- spec/cases/http_services/http_service_spec.rb
|
|
170
|
+
- spec/cases/http_services/net_http_service_spec.rb
|
|
171
|
+
- spec/cases/http_services/typhoeus_service_spec.rb
|
|
172
|
+
- spec/cases/koala_spec.rb
|
|
173
|
+
- spec/cases/oauth_spec.rb
|
|
174
|
+
- spec/cases/realtime_updates_spec.rb
|
|
175
|
+
- spec/cases/rest_api_spec.rb
|
|
176
|
+
- spec/cases/test_users_spec.rb
|
|
177
|
+
- spec/cases/uploadable_io_spec.rb
|
|
178
|
+
- spec/fixtures/beach.jpg
|
|
179
|
+
- spec/fixtures/cat.m4v
|
|
180
|
+
- spec/fixtures/facebook_data.yml
|
|
181
|
+
- spec/fixtures/mock_facebook_responses.yml
|
|
182
|
+
- spec/spec_helper.rb
|
|
183
|
+
- spec/support/graph_api_shared_examples.rb
|
|
184
|
+
- spec/support/json_testing_fix.rb
|
|
185
|
+
- spec/support/live_testing_data_helper.rb
|
|
186
|
+
- spec/support/mock_http_service.rb
|
|
187
|
+
- spec/support/rest_api_shared_examples.rb
|
|
188
|
+
- spec/support/setup_mocks_or_live.rb
|
|
189
|
+
- 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,14 +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"
|
|
8
|
-
it_should_behave_like "Koala RestAPI without an access token"
|
|
9
|
-
|
|
10
|
-
it_should_behave_like "Koala GraphAPI"
|
|
11
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
|
12
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
|
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
|
3
|
-
include LiveTestingDataHelper
|
|
4
|
-
|
|
5
|
-
before(:each) do
|
|
6
|
-
@api = Koala::Facebook::GraphAndRestAPI.new(@token)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it_should_behave_like "Koala RestAPI"
|
|
10
|
-
it_should_behave_like "Koala RestAPI with an access token"
|
|
11
|
-
|
|
12
|
-
it_should_behave_like "Koala GraphAPI"
|
|
13
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
|
14
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala GraphAPI without an access token" do
|
|
2
|
-
|
|
3
|
-
it "should not get private data about a user" do
|
|
4
|
-
result = @api.get_object("koppel")
|
|
5
|
-
# updated_time should be a pretty fixed test case
|
|
6
|
-
result["updated_time"].should be_nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "should not be able to get data about 'me'" do
|
|
10
|
-
lambda { @api.get_object("me") }.should raise_error(Koala::Facebook::APIError)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "shouldn't be able to access connections from users" do
|
|
14
|
-
lambda { @api.get_connections("lukeshepard", "likes") }.should raise_error(Koala::Facebook::APIError)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should not be able to put an object" do
|
|
18
|
-
lambda { @result = @api.put_object("lukeshepard", "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
|
|
19
|
-
puts "Error! Object #{@result.inspect} somehow put onto Luke Shepard's wall!" if @result
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# these are not strictly necessary as the other put methods resolve to put_object, but are here for completeness
|
|
23
|
-
it "should not be able to post to a feed" do
|
|
24
|
-
(lambda do
|
|
25
|
-
attachment = {:name => "Context Optional", :link => "http://www.contextoptional.com/"}
|
|
26
|
-
@result = @api.put_wall_post("Hello, world", attachment, "contextoptional")
|
|
27
|
-
end).should raise_error(Koala::Facebook::APIError)
|
|
28
|
-
puts "Error! Object #{@result.inspect} somehow put onto Context Optional's wall!" if @result
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should not be able to comment on an object" do
|
|
32
|
-
# random public post on the ContextOptional wall
|
|
33
|
-
lambda { @result = @api.put_comment("7204941866_119776748033392", "The hackathon was great!") }.should raise_error(Koala::Facebook::APIError)
|
|
34
|
-
puts "Error! Object #{@result.inspect} somehow commented on post 7204941866_119776748033392!" if @result
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should not be able to like an object" do
|
|
38
|
-
lambda { @api.put_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# DELETE
|
|
42
|
-
it "should not be able to delete posts" do
|
|
43
|
-
# test post on the Ruby SDK Test application
|
|
44
|
-
lambda { @result = @api.delete_object("115349521819193_113815981982767") }.should raise_error(Koala::Facebook::APIError)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "should not be able to delete a like" do
|
|
48
|
-
lambda { @api.delete_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
class FacebookNoAccessTokenTests < Test::Unit::TestCase
|
|
53
|
-
describe "Koala GraphAPI without an access token" do
|
|
54
|
-
before :each do
|
|
55
|
-
@api = Koala::Facebook::GraphAPI.new
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it_should_behave_like "Koala GraphAPI"
|
|
59
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
|
60
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala GraphAPI" do
|
|
2
|
-
# all Graph API instances should pass these tests, regardless of configuration
|
|
3
|
-
|
|
4
|
-
# API
|
|
5
|
-
it "should never use the rest api server" do
|
|
6
|
-
Koala.should_receive(:make_request).with(
|
|
7
|
-
anything,
|
|
8
|
-
anything,
|
|
9
|
-
anything,
|
|
10
|
-
hash_not_including(:rest_api => true)
|
|
11
|
-
).and_return(Koala::Response.new(200, "", {}))
|
|
12
|
-
|
|
13
|
-
@api.api("anything")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# GRAPH CALL
|
|
17
|
-
describe "graph_call" do
|
|
18
|
-
it "should pass all arguments to the api method" do
|
|
19
|
-
args = ["koppel", {}, "get", {:a => :b}]
|
|
20
|
-
|
|
21
|
-
@api.should_receive(:api).with(*args)
|
|
22
|
-
|
|
23
|
-
@api.graph_call(*args)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should throw an APIError if the result hash has an error key" do
|
|
27
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error" => "An error occurred!"}, {}))
|
|
28
|
-
lambda { @api.graph_call("koppel", {}) }.should raise_exception(Koala::Facebook::APIError)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# SEARCH
|
|
33
|
-
it "should be able to search" do
|
|
34
|
-
result = @api.search("facebook")
|
|
35
|
-
result.length.should be_an(Integer)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# DATA
|
|
39
|
-
# access public info
|
|
40
|
-
|
|
41
|
-
it "should get public data about a user" do
|
|
42
|
-
result = @api.get_object("koppel")
|
|
43
|
-
# the results should have an ID and a name, among other things
|
|
44
|
-
(result["id"] && result["name"]).should_not be_nil
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "should get public data about a Page" do
|
|
48
|
-
result = @api.get_object("contextoptional")
|
|
49
|
-
# the results should have an ID and a name, among other things
|
|
50
|
-
(result["id"] && result["name"]).should
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "should be able to get multiple objects" do
|
|
54
|
-
results = @api.get_objects(["contextoptional", "naitik"])
|
|
55
|
-
results.length.should == 2
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should be able to access a user's picture" do
|
|
59
|
-
@api.get_picture("chris.baclig").should =~ /http\:\/\//
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "should be able to access a user's picture, given a picture type" do
|
|
63
|
-
@api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "should be able to access connections from public Pages" do
|
|
67
|
-
result = @api.get_connections("contextoptional", "photos")
|
|
68
|
-
result.should be_a(Array)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# SEARCH
|
|
72
|
-
it "should be able to search" do
|
|
73
|
-
result = @api.search("facebook")
|
|
74
|
-
result.length.should be_an(Integer)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# PAGING THROUGH COLLECTIONS
|
|
78
|
-
# see also graph_collection_tests
|
|
79
|
-
it "should make a request for a page when provided a specific set of page params" do
|
|
80
|
-
query = [1, 2]
|
|
81
|
-
@api.should_receive(:graph_call).with(*query)
|
|
82
|
-
@api.get_page(query)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
end
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
shared_examples_for "Koala GraphAPI with an access token" do
|
|
2
|
-
|
|
3
|
-
it "should get private data about a user" do
|
|
4
|
-
result = @api.get_object("koppel")
|
|
5
|
-
# updated_time should be a pretty fixed test case
|
|
6
|
-
result["updated_time"].should_not be_nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "should get data about 'me'" do
|
|
10
|
-
result = @api.get_object("me")
|
|
11
|
-
result["updated_time"].should
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should be able to get multiple objects" do
|
|
15
|
-
result = @api.get_objects(["contextoptional", "naitik"])
|
|
16
|
-
result.length.should == 2
|
|
17
|
-
end
|
|
18
|
-
it "should be able to access connections from users" do
|
|
19
|
-
result = @api.get_connections("lukeshepard", "likes")
|
|
20
|
-
result.length.should > 0
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# PUT
|
|
24
|
-
it "should be able to write an object to the graph" do
|
|
25
|
-
result = @api.put_wall_post("Hello, world, from the test suite!")
|
|
26
|
-
@temporary_object_id = result["id"]
|
|
27
|
-
@temporary_object_id.should_not be_nil
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# DELETE
|
|
31
|
-
it "should be able to delete posts" do
|
|
32
|
-
result = @api.put_wall_post("Hello, world, from the test suite delete method!")
|
|
33
|
-
object_id_to_delete = result["id"]
|
|
34
|
-
delete_result = @api.delete_object(object_id_to_delete)
|
|
35
|
-
delete_result.should == true
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should be able to delete likes" do
|
|
39
|
-
result = @api.put_wall_post("Hello, world, from the test suite delete method!")
|
|
40
|
-
@temporary_object_id = result["id"]
|
|
41
|
-
@api.put_like(@temporary_object_id)
|
|
42
|
-
delete_like_result = @api.delete_like(@temporary_object_id)
|
|
43
|
-
delete_like_result.should == true
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# additional put tests
|
|
47
|
-
it "should be able to verify messages posted to a wall" do
|
|
48
|
-
message = "the cats are asleep"
|
|
49
|
-
put_result = @api.put_wall_post(message)
|
|
50
|
-
@temporary_object_id = put_result["id"]
|
|
51
|
-
get_result = @api.get_object(@temporary_object_id)
|
|
52
|
-
|
|
53
|
-
# make sure the message we sent is the message that got posted
|
|
54
|
-
get_result["message"].should == message
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "should be able to post a message with an attachment to a feed" do
|
|
58
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", {:name => "Context Optional", :link => "http://www.contextoptional.com/"})
|
|
59
|
-
@temporary_object_id = result["id"]
|
|
60
|
-
@temporary_object_id.should_not be_nil
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "should be able to post photos to the user's wall with an open file object" do
|
|
64
|
-
file_hash = {
|
|
65
|
-
"content_type" => "image/jpg",
|
|
66
|
-
"path" => File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg"),
|
|
67
|
-
"file" => File.open(File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg"))
|
|
68
|
-
}
|
|
69
|
-
result = @api.put_picture(file_hash)
|
|
70
|
-
@temporary_object_id = result["id"]
|
|
71
|
-
@temporary_object_id.should_not be_nil
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should be able to post photos to the user's wall without an open file object" do
|
|
75
|
-
file_hash = {
|
|
76
|
-
"content_type" => "image/jpg",
|
|
77
|
-
"path" => File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg")
|
|
78
|
-
}
|
|
79
|
-
result = @api.put_picture(file_hash)
|
|
80
|
-
@temporary_object_id = result["id"]
|
|
81
|
-
@temporary_object_id.should_not be_nil
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "should be able to verify a photo posted to a user's wall" do
|
|
85
|
-
file_hash = {
|
|
86
|
-
"content_type" => "image/jpg",
|
|
87
|
-
"path" => File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg")
|
|
88
|
-
}
|
|
89
|
-
expected_message = "This is the test message"
|
|
90
|
-
|
|
91
|
-
result = @api.put_picture(file_hash, :message => expected_message)
|
|
92
|
-
@temporary_object_id = result["id"]
|
|
93
|
-
@temporary_object_id.should_not be_nil
|
|
94
|
-
|
|
95
|
-
get_result = @api.get_object(@temporary_object_id)
|
|
96
|
-
get_result["name"].should == expected_message
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should be able to verify a message with an attachment posted to a feed" do
|
|
100
|
-
attachment = {"name" => "Context Optional", "link" => "http://www.contextoptional.com/"}
|
|
101
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", attachment)
|
|
102
|
-
@temporary_object_id = result["id"]
|
|
103
|
-
get_result = @api.get_object(@temporary_object_id)
|
|
104
|
-
|
|
105
|
-
# make sure the result we fetch includes all the parameters we sent
|
|
106
|
-
it_matches = attachment.inject(true) {|valid, param| valid && (get_result[param[0]] == attachment[param[0]])}
|
|
107
|
-
it_matches.should == true
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "should be able to comment on an object" do
|
|
111
|
-
result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
|
|
112
|
-
@temporary_object_id = result["id"]
|
|
113
|
-
|
|
114
|
-
# this will be deleted when the post gets deleted
|
|
115
|
-
comment_result = @api.put_comment(@temporary_object_id, "it's my comment!")
|
|
116
|
-
comment_result.should_not be_nil
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "should be able to verify a comment posted about an object" do
|
|
120
|
-
message_text = "Hello, world, from the test suite, testing comments!"
|
|
121
|
-
result = @api.put_wall_post(message_text)
|
|
122
|
-
@temporary_object_id = result["id"]
|
|
123
|
-
|
|
124
|
-
# this will be deleted when the post gets deleted
|
|
125
|
-
comment_text = "it's my comment!"
|
|
126
|
-
comment_result = @api.put_comment(@temporary_object_id, comment_text)
|
|
127
|
-
get_result = @api.get_object(comment_result["id"])
|
|
128
|
-
|
|
129
|
-
# make sure the text of the comment matches what we sent
|
|
130
|
-
get_result["message"].should == comment_text
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it "should be able to like an object" do
|
|
134
|
-
result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
|
|
135
|
-
@temporary_object_id = result["id"]
|
|
136
|
-
like_result = @api.put_like(@temporary_object_id)
|
|
137
|
-
like_result.should be_true
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
class FacebookWithAccessTokenTests < Test::Unit::TestCase
|
|
142
|
-
describe "Koala GraphAPI with an access token" do
|
|
143
|
-
include LiveTestingDataHelper
|
|
144
|
-
|
|
145
|
-
before :each do
|
|
146
|
-
@api = Koala::Facebook::GraphAPI.new(@token)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it_should_behave_like "Koala GraphAPI"
|
|
150
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
|
151
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
|
152
|
-
|
|
153
|
-
end
|
|
154
|
-
end
|