koala 1.9.0 → 1.10.0rc

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fce15c756d8195dd27bfff27a1dfb8d22c7c17d9
4
- data.tar.gz: 3544dc9c1b0ef86ca8ef8282201c5249847ce33d
3
+ metadata.gz: 25a25033e35b0e687e7bb6031e32927ff5874841
4
+ data.tar.gz: ffd9a57bdb9e2ecc42c28fee1747d13ee8bb277f
5
5
  SHA512:
6
- metadata.gz: 6936a245c607107f259c0c91ec29684e14a5eab681435773b57b8135caeb52890cf8023072954122c884a6d01b44ef2eb78f8f6a8b014624a315963d42a425aa
7
- data.tar.gz: 6fe435caee7dbec526eafc7309e6490af6906f3627cebb9e3510321dc067caba639ade215762a804922d2e0f02ba2bc112110ece5a442be230b3b01a81f98ab4
6
+ metadata.gz: 2f72aa59b3f6b967e5b2aa9501827e1a8cdb0e4a392063a00b806d5cad43e37086797c1fe69d0da59ede5c4a963650c238ee54fdf26401902ca586f8214f7214
7
+ data.tar.gz: cdb59b3cf357b2ef6d99e6106582899f9bff5db23d04bbdef46d29eea09274b0e1ba2ffc60cac25d5f157f3f18045be6f95885e8241351f8db3016113146a9f7
data/.travis.yml CHANGED
@@ -4,8 +4,7 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.0
6
6
  # rbx
7
- - rbx-2.1.1
8
- - rbx
7
+ - rbx-2
9
8
  # jruby
10
9
  - jruby-19mode
11
10
  bundler_args: --without development
data/Gemfile CHANGED
@@ -16,10 +16,4 @@ end
16
16
 
17
17
  gem "jruby-openssl" if defined? JRUBY_VERSION
18
18
 
19
- platforms :rbx do
20
- gem 'rubysl', '~> 2.0' # if using anything in the ruby standard library
21
- gem 'psych' # if using yaml
22
- gem 'rubinius-developer_tools' # if using any of coverage, debugger, profiler
23
- end
24
-
25
19
  gemspec
data/changelog.md CHANGED
@@ -1,3 +1,20 @@
1
+ v.1.10.0
2
+ ========
3
+
4
+ New features:
5
+ * API versioning is now supported through global and per-options requests
6
+ (Koala.config.api_version and the :api_version key specified as a per-request
7
+ options)
8
+
9
+ Updated features:
10
+ * API calls won't modify argument hashes in place anymore (thanks, MSex!)
11
+
12
+ Testing improvements:
13
+ * Use the modern RSpec syntax (thanks, loganhasson!)
14
+
15
+ Documentation improvements:
16
+ * Properly document the timeout option (thanks, bachand!)
17
+
1
18
  v1.9.0
2
19
  ======
3
20
 
data/lib/koala.rb CHANGED
@@ -35,6 +35,13 @@ module Koala
35
35
  yield config
36
36
  end
37
37
 
38
+ # Allows you to control various Koala configuration options.
39
+ # Notable options:
40
+ # * server endpoints: you can override any or all the server endpoints
41
+ # (see HTTPService::DEFAULT_SERVERS) if you want to run requests through
42
+ # other servers.
43
+ # * api_version: controls which Facebook API version to use (v1.0, v2.0,
44
+ # etc)
38
45
  def config
39
46
  @config ||= OpenStruct.new(HTTPService::DEFAULT_SERVERS)
40
47
  end
data/lib/koala/api.rb CHANGED
@@ -48,6 +48,10 @@ module Koala
48
48
  #
49
49
  # @return the body of the response from Facebook (unless another http_component is requested)
50
50
  def api(path, args = {}, verb = "get", options = {}, &error_checking_block)
51
+ # we make a copy of args so the modifications (added access_token & appsecret_proof)
52
+ # do not affect the received argument
53
+ args = args.dup
54
+
51
55
  # If a access token is explicitly provided, use that
52
56
  # This is explicitly needed in batch requests so GraphCollection
53
57
  # results preserve any specific access tokens provided
@@ -59,8 +63,12 @@ module Koala
59
63
  # Translate any arrays in the params into comma-separated strings
60
64
  args = sanitize_request_parameters(args)
61
65
 
62
- # add a leading /
66
+ # add a leading / if needed...
63
67
  path = "/#{path}" unless path =~ /^\//
68
+ # ...and an API version if specified
69
+ if api_version = options[:api_version] || Koala.config.api_version
70
+ path = "/#{api_version}#{path}"
71
+ end
64
72
 
65
73
  # make the request via the provided service
66
74
  result = Koala.make_request(path, args, verb, options)
