koala 1.10.0rc → 1.10.0rc2

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: 25a25033e35b0e687e7bb6031e32927ff5874841
4
- data.tar.gz: ffd9a57bdb9e2ecc42c28fee1747d13ee8bb277f
3
+ metadata.gz: b13d1518c051e76b003501281c71fdad6bcf3aad
4
+ data.tar.gz: 33d572064130127326b8e6ade6381bbb6a22fec4
5
5
  SHA512:
6
- metadata.gz: 2f72aa59b3f6b967e5b2aa9501827e1a8cdb0e4a392063a00b806d5cad43e37086797c1fe69d0da59ede5c4a963650c238ee54fdf26401902ca586f8214f7214
7
- data.tar.gz: cdb59b3cf357b2ef6d99e6106582899f9bff5db23d04bbdef46d29eea09274b0e1ba2ffc60cac25d5f157f3f18045be6f95885e8241351f8db3016113146a9f7
6
+ metadata.gz: 7e0df1d828fc7fdcbae60923971f06c515b6e0e1811308fcb2a20085c6f3703d2c13e70e5215b9fecb05b5cf0f95a41429ed479d45530198613163ee61111561
7
+ data.tar.gz: 716418c731ab9ca3e7ed87427b82142024f8762914d34c64cc12d9e9ef9ad988a29fe071ac602fa41c6a98515de2a3b580d8faceab710874f60528cce7b8d939
data/changelog.md CHANGED
@@ -8,12 +8,14 @@ New features:
8
8
 
9
9
  Updated features:
10
10
  * API calls won't modify argument hashes in place anymore (thanks, MSex!)
11
+ * OAuth#dialog_url now uses https rather than http
11
12
 
12
13
  Testing improvements:
13
14
  * Use the modern RSpec syntax (thanks, loganhasson!)
14
15
 
15
16
  Documentation improvements:
16
17
  * Properly document the timeout option (thanks, bachand!)
18
+ * The gemspec now includes the license (thanks, coreyhaines!)
17
19
 
18
20
  v1.9.0
19
21
  ======
data/koala.gemspec CHANGED
@@ -6,6 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.name = "koala"
7
7
  gem.summary = "A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication."
8
8
  gem.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."
9
+ gem.licenses = ['MIT']
9
10
  gem.homepage = "http://github.com/arsduo/koala"
10
11
  gem.version = Koala::VERSION
11
12
 
data/lib/koala/api.rb CHANGED
@@ -65,10 +65,6 @@ module Koala
65
65
 
66
66
  # add a leading / if needed...
67
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
72
68
 
73
69
  # make the request via the provided service
74
70
  result = Koala.make_request(path, args, verb, options)
@@ -47,12 +47,17 @@ module Koala
47
47
  # @option options :video use the server designated for video uploads
48
48
  # @option options :beta use the beta tier
49
49
  # @option options :use_ssl force https, even if not needed
50
+ # @option options :api_version a version of the Facebook API, e.g. v2.0
50
51
  #
51
52
  # @return a complete server address with protocol
52
53
  def self.server(options = {})
53
54
  server = "#{options[:rest_api] ? Koala.config.rest_server : Koala.config.graph_server}"
54
55
  server.gsub!(Koala.config.host_path_matcher, Koala.config.video_replace) if options[:video]
55
56
  server.gsub!(Koala.config.host_path_matcher, Koala.config.beta_replace) if options[:beta]
57
+ # ...and an API version if specified
58
+ if api_version = options[:api_version] || Koala.config.api_version
59
+ server = "#{server}/#{api_version}"
60
+ end
56
61
  "#{options[:use_ssl] ? "https" : "http"}://#{server}"
57
62
  end
58
63
 
data/lib/koala/oauth.rb CHANGED
@@ -90,7 +90,7 @@ module Koala
90
90
  url_options = {:client_id => @app_id}.merge(options)
91
91
 
92
92
  # Creates the URL for oauth authorization for a given callback and optional set of permissions
93
- build_url("https://#{Koala.config.dialog_host}/dialog/oauth", true, url_options)
93
+ build_url(:dialog_host, "/dialog/oauth", true, url_options)
94
94
  end
95
95
 
96
96
  # Once you receive an OAuth code, you need to redeem it from Facebook using an appropriate URL.
@@ -114,7 +114,7 @@ module Koala
114
114
  :code => code,
115
115
  :client_secret => @app_secret
116
116
  }.merge(options)
117
- build_url("https://#{Koala.config.graph_server}/oauth/access_token", true, url_options)
117
+ build_url(:graph_server, "/oauth/access_token", true, url_options)
118
118
  end
119
119
 
120
120
  # Builds a URL for a given dialog (feed, friends, OAuth, pay, send, etc.)
@@ -129,7 +129,7 @@ module Koala
129
129
  def url_for_dialog(dialog_type, options = {})
130
130
  # some endpoints require app_id, some client_id, supply both doesn't seem to hurt
