koala 1.6.0 → 1.7.0rc1
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/.travis.yml +2 -5
- data/Gemfile +1 -2
- data/changelog.md +107 -4
- data/koala.gemspec +5 -5
- data/lib/koala.rb +13 -4
- data/lib/koala/api.rb +28 -3
- data/lib/koala/api/graph_api.rb +33 -3
- data/lib/koala/api/graph_collection.rb +20 -20
- data/lib/koala/api/rest_api.rb +1 -3
- data/lib/koala/http_service.rb +21 -16
- data/lib/koala/oauth.rb +15 -11
- data/lib/koala/version.rb +1 -1
- data/readme.md +34 -7
- data/spec/cases/api_spec.rb +21 -1
- data/spec/cases/graph_api_batch_spec.rb +38 -16
- data/spec/cases/graph_api_spec.rb +13 -20
- data/spec/cases/http_service_spec.rb +39 -9
- data/spec/cases/koala_spec.rb +34 -22
- data/spec/cases/oauth_spec.rb +16 -12
- data/spec/cases/test_users_spec.rb +5 -1
- data/spec/fixtures/mock_facebook_responses.yml +14 -6
- data/spec/spec_helper.rb +19 -35
- data/spec/support/graph_api_shared_examples.rb +34 -17
- data/spec/support/koala_test.rb +10 -1
- data/spec/support/mock_http_service.rb +77 -33
- metadata +27 -32
- data/spec/support/json_testing_fix.rb +0 -42
data/spec/cases/api_spec.rb
CHANGED
@@ -50,10 +50,30 @@ describe "Koala::Facebook::API" do
|
|
50
50
|
it "returns the entire response if http_component => :response" do
|
51
51
|
http_component = :response
|
52
52
|
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
53
|
-
Koala.stub(:make_request).and_return(response)
|
53
|
+
Koala.stub(:make_request).and_return(response)
|
54
54
|
@service.api('anything', {}, 'get', :http_component => http_component).should == response
|
55
55
|
end
|
56
56
|
|
57
|
+
it "turns arrays of non-enumerables into comma-separated arguments" do
|
58
|
+
args = [12345, {:foo => [1, 2, "3", :four]}]
|
59
|
+
expected = ["/12345", {:foo => "1,2,3,four"}, "get", {}]
|
60
|
+
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
61
|
+
Koala.should_receive(:make_request).with(*expected).and_return(response)
|
62
|
+
@service.api(*args)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "doesn't turn arrays containing enumerables into comma-separated strings" do
|
66
|
+
params = {:foo => [1, 2, ["3"], :four]}
|
67
|
+
args = [12345, params]
|
68
|
+
# we leave this as is -- the HTTP layer can either handle it appropriately
|
69
|
+
# (if appropriate behavior is defined)
|
70
|
+
# or raise an exception
|
71
|
+
expected = ["/12345", params, "get", {}]
|
72
|
+
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
73
|
+
Koala.should_receive(:make_request).with(*expected).and_return(response)
|
74
|
+
@service.api(*args)
|
75
|
+
end
|
76
|
+
|
57
77
|
it "returns the body of the request as JSON if no http_component is given" do
|
58
78
|
response = stub('response', :body => 'body', :status => 200)
|
59
79
|
Koala.stub(:make_request).and_return(response)
|
@@ -507,7 +507,6 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
507
507
|
pictures = @api.batch do |batch_api|
|
508
508
|
batch_api.get_picture('me')
|
509
509
|
end
|
510
|
-
puts pictures.inspect
|
511
510
|
pictures.first.should =~ /http\:\/\// # works both live & stubbed
|
512
511
|
end
|
513
512
|
|
@@ -517,7 +516,34 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
517
516
|
batch_api.get_connections(@app_id, 'insights', {}, {"access_token" => @app_api.access_token})
|
518
517
|
end
|
519
518
|
me['id'].should_not be_nil
|
520
|
-
insights.should be_an(
|
519
|
+
insights.should be_an(Koala::Facebook::GraphCollection)
|
520
|
+
end
|
521
|
+
|
522
|
+
it "preserves batch-op specific access tokens in GraphCollection returned from batch" do
|
523
|
+
# Provide an alternate token for a batch operation
|
524
|
+
@other_access_token_args = { 'access_token' => @app_api.access_token }
|
525
|
+
|
526
|
+
# make a batch call for insights using another token
|
527
|
+
me, insights = @api.batch do |batch_api|
|
528
|
+
batch_api.get_object('me')
|
529
|
+
batch_api.get_connections(@app_id, 'insights', {}, @other_access_token_args)
|
530
|
+
end
|
531
|
+
|
532
|
+
# The alternate token is returned with the next page parameters
|
533
|
+
# The GraphCollection should receive a request for the next_page_params during paging
|
534
|
+
insights.should_receive(:next_page_params).and_return([stub("base"), @other_access_token_args.dup])
|
535
|
+
|
536
|
+
# The alternate access token should pass through to making the request
|
537
|
+
# Koala should receive a request during paging using the alternate token
|
538
|
+
Koala.should_receive(:make_request).with(
|
539
|
+
anything,
|
540
|
+
hash_including(@other_access_token_args.dup),
|
541
|
+
anything,
|
542
|
+
anything
|
543
|
+
).and_return(Koala::HTTPService::Response.new(200, "", ""))
|
544
|
+
|
545
|
+
# Page the collection
|
546
|
+
insights.next_page
|
521
547
|
end
|
522
548
|
|
523
549
|
it "inserts errors in the appropriate place, without breaking other results" do
|
@@ -551,37 +577,33 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
551
577
|
|
552
578
|
describe 'with post-processing callback' do
|
553
579
|
let(:me_result) { stub("me result") }
|
554
|
-
let(:friends_result) { stub("friends result") }
|
580
|
+
let(:friends_result) { [stub("friends result")] }
|
555
581
|
|
556
|
-
let(:me_callback) { lambda {|
|
557
|
-
let(:friends_callback) { lambda {|
|
582
|
+
let(:me_callback) { lambda {|arg| {"result" => me_result, "args" => arg} } }
|
583
|
+
let(:friends_callback) { lambda {|arg| {"result" => friends_result, "args" => arg} } }
|
558
584
|
|
559
585
|
it 'calls the callback with the appropriate data' do
|
560
|
-
|
561
|
-
'id' => KoalaTest.user1
|
562
|
-
))
|
563
|
-
friends_callback.should_receive(:call).with([
|
564
|
-
hash_including('id' => KoalaTest.user2)
|
565
|
-
])
|
566
|
-
@api.batch do |batch_api|
|
586
|
+
me, friends = @api.batch do |batch_api|
|
567
587
|
batch_api.get_object('me', &me_callback)
|
568
588
|
batch_api.get_connections('me', 'friends', &friends_callback)
|
569
589
|
end
|
590
|
+
me["args"].should include("id" => KoalaTest.user1)
|
591
|
+
friends["args"].first.should include("id" => KoalaTest.user2)
|
570
592
|
end
|
571
593
|
|
572
594
|
it 'passes GraphCollections, not raw data' do
|
573
|
-
|
574
|
-
@api.batch do |batch_api|
|
595
|
+
me, friends = @api.batch do |batch_api|
|
575
596
|
batch_api.get_object('me')
|
576
597
|
batch_api.get_connections('me', 'friends', &friends_callback)
|
577
598
|
end
|
599
|
+
friends["args"].should be_a(Koala::Facebook::API::GraphCollection)
|
578
600
|
end
|
579
601
|
|
580
602
|
it "returns the result of the callback" do
|
581
603
|
@api.batch do |batch_api|
|
582
604
|
batch_api.get_object('me', &me_callback)
|
583
605
|
batch_api.get_connections('me', 'friends', &friends_callback)
|
584
|
-
end.should == [me_result, friends_result]
|
606
|
+
end.map {|r| r["result"]}.should == [me_result, friends_result]
|
585
607
|
end
|
586
608
|
end
|
587
609
|
|
@@ -663,4 +685,4 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
663
685
|
end
|
664
686
|
end
|
665
687
|
end
|
666
|
-
end
|
688
|
+
end
|
@@ -10,27 +10,22 @@ describe 'Koala::Facebook::GraphAPIMethods' do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'post-processing for' do
|
13
|
-
let(:
|
13
|
+
let(:result) { stub("result") }
|
14
|
+
let(:post_processing) { lambda {|arg| {"result" => result, "args" => arg} } }
|
14
15
|
|
15
16
|
# Most API methods have the same signature, we test get_object representatively
|
16
17
|
# and the other methods which do some post-processing locally
|
17
18
|
context '#get_object' do
|
18
19
|
it 'returns result of block' do
|
19
|
-
|
20
|
-
@api.
|
21
|
-
post_processing.should_receive(:call).
|
22
|
-
with(result).and_return('new result')
|
23
|
-
@api.get_object('koppel', &post_processing).should == 'new result'
|
20
|
+
@api.stub(:api).and_return(stub("other results"))
|
21
|
+
@api.get_object('koppel', &post_processing)["result"].should == result
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
25
|
context '#get_picture' do
|
28
26
|
it 'returns result of block' do
|
29
|
-
|
30
|
-
@api.
|
31
|
-
post_processing.should_receive(:call).
|
32
|
-
with(result).and_return('new result')
|
33
|
-
@api.get_picture('lukeshepard', &post_processing).should == 'new result'
|
27
|
+
@api.stub(:api).and_return("Location" => stub("other result"))
|
28
|
+
@api.get_picture('lukeshepard', &post_processing)["result"].should == result
|
34
29
|
end
|
35
30
|
end
|
36
31
|
|
@@ -45,12 +40,11 @@ describe 'Koala::Facebook::GraphAPIMethods' do
|
|
45
40
|
it 'is called with resolved response' do
|
46
41
|
resolved_result = {
|
47
42
|
'query1' => [{'id' => 123}],
|
48
|
-
'query2' => [{'id'=>456}]
|
43
|
+
'query2' => [{'id' => 456}]
|
49
44
|
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
{'id'=>'123', 'id'=>'456'}
|
45
|
+
response = @api.fql_multiquery({}, &post_processing)
|
46
|
+
response["args"].should == resolved_result
|
47
|
+
response["result"].should == result
|
54
48
|
end
|
55
49
|
end
|
56
50
|
|
@@ -58,10 +52,9 @@ describe 'Koala::Facebook::GraphAPIMethods' do
|
|
58
52
|
it 'returns result of block' do
|
59
53
|
token = Koala::MockHTTPService::APP_ACCESS_TOKEN
|
60
54
|
@api.stub(:api).and_return("access_token" => token)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
'base64-encoded access token'
|
55
|
+
response = @api.get_page_access_token('facebook', &post_processing)
|
56
|
+
response["args"].should == token
|
57
|
+
response["result"].should == result
|
65
58
|
end
|
66
59
|
end
|
67
60
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Koala::HTTPService do
|
4
4
|
it "has a faraday_middleware accessor" do
|
5
5
|
Koala::HTTPService.methods.map(&:to_sym).should include(:faraday_middleware)
|
6
6
|
Koala::HTTPService.methods.map(&:to_sym).should include(:faraday_middleware=)
|
@@ -45,15 +45,43 @@ describe "Koala::HTTPService" do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
describe Koala::HTTPService::DEFAULT_SERVERS do
|
49
|
+
let(:defaults) { Koala::HTTPService::DEFAULT_SERVERS }
|
50
|
+
|
51
|
+
it "defines the graph server" do
|
52
|
+
defaults[:graph_server].should == "graph.facebook.com"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "defines the rest server" do
|
56
|
+
defaults[:rest_server].should == "api.facebook.com"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "defines the dialog host" do
|
60
|
+
defaults[:dialog_host].should == "www.facebook.com"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "defines the path replacement regular expression" do
|
64
|
+
defaults[:host_path_matcher].should == /\.facebook/
|
65
|
+
end
|
66
|
+
|
67
|
+
it "defines the video server replacement for uploads" do
|
68
|
+
defaults[:video_replace].should == "-video.facebook"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "defines the beta tier replacement" do
|
72
|
+
defaults[:beta_replace].should == ".beta.facebook"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
48
76
|
describe "server" do
|
49
77
|
describe "with no options" do
|
50
78
|
it "returns the REST server if options[:rest_api]" do
|
51
|
-
Koala::HTTPService.server(:rest_api => true).should =~ Regexp.new(Koala
|
79
|
+
Koala::HTTPService.server(:rest_api => true).should =~ Regexp.new(Koala.config.rest_server)
|
52
80
|
end
|
53
81
|
|
54
82
|
it "returns the graph server if !options[:rest_api]" do
|
55
|
-
Koala::HTTPService.server(:rest_api => false).should =~ Regexp.new(Koala
|
56
|
-
Koala::HTTPService.server({}).should =~ Regexp.new(Koala
|
83
|
+
Koala::HTTPService.server(:rest_api => false).should =~ Regexp.new(Koala.config.graph_server)
|
84
|
+
Koala::HTTPService.server({}).should =~ Regexp.new(Koala.config.graph_server)
|
57
85
|
end
|
58
86
|
end
|
59
87
|
|
@@ -64,12 +92,12 @@ describe "Koala::HTTPService" do
|
|
64
92
|
|
65
93
|
it "returns the beta REST server if options[:rest_api]" do
|
66
94
|
server = Koala::HTTPService.server(@options.merge(:rest_api => true))
|
67
|
-
server.should =~ Regexp.new(Koala
|
95
|
+
server.should =~ Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, ".beta.facebook"))
|
68
96
|
end
|
69
97
|
|
70
98
|
it "returns the beta rest server if !options[:rest_api]" do
|
71
99
|
server = Koala::HTTPService.server(@options)
|
72
|
-
server.should =~ Regexp.new(Koala
|
100
|
+
server.should =~ Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, ".beta.facebook"))
|
73
101
|
end
|
74
102
|
end
|
75
103
|
|
@@ -80,12 +108,12 @@ describe "Koala::HTTPService" do
|
|
80
108
|
|
81
109
|
it "returns the REST video server if options[:rest_api]" do
|
82
110
|
server = Koala::HTTPService.server(@options.merge(:rest_api => true))
|
83
|
-
server.should =~ Regexp.new(Koala
|
111
|
+
server.should =~ Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, "-video.facebook"))
|
84
112
|
end
|
85
113
|
|
86
114
|
it "returns the graph video server if !options[:rest_api]" do
|
87
115
|
server = Koala::HTTPService.server(@options)
|
88
|
-
server.should =~ Regexp.new(Koala
|
116
|
+
server.should =~ Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, "-video.facebook"))
|
89
117
|
end
|
90
118
|
end
|
91
119
|
end
|
@@ -212,8 +240,10 @@ describe "Koala::HTTPService" do
|
|
212
240
|
end
|
213
241
|
|
214
242
|
it "uses the default builder block if HTTPService.faraday_middleware block is not defined" do
|
243
|
+
block = Proc.new {}
|
244
|
+
stub_const("Koala::HTTPService::DEFAULT_MIDDLEWARE", block)
|
215
245
|
Koala::HTTPService.stub(:faraday_middleware).and_return(nil)
|
216
|
-
Faraday.should_receive(:new).with(anything, anything, &
|
246
|
+
Faraday.should_receive(:new).with(anything, anything, &block).and_return(@mock_connection)
|
217
247
|
Koala::HTTPService.make_request("anything", {}, "get")
|
218
248
|
end
|
219
249
|
|
data/spec/cases/koala_spec.rb
CHANGED
@@ -1,38 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Koala do
|
4
|
-
|
5
|
-
|
6
4
|
it "has an http_service accessor" do
|
7
5
|
Koala.should respond_to(:http_service)
|
8
6
|
Koala.should respond_to(:http_service=)
|
9
7
|
end
|
10
|
-
|
8
|
+
|
11
9
|
describe "constants" do
|
12
10
|
it "has a version" do
|
13
11
|
Koala.const_defined?("VERSION").should be_true
|
14
12
|
end
|
15
|
-
|
16
|
-
describe Koala::Facebook do
|
17
|
-
it "defines GRAPH_SERVER" do
|
18
|
-
Koala::Facebook::GRAPH_SERVER.should == "graph.facebook.com"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "defines REST_SERVER" do
|
22
|
-
Koala::Facebook::REST_SERVER.should == "api.facebook.com"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "defines DIALOG_HOST" do
|
26
|
-
Koala::Facebook::DIALOG_HOST.should == "www.facebook.com"
|
27
|
-
end
|
28
|
-
end
|
29
13
|
end
|
30
|
-
|
14
|
+
|
31
15
|
context "for deprecated services" do
|
32
16
|
before :each do
|
33
17
|
@service = Koala.http_service
|
34
18
|
end
|
35
|
-
|
19
|
+
|
36
20
|
after :each do
|
37
21
|
Koala.http_service = @service
|
38
22
|
end
|
@@ -42,7 +26,7 @@ describe Koala do
|
|
42
26
|
mock_service.should_receive(:deprecated_interface)
|
43
27
|
Koala.http_service = mock_service
|
44
28
|
end
|
45
|
-
|
29
|
+
|
46
30
|
it "does not set the service if it's deprecated" do
|
47
31
|
mock_service = stub("http service")
|
48
32
|
mock_service.stub(:deprecated_interface)
|
@@ -63,10 +47,38 @@ describe Koala do
|
|
63
47
|
args = {:a => 2}
|
64
48
|
verb = "get"
|
65
49
|
options = {:c => :d}
|
66
|
-
|
50
|
+
|
67
51
|
Koala.http_service.should_receive(:make_request).with(path, args, verb, options)
|
68
52
|
Koala.make_request(path, args, verb, options)
|
69
53
|
end
|
70
54
|
end
|
71
55
|
|
72
|
-
|
56
|
+
describe ".configure" do
|
57
|
+
it "yields a configurable object" do
|
58
|
+
expect {
|
59
|
+
Koala.configure {|c| c.foo = "bar"}
|
60
|
+
}.not_to raise_exception
|
61
|
+
end
|
62
|
+
|
63
|
+
it "caches the config (singleton)" do
|
64
|
+
c = Koala.config
|
65
|
+
expect(c.object_id).to eq(Koala.config.object_id)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe ".config" do
|
70
|
+
it "exposes the basic configuration" do
|
71
|
+
Koala::HTTPService::DEFAULT_SERVERS.each_pair do |k, v|
|
72
|
+
expect(Koala.config.send(k)).to eq(v)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "exposes the values configured" do
|
77
|
+
Koala.configure do |config|
|
78
|
+
config.graph_server = "some-new.graph_server.com"
|
79
|
+
end
|
80
|
+
Koala.config.graph_server.should == "some-new.graph_server.com"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
data/spec/cases/oauth_spec.rb
CHANGED
@@ -148,7 +148,6 @@ describe "Koala::Facebook::OAuth" do
|
|
148
148
|
|
149
149
|
it "returns all the cookie components from valid cookie string" do
|
150
150
|
cookie_data = KoalaTest.oauth_test_data["valid_cookies"]
|
151
|
-
puts cookie_data.inspect
|
152
151
|
parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
|
153
152
|
number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
|
154
153
|
parsing_results.length.should == number_of_components
|
@@ -190,7 +189,7 @@ describe "Koala::Facebook::OAuth" do
|
|
190
189
|
end
|
191
190
|
|
192
191
|
it "does not uses get_user_info_from_cookies to parse the cookies" do
|
193
|
-
@oauth.should_not_receive(:get_user_info_from_cookies).with(@cookie)
|
192
|
+
@oauth.should_not_receive(:get_user_info_from_cookies).with(@cookie)
|
194
193
|
@oauth.get_user_from_cookies(@cookie)
|
195
194
|
end
|
196
195
|
|
@@ -205,6 +204,11 @@ describe "Koala::Facebook::OAuth" do
|
|
205
204
|
result = @oauth.get_user_from_cookies(bad_cookie_hash)
|
206
205
|
result.should be_nil
|
207
206
|
end
|
207
|
+
|
208
|
+
it "is deprecated" do
|
209
|
+
Koala::Utils.should_receive(:deprecate)
|
210
|
+
@oauth.get_user_from_cookies({})
|
211
|
+
end
|
208
212
|
end
|
209
213
|
|
210
214
|
describe "for unsigned cookies" do
|
@@ -237,37 +241,37 @@ describe "Koala::Facebook::OAuth" do
|
|
237
241
|
describe "#url_for_oauth_code" do
|
238
242
|
it "generates a properly formatted OAuth code URL with the default values" do
|
239
243
|
url = @oauth.url_for_oauth_code
|
240
|
-
url.should match_url("https://#{Koala
|
244
|
+
url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
|
241
245
|
end
|
242
246
|
|
243
247
|
it "generates a properly formatted OAuth code URL when a callback is given" do
|
244
248
|
callback = "foo.com"
|
245
249
|
url = @oauth.url_for_oauth_code(:callback => callback)
|
246
|
-
url.should match_url("https://#{Koala
|
250
|
+
url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{callback}")
|
247
251
|
end
|
248
252
|
|
249
253
|
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
|
250
254
|
permissions = "publish_stream,read_stream"
|
251
255
|
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
252
|
-
url.should match_url("https://#{Koala
|
256
|
+
url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
|
253
257
|
end
|
254
258
|
|
255
259
|
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
|
256
260
|
permissions = ["publish_stream", "read_stream"]
|
257
261
|
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
258
|
-
url.should match_url("https://#{Koala
|
262
|
+
url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
|
259
263
|
end
|
260
264
|
|
261
265
|
it "generates a properly formatted OAuth code URL when both permissions and callback are provided" do
|
262
266
|
permissions = "publish_stream,read_stream"
|
263
267
|
callback = "foo.com"
|
264
268
|
url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
|
265
|
-
url.should match_url("https://#{Koala
|
269
|
+
url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
|
266
270
|
end
|
267
271
|
|
268
272
|
it "generates a properly formatted OAuth code URL when a display is given as a string" do
|
269
273
|
url = @oauth.url_for_oauth_code(:display => "page")
|
270
|
-
url.should match_url("https://#{Koala
|
274
|
+
url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
|
271
275
|
end
|
272
276
|
|
273
277
|
it "raises an exception if no callback is given in initialization or the call" do
|
@@ -295,13 +299,13 @@ describe "Koala::Facebook::OAuth" do
|
|
295
299
|
|
296
300
|
it "generates a properly formatted OAuth token URL when provided a code" do
|
297
301
|
url = @oauth.url_for_access_token(@code)
|
298
|
-
url.should match_url("https://#{Koala
|
302
|
+
url.should 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}")
|
299
303
|
end
|
300
304
|
|
301
305
|
it "generates a properly formatted OAuth token URL when provided a callback" do
|
302
306
|
callback = "foo.com"
|
303
307
|
url = @oauth.url_for_access_token(@code, :callback => callback)
|
304
|
-
url.should match_url("https://#{Koala
|
308
|
+
url.should match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
|
305
309
|
end
|
306
310
|
|
307
311
|
it "includes any additional options as URL parameters, appropriately escaped" do
|
@@ -319,7 +323,7 @@ describe "Koala::Facebook::OAuth" do
|
|
319
323
|
describe "#url_for_dialog" do
|
320
324
|
it "builds the base properly" do
|
321
325
|
dialog_type = "my_dialog_type"
|
322
|
-
@oauth.url_for_dialog(dialog_type).should =~ /^http:\/\/#{Koala
|
326
|
+
@oauth.url_for_dialog(dialog_type).should =~ /^http:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/
|
323
327
|
end
|
324
328
|
|
325
329
|
it "adds the app_id/client_id to the url" do
|
@@ -541,7 +545,7 @@ describe "Koala::Facebook::OAuth" do
|
|
541
545
|
end
|
542
546
|
|
543
547
|
it "fetches a proper token string from Facebook when asked for the app token" do
|
544
|
-
result = @oauth.send(:fetch_token_string, {:
|
548
|
+
result = @oauth.send(:fetch_token_string, {:grant_type => 'client_credentials'}, true)
|
545
549
|
result.should =~ /^access_token/
|
546
550
|
end
|
547
551
|
end
|