data/lib/koala/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Koala
2
- VERSION = "1.9.0"
2
+ VERSION = "1.10.0rc"
3
3
  end
data/readme.md CHANGED
@@ -1,10 +1,5 @@
1
1
  [![Build Status](https://secure.travis-ci.org/arsduo/koala.png)](http://travis-ci.org/arsduo/koala)
2
2
 
3
- **Note**: a recent Facebook change will cause apps that parse the cookies every
4
- request to fail with the error "OAuthException: This authorization code has
5
- been used." If you're seeing this, please read the note in the [OAuth
6
- wiki](https://github.com/arsduo/koala/wiki/OAuth) for more information.
7
-
8
3
  Koala
9
4
  ====
10
5
  [Koala](http://github.com/arsduo/koala) is a Facebook library for Ruby, supporting the Graph API (including the batch requests and photo uploads), the REST API, realtime updates, test users, and OAuth validation. We wrote Koala with four goals:
@@ -19,7 +14,7 @@ Installation
19
14
 
20
15
  In Bundler:
21
16
  ```ruby
22
- gem "koala", "~> 1.8.0rc1"
17
+ gem "koala", "~> 1.9.0"
23
18
  ```
24
19
 
25
20
  Otherwise:
@@ -28,7 +23,8 @@ Otherwise:
28
23
  ```
29
24
 
30
25
  Graph API
31
- ----
26
+ ---------
27
+
32
28
  The Graph API is the simple, slick new interface to Facebook's data.
33
29
  Using it with Koala is quite straightforward. First, you'll need an access token, which you can get through
34
30
  Facebook's [Graph API Explorer](https://developers.facebook.com/tools/explorer) (click on 'Get Access Token').
@@ -54,6 +50,16 @@ friends = @graph.get_connections("me", "friends")
54
50
  # You'll need to turn on 'Require proof on all calls' in the advanced section
55
51
  # of your app's settings when doing this.
56
52
  @graph = Koala::Facebook::API.new(oauth_access_token, app_secret)
53
+
54
+ # Facebook is now versioning their API. You can specify version either
55
+ globally:
56
+ Koala.config.api_version = "v2.0"
57
+ # or on a per-request basis
58
+ @graph.get_object("me", {}, api_version: "v2.0")
59
+ # If you don't specify a version, Facebook will default to the oldest version
60
+ # your app is allowed to use. Note that apps created after f8 2014 *cannot* use
61
+ # the v1.0 API. See https://developers.facebook.com/docs/apps/versions for more
62
+ # information.
57
63
  ```
58
64
 
59
65
  The response of most requests is the JSON data returned from the Facebook servers as a Hash.
@@ -224,7 +230,7 @@ Koala.http_service.http_options = {
224
230
  :ssl => { :ca_path => "/etc/ssl/certs" }
225
231
  }
226
232
  # or on a per-request basis
227
- @api.get_object(id, args_hash, { :timeout => 10 })
233
+ @api.get_object(id, args_hash, { :request => { :timeout => 10 } })
228
234
  ```
229
235
  The <a href="https://github.com/arsduo/koala/wiki/HTTP-Services">HTTP Services wiki page</a> has more information on what options are available, as well as on how to configure your own Faraday middleware stack (for instance, to implement request logging).
230
236
 
@@ -30,6 +30,21 @@ describe "Koala::Facebook::API" do
30
30
  service.api('anything')
31
31
  end
32
32
 
33
+ it "doesn't add token to received arguments" do
34
+ token = 'adfadf'
35
+ service = Koala::Facebook::API.new token
36
+
37
+ expect(Koala).to receive(:make_request).with(
38
+ anything,
39
+ hash_including('access_token' => token),
40
+ anything,
41
+ anything
42
+ ).and_return(Koala::HTTPService::Response.new(200, "", ""))
43
+
44
+ args = {}.freeze
45
+ service.api('anything', args)
46
+ end
47
+
33
48
  it "has an attr_reader for access token" do
34
49
  token = 'adfadf'
35
50
  service = Koala::Facebook::API.new token
@@ -117,17 +132,56 @@ describe "Koala::Facebook::API" do
117
132
  expect(@service.api('anything')).to be_falsey
118
133
  end
119
134
 
120
- describe "with regard to leading slashes" do
121
- it "adds a leading / to the path if not present" do
122
- path = "anything"
123
- expect(Koala).to receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
124
- @service.api(path)
135
+ describe "path manipulation" do
136
+ context "leading /" do
137
+ it "adds a leading / to the path if not present" do
138
+ path = "anything"
139
+ expect(Koala).to receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
140
+ @service.api(path)
141
+ end
142
+
143
+ it "doesn't change the path if a leading / is present" do
144
+ path = "/anything"
145
+ expect(Koala).to receive(:make_request).with(path, anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
146
+ @service.api(path)
147
+ end
125
148
  end
126
149
 
127
- it "doesn't change the path if a leading / is present" do
128
- path = "/anything"
129
- expect(Koala).to receive(:make_request).with(path, anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
130
- @service.api(path)
150
+ context "API versions" do
151
+ let(:path) { "/anything" }
152
+
153
+ it "adds a version if specified by Koala.config" do
154
+ Koala.config.api_version = "v1000.000"
155
+ expect(Koala).to receive(:make_request).with(
156
+ "/#{Koala.config.api_version}#{path}",
157
+ anything,
158
+ anything,
159
+ anything
160
+ ).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
161
+ @service.api(path)
162
+ end
163
+
164
+ it "prefers a version set in the options" do
165
+ Koala.config.api_version = "v1000.000"
166
+ version = "v2.0"
167
+ expect(Koala).to receive(:make_request).with(
168
+ "/#{version}#{path}",
169
+ anything,
170
+ anything,
171
+ anything
172
+ ).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
173
+ @service.api(path, {}, "get", api_version: "v2.0")
174
+ end
175
+
176
+ it "doesn't include a version if not specified" do
177
+ expect(Koala).to receive(:make_request).with(
178
+ path,
179
+ anything,
180
+ anything,
181
+ anything
182
+ ).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
183
+ @service.api(path)
184
+ end
131
185
  end
132
186
  end
133
187
 
@@ -173,14 +227,14 @@ describe "Koala::Facebook::API" do
173
227
  let(:api) { Koala::Facebook::API.new(access_token, appsecret) }
174
228
 
175
229
  it "will be included by default" do
176
- Koala.should_receive(:make_request).with(path, token_args.merge(appsecret_proof_args), verb, {}).and_return(response)
230
+ expect(Koala).to receive(:make_request).with(path, token_args.merge(appsecret_proof_args), verb, {}).and_return(response)
177
231
  api.api(path, {}, verb, :appsecret_proof => true)
178
232
  end
179
233
  end
180
234
 
181
235
  describe "but without an appsecret included on API initialization" do
182
236
  it "will not be included" do
183
- Koala.should_receive(:make_request).with(path, token_args, verb, {}).and_return(response)
237
+ expect(Koala).to receive(:make_request).with(path, token_args, verb, {}).and_return(response)
184
238
  api.api(path, {}, verb, :appsecret_proof => true)
185
239
  end
186
240
  end
@@ -191,7 +245,7 @@ describe "Koala::Facebook::API" do
191
245
  let(:api) { Koala::Facebook::API.new(nil, appsecret) }
192
246
 
193
247
  it "will not be included" do
194
- Koala.should_receive(:make_request).with(path, {}, verb, {}).and_return(response)
248
+ expect(Koala).to receive(:make_request).with(path, {}, verb, {}).and_return(response)
195
249
  api.api(path, {}, verb, :appsecret_proof => true)
196
250
  end
197
251
  end
@@ -200,7 +254,7 @@ describe "Koala::Facebook::API" do
200
254
  let(:api) { Koala::Facebook::API.new }
201
255
 
202
256
  it "will not be included" do
203
- Koala.should_receive(:make_request).with(path, {}, verb, {}).and_return(response)
257
+ expect(Koala).to receive(:make_request).with(path, {}, verb, {}).and_return(response)
204
258
  api.api(path, {}, verb, :appsecret_proof => true)
205
259
  end
206
260
  end
@@ -20,6 +20,12 @@ describe 'Koala::Facebook::GraphAPIMethods' do
20
20
  allow(@api).to receive(:api).and_return(double("other results"))
21
21
  expect(@api.get_object('koppel', &post_processing)["result"]).to eq(result)
22
22
  end
23
+
24
+ it "doesn't add token to received arguments" do
25
+ args = {}.freeze
26
+ expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, "", ""))
27
+ expect(@api.get_object('koppel', args, &post_processing)["result"]).to eq(result)
28
+ end
23
29
  end
24
30
 
25
31
  context '#get_picture' do
@@ -299,7 +299,7 @@ describe "Koala::Facebook::TestUsers" do
299
299
 
300
300
  if KoalaTest.mock_interface?
301
301
  id_counter = 999999900
302
- allow(@test_users).to receive(:create).and_return do
302
+ allow(@test_users).to receive(:create) do
303
303
  id_counter += 1
304
304
  {"id" => id_counter, "access_token" => @token, "login_url" => "https://www.facebook.com/platform/test_account.."}
305
305
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Koppel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-08 00:00:00.000000000 Z
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -140,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - ">"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: 1.3.1
146
146
  requirements: []
147
147
  rubyforge_project:
148
148
  rubygems_version: 2.2.1