131
131
  url_options = {:app_id => @app_id, :client_id => @app_id}.merge(options)
132
- build_url("http://#{Koala.config.dialog_host}/dialog/#{dialog_type}", true, url_options)
132
+ build_url(:dialog_host, "/dialog/#{dialog_type}", true, url_options)
133
133
  end
134
134
 
135
135
  # Generates a 'client code' from a server side long-lived access token. With the generated
@@ -376,12 +376,21 @@ module Koala
376
376
  Base64.decode64(str.tr('-_', '+/'))
377
377
  end
378
378
 
379
- def build_url(base, require_redirect_uri = false, url_options = {})
379
+ def server_url(type)
380
+ url = "https://#{Koala.config.send(type)}"
381
+ if version = Koala.config.api_version
382
+ "#{url}/#{version}"
383
+ else
384
+ url
385
+ end
386
+ end
387
+
388
+ def build_url(type, path, require_redirect_uri = false, url_options = {})
380
389
  if require_redirect_uri && !(url_options[:redirect_uri] ||= url_options.delete(:callback) || @oauth_callback_url)
381
390
  raise ArgumentError, "build_url must get a callback either from the OAuth object or in the parameters!"
382
391
  end
383
-
384
- "#{base}?#{Koala::HTTPService.encode_params(url_options)}"
392
+ params = Koala::HTTPService.encode_params(url_options)
393
+ "#{server_url(type)}#{path}?#{params}"
385
394
  end
386
395
  end
387
396
  end
data/lib/koala/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Koala
2
- VERSION = "1.10.0rc"
2
+ VERSION = "1.10.0rc2"
3
3
  end
data/readme.md CHANGED
@@ -14,7 +14,7 @@ Installation
14
14
 
15
15
  In Bundler:
16
16
  ```ruby
17
- gem "koala", "~> 1.9.0"
17
+ gem "koala", "~> 1.10.0rc"
18
18
  ```
19
19
 
20
20
  Otherwise:
@@ -51,15 +51,15 @@ friends = @graph.get_connections("me", "friends")
51
51
  # of your app's settings when doing this.
52
52
  @graph = Koala::Facebook::API.new(oauth_access_token, app_secret)
53
53
 
54
- # Facebook is now versioning their API. You can specify version either
55
- globally:
54
+ # Facebook is now versioning their API. # If you don't specify a version, Facebook
55
+ # will default to the oldest version your app is allowed to use. Note that apps
56
+ # created after f8 2014 *cannot* use the v1.0 API. See
57
+ # https://developers.facebook.com/docs/apps/versions for more information.
58
+ #
59
+ # You can specify version either globally:
56
60
  Koala.config.api_version = "v2.0"
57
61
  # or on a per-request basis
58
62
  @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.
