koala 1.0.0 → 1.1.0rc

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,6 +87,29 @@ shared_examples_for "Koala RestAPI" do
87
87
 
88
88
  @api.rest_call('anything', {}, options)
89
89
  end
90
+
91
+ it "uses get by default" do
92
+ @api.should_receive(:api).with(
93
+ anything,
94
+ anything,
95
+ "get",
96
+ anything
97
+ )
98
+
99
+ @api.rest_call('anything')
100
+ end
101
+
102
+ it "allows you to specify other http methods as the last argument" do
103
+ method = 'bar'
104
+ @api.should_receive(:api).with(
105
+ anything,
106
+ anything,
107
+ method,
108
+ anything
109
+ )
110
+
111
+ @api.rest_call('anything', {}, {}, method)
112
+ end
90
113
 
91
114
  it "should throw an APIError if the result hash has an error key" do
92
115
  Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error_code" => "An error occurred!"}, {}))
@@ -96,8 +119,7 @@ shared_examples_for "Koala RestAPI" do
96
119
  describe "when making a FQL request" do
97
120
  it "should call fql.query method" do
98
121
  @api.should_receive(:rest_call).with(
99
- "fql.query",
100
- anything
122
+ "fql.query", anything, anything
101
123
  ).and_return(Koala::Response.new(200, "2", {}))
102
124
 
103
125
  @api.fql_query stub('query string')
@@ -107,17 +129,78 @@ shared_examples_for "Koala RestAPI" do
107
129
  query = stub('query string')
108
130
 
109
131
  @api.should_receive(:rest_call).with(
110
- anything,
111
- hash_including("query" => query)
132
+ anything, hash_including(:query => query), anything
112
133
  )
113
134
 
114
135
  @api.fql_query(query)
115
136
  end
137
+
138
+ it "should pass on any other arguments provided" do
139
+ args = {:a => 2}
140
+ @api.should_receive(:rest_call).with(anything, hash_including(args), anything)
141
+ @api.fql_query("a query", args)
142
+ end
143
+
144
+ it "should pass on any http options provided" do
145
+ opts = {:a => 2}
146
+ @api.should_receive(:rest_call).with(anything, anything, hash_including(opts))
147
+ @api.fql_query("a query", {}, opts)
148
+ end
149
+ end
150
+
151
+ describe "when making a FQL-multiquery request" do
152
+ it "should call fql.multiquery method" do
153
+ @api.should_receive(:rest_call).with(
154
+ "fql.multiquery", anything, anything
155
+ ).and_return({})
156
+
157
+ @api.fql_multiquery stub('query string')
158
+ end
159
+
160
+ it "should pass a queries argument" do
161
+ queries = stub('query string')
162
+ queries_json = "some JSON"
163
+ queries.stub(:to_json).and_return(queries_json)
164
+
165
+ @api.should_receive(:rest_call).with(
166
+ anything,
167
+ hash_including(:queries => queries_json),
168
+ anything
169
+ )
170
+
171
+ @api.fql_multiquery(queries)
172
+ end
173
+
174
+ it "simplifies the response format" do
175
+ raw_results = [
176
+ {"name" => "query1", "fql_result_set" => [1, 2, 3]},
177
+ {"name" => "query2", "fql_result_set" => [:a, :b, :c]}
178
+ ]
179
+ expected_results = {
180
+ "query1" => [1, 2, 3],
181
+ "query2" => [:a, :b, :c]
182
+ }
183
+
184
+ @api.stub(:rest_call).and_return(raw_results)
185
+ results = @api.fql_multiquery({:query => true})
186
+ results.should == expected_results
187
+ end
188
+
189
+ it "should pass on any other arguments provided" do
190
+ args = {:a => 2}
191
+ @api.should_receive(:rest_call).with(anything, hash_including(args), anything)
192
+ @api.fql_multiquery("a query", args)
193
+ end
194
+
195
+ it "should pass on any http options provided" do
196
+ opts = {:a => 2}
197
+ @api.should_receive(:rest_call).with(anything, anything, hash_including(opts))
198
+ @api.fql_multiquery("a query", {}, opts)
199
+ end
116
200
  end
117
201
  end
118
202
  end
119
203
 
120
-
121
204
  shared_examples_for "Koala RestAPI with an access token" do
122
205
  # FQL
123
206
  it "should be able to access public information via FQL" do
@@ -126,6 +209,16 @@ shared_examples_for "Koala RestAPI with an access token" do
126
209
  result.first['first_name'].should == 'Chris'
127
210
  end
128
211
 
212
+ it "should be able to access public information via FQL.multiquery" do
213
+ result = @api.fql_multiquery(
214
+ :query1 => 'select first_name from user where uid = 216743',
215
+ :query2 => 'select first_name from user where uid = 2905623'
216
+ )
217
+ result.size.should == 2
218
+ result["query1"].first['first_name'].should == 'Chris'
219
+ result["query2"].first['first_name'].should == 'Alex'
220
+ end
221
+
129
222
  it "should be able to access protected information via FQL" do
130
223
  # Tests agains the permissions fql table
131
224
 
@@ -138,10 +231,21 @@ shared_examples_for "Koala RestAPI with an access token" do
138
231
  result = @api.fql_query("select read_stream from permissions where uid = #{id}")
139
232
 
140
233
  result.size.should == 1
141
- # we assume that you have read_stream permissions, so we can test against that
142
- # (should we keep this?)
234
+ # we've verified that you have read_stream permissions, so we can test against that
143
235
  result.first["read_stream"].should == 1
144
236
  end
237
+
238
+
239
+ it "should be able to access protected information via FQL.multiquery" do
240
+ result = @api.fql_multiquery(
241
+ :query1 => "select post_id from stream where source_id = me()",
242
+ :query2 => "select fromid from comment where post_id in (select post_id from #query1)",
243
+ :query3 => "select uid, name from user where uid in (select fromid from #query2)"
244
+ )
245
+ result.size.should == 3
246
+ result.keys.should include("query1", "query2", "query3")
247
+ end
248
+
145
249
  end
146
250
 
147
251
 
@@ -153,9 +257,29 @@ shared_examples_for "Koala RestAPI without an access token" do
153
257
  @result.size.should == 1
154
258
  @result.first["first_name"].should == "Chris"
155
259
  end
260
+
261
+ it "should be able to access public information via FQL.multiquery" do
262
+ result = @api.fql_multiquery(
263
+ :query1 => 'select first_name from user where uid = 216743',
264
+ :query2 => 'select first_name from user where uid = 2905623'
265
+ )
266
+ result.size.should == 2
267
+ result["query1"].first['first_name'].should == 'Chris'
268
+ result["query2"].first['first_name'].should == 'Alex'
269
+ end
156
270
 
157
271
  it "should not be able to access protected information via FQL" do
158
272
  lambda { @api.fql_query("select read_stream from permissions where uid = 216743") }.should raise_error(Koala::Facebook::APIError)
159
273
  end
274
+
275
+ it "should not be able to access protected information via FQL.multiquery" do
276
+ lambda {
277
+ @api.fql_multiquery(
278
+ :query1 => "select post_id from stream where source_id = me()",
279
+ :query2 => "select fromid from comment where post_id in (select post_id from #query1)",
280
+ :query3 => "select uid, name from user where uid in (select fromid from #query2)"
281
+ )
282
+ }.should raise_error(Koala::Facebook::APIError)
283
+ end
160
284
  end
161
285
  end
@@ -5,11 +5,11 @@ module KoalaTest
5
5
  # make sure we have the necessary permissions
6
6
  api = Koala::Facebook::GraphAndRestAPI.new(token)
7
7
  uid = api.get_object("me")["id"]
8
- perms = api.fql_query("select read_stream, publish_stream, user_photos from permissions where uid = #{uid}")[0]
8
+ perms = api.fql_query("select read_stream, publish_stream, user_photos, read_insights from permissions where uid = #{uid}")[0]
9
9
  perms.each_pair do |perm, value|
10
- unless value == 1
10
+ if value == (perm == "read_insights" ? 1 : 0) # live testing depends on insights calls failing
11
11
  puts "failed!\n" # put a new line after the print above
12
- raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions. You have: #{perms.inspect}"
12
+ raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions, and lack read_insights. You have: #{perms.inspect}"
13
13
  end
14
14
  end
15
15
  puts "done!"
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
4
+ hash: 7712002
5
+ prerelease: 5
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ - rc
11
+ version: 1.1.0rc
11
12
  platform: ruby
12
13
  authors:
13
14
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
@@ -15,10 +16,11 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-05-01 00:00:00 Z
19
+ date: 2011-06-06 00:00:00 +02:00
20
+ default_executable:
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
- prerelease: false
23
+ type: :runtime
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
23
25
  none: false
24
26
  requirements:
@@ -29,11 +31,11 @@ dependencies:
29
31
  - 1
30
32
  - 0
31
33
  version: "1.0"
32
- type: :runtime
33
- name: json
34
34
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
35
+ name: json
36
36
  prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ type: :runtime
37
39
  requirement: &id002 !ruby/object:Gem::Requirement
38
40
  none: false
39
41
  requirements:
@@ -44,27 +46,26 @@ dependencies:
44
46
  - 1
45
47
  - 0
46
48
  version: "1.0"
47
- type: :runtime
48
- name: multipart-post
49
49
  version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
50
+ name: multipart-post
51
51
  prerelease: false
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
52
54
  requirement: &id003 !ruby/object:Gem::Requirement
53
55
  none: false
54
56
  requirements:
55
57
  - - ~>
56
58
  - !ruby/object:Gem::Version
57
- hash: 27
59
+ hash: 9
58
60
  segments:
59
61
  - 2
60
62
  - 5
61
- - 0
62
- version: 2.5.0
63
- type: :development
64
- name: rspec
63
+ version: "2.5"
65
64
  version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
65
+ name: rspec
67
66
  prerelease: false
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
68
69
  requirement: &id004 !ruby/object:Gem::Requirement
69
70
  none: false
70
71
  requirements:
@@ -76,11 +77,11 @@ dependencies:
76
77
  - 8
77
78
  - 7
78
79
  version: 0.8.7
79
- type: :development
80
- name: rake
81
80
  version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
81
+ name: rake
83
82
  prerelease: false
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
84
85
  requirement: &id005 !ruby/object:Gem::Requirement
85
86
  none: false
86
87
  requirements:
@@ -92,9 +93,9 @@ dependencies:
92
93
  - 2
93
94
  - 4
94
95
  version: 0.2.4
95
- type: :development
96
- name: typhoeus
97
96
  version_requirements: *id005
97
+ name: typhoeus
98
+ prerelease: false
98
99
  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.
99
100
  email: alex@alexkoppel.com
100
101
  executables: []
@@ -105,16 +106,22 @@ extra_rdoc_files:
105
106
  - readme.md
106
107
  - CHANGELOG
107
108
  files:
109
+ - .autotest
108
110
  - .gitignore
109
111
  - CHANGELOG
110
112
  - Gemfile
111
113
  - LICENSE
112
114
  - Manifest
113
115
  - Rakefile
116
+ - autotest/discover.rb
114
117
  - koala.gemspec
115
118
  - lib/koala.rb
116
119
  - lib/koala/graph_api.rb
120
+ - lib/koala/graph_api_batch.rb
117
121
  - lib/koala/http_services.rb
122
+ - lib/koala/http_services/net_http_service.rb
123
+ - lib/koala/http_services/typhoeus_service.rb
124
+ - lib/koala/oauth.rb
118
125
  - lib/koala/realtime_updates.rb
119
126
  - lib/koala/rest_api.rb
120
127
  - lib/koala/test_users.rb
@@ -122,10 +129,12 @@ files:
122
129
  - readme.md
123
130
  - spec/cases/api_base_spec.rb
124
131
  - spec/cases/graph_and_rest_api_spec.rb
132
+ - spec/cases/graph_api_batch_spec.rb
125
133
  - spec/cases/graph_api_spec.rb
126
134
  - spec/cases/http_services/http_service_spec.rb
127
135
  - spec/cases/http_services/net_http_service_spec.rb
128
136
  - spec/cases/http_services/typhoeus_service_spec.rb
137
+ - spec/cases/koala_spec.rb
129
138
  - spec/cases/oauth_spec.rb
130
139
  - spec/cases/realtime_updates_spec.rb
131
140
  - spec/cases/rest_api_spec.rb
@@ -141,6 +150,7 @@ files:
141
150
  - spec/support/rest_api_shared_examples.rb
142
151
  - spec/support/setup_mocks_or_live.rb
143
152
  - spec/support/uploadable_io_shared_examples.rb
153
+ has_rdoc: true
144
154
  homepage: http://github.com/arsduo/koala
145
155
  licenses: []
146
156
 
@@ -174,17 +184,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
184
  requirements: []
175
185
 
176
186
  rubyforge_project:
177
- rubygems_version: 1.7.2
187
+ rubygems_version: 1.6.2
178
188
  signing_key:
179
189
  specification_version: 3
180
190
  summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.
181
191
  test_files:
182
192
  - spec/cases/api_base_spec.rb
183
193
  - spec/cases/graph_and_rest_api_spec.rb
194
+ - spec/cases/graph_api_batch_spec.rb
184
195
  - spec/cases/graph_api_spec.rb
185
196
  - spec/cases/http_services/http_service_spec.rb
186
197
  - spec/cases/http_services/net_http_service_spec.rb
187
198
  - spec/cases/http_services/typhoeus_service_spec.rb
199
+ - spec/cases/koala_spec.rb
188
200
  - spec/cases/oauth_spec.rb
189
201
  - spec/cases/realtime_updates_spec.rb
190
202
  - spec/cases/rest_api_spec.rb