63
63
  ```
64
64
 
65
65
  The response of most requests is the JSON data returned from the Facebook servers as a Hash.
@@ -146,43 +146,6 @@ describe "Koala::Facebook::API" do
146
146
  @service.api(path)
147
147
  end
148
148
  end
149
-
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
185
- end
186
149
  end
187
150
 
188
151
  describe "with an access token" do
@@ -76,12 +76,26 @@ describe Koala::HTTPService do
76
76
  describe "server" do
77
77
  describe "with no options" do
78
78
  it "returns the REST server if options[:rest_api]" do
79
- expect(Koala::HTTPService.server(:rest_api => true)).to match(Regexp.new(Koala.config.rest_server))
79
+ expect(Koala::HTTPService.server(:rest_api => true)).to eq(
80
+ "http://#{Koala.config.rest_server}"
81
+ )
80
82
  end
81
83
 
82
84
  it "returns the graph server if !options[:rest_api]" do
83
- expect(Koala::HTTPService.server(:rest_api => false)).to match(Regexp.new(Koala.config.graph_server))
84
- expect(Koala::HTTPService.server({})).to match(Regexp.new(Koala.config.graph_server))
85
+ expect(Koala::HTTPService.server(:rest_api => false)).to eq(
86
+ "http://#{Koala.config.graph_server}"
87
+ )
88
+ expect(Koala::HTTPService.server({})).to eq(
89
+ "http://#{Koala.config.graph_server}"
90
+ )
91
+ end
92
+
93
+ context "with use_ssl" do
94
+ it "includes https" do
95
+ expect(Koala::HTTPService.server(use_ssl: true)).to eq(
96
+ "https://#{Koala.config.graph_server}"
97
+ )
98
+ end
85
99
  end
86
100
  end
87
101
 
@@ -116,6 +130,23 @@ describe Koala::HTTPService do
116
130
  expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, "-video.facebook")))
117
131
  end
118
132
  end
133
+
134
+ context "with API versions" do
135
+ it "adds a version if specified by Koala.config" do
136
+ Koala.config.api_version = "v1000.000"
137
+ expect(Koala::HTTPService.server).to eq(
138
+ "http://#{Koala.config.graph_server}/#{Koala.config.api_version}"
139
+ )
140
+ end
141
+
142
+ it "prefers a version set in the options" do
143
+ Koala.config.api_version = "v1000.000"
144
+ version = "v2.0"
145
+ expect(Koala::HTTPService.server(api_version: version)).to eq(
146
+ "http://#{Koala.config.graph_server}/#{version}"
147
+ )
148
+ end
149
+ end
119
150
  end
120
151
 
121
152
  describe ".encode_params" do
@@ -244,6 +244,12 @@ describe "Koala::Facebook::OAuth" do
244
244
  expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
245
245
  end
246
246
 
247
+ it "includes the api version if specified" do
248
+ version = Koala.config.api_version = "v.2.2.2.2"
249
+ url = @oauth.url_for_oauth_code
250
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/#{version}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
251
+ end
252
+
247
253
  it "generates a properly formatted OAuth code URL when a callback is given" do
248
254
  callback = "foo.com"
249
255
  url = @oauth.url_for_oauth_code(:callback => callback)
@@ -302,6 +308,12 @@ describe "Koala::Facebook::OAuth" do
302
308
  expect(url).to match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
303
309
  end
304
310
 
311
+ it "includes the api version if specified" do
312
+ version = Koala.config.api_version = "v.2.2.2.2"
313
+ url = @oauth.url_for_access_token(@code)
314
+ expect(url).to match_url("https://#{Koala.config.graph_server}/#{version}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
315
+ end
316
+
305
317
  it "generates a properly formatted OAuth token URL when provided a callback" do
306
318
  callback = "foo.com"
307
319
  url = @oauth.url_for_access_token(@code, :callback => callback)
@@ -323,7 +335,13 @@ describe "Koala::Facebook::OAuth" do
323
335
  describe "#url_for_dialog" do
324
336
  it "builds the base properly" do
325
337
  dialog_type = "my_dialog_type"
326
- expect(@oauth.url_for_dialog(dialog_type)).to match(/^http:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/)
338
+ expect(@oauth.url_for_dialog(dialog_type)).to match(/^https:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/)
339
+ end
340
+
341
+ it "includes the api version if specified" do
342
+ version = Koala.config.api_version = "v.2.2.2.2"
343
+ dialog_type = "my_dialog_type"
344
+ expect(@oauth.url_for_dialog(dialog_type)).to match("https:\/\/#{Koala.config.dialog_host}\/#{version}\/dialog\/#{dialog_type}")
327
345
  end
328
346
 
329
347
  it "adds the app_id/client_id to the url" do
@@ -352,22 +370,22 @@ describe "Koala::Facebook::OAuth" do
352
370
  # slightly brittle (e.g. if parameter order changes), but still useful
353
371
  it "can generate a send dialog" do
354
372
  url = @oauth.url_for_dialog("send", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
355
- expect(url).to match_url("http://www.facebook.com/dialog/send?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
373
+ expect(url).to match_url("https://www.facebook.com/dialog/send?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
356
374
  end
357
375
 
358
376
  it "can generate a feed dialog" do
359
377
  url = @oauth.url_for_dialog("feed", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
360
- expect(url).to match_url("http://www.facebook.com/dialog/feed?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
378
+ expect(url).to match_url("https://www.facebook.com/dialog/feed?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
361
379
  end
362
380
 
363
381
  it "can generate a oauth dialog" do
364
382
  url = @oauth.url_for_dialog("oauth", :scope => "email", :response_type => "token")
365
- expect(url).to match_url("http://www.facebook.com/dialog/oauth?app_id=#{@app_id}&client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}&response_type=token&scope=email")
383
+ expect(url).to match_url("https://www.facebook.com/dialog/oauth?app_id=#{@app_id}&client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}&response_type=token&scope=email")
366
384
  end
367
385
 
368
386
  it "can generate a pay dialog" do
369
387
  url = @oauth.url_for_dialog("pay", :order_id => "foo", :credits_purchase => false)
370
- expect(url).to match_url("http://www.facebook.com/dialog/pay?app_id=#{@app_id}&client_id=#{@app_id}&order_id=foo&credits_purchase=false&redirect_uri=#{CGI.escape @callback_url}")
388
+ expect(url).to match_url("https://www.facebook.com/dialog/pay?app_id=#{@app_id}&client_id=#{@app_id}&order_id=foo&credits_purchase=false&redirect_uri=#{CGI.escape @callback_url}")
371
389
  end
372
390
  end
373
391
  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.10.0rc
4
+ version: 1.10.0rc2
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-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -123,7 +123,8 @@ files:
123
123
  - spec/support/rest_api_shared_examples.rb
124
124
  - spec/support/uploadable_io_shared_examples.rb
125
125
  homepage: http://github.com/arsduo/koala
126
- licenses: []
126
+ licenses:
127
+ - MIT
127
128
  metadata: {}
128
129
  post_install_message:
129
130
  rdoc_options: