rest-core 0.2.3 → 0.3.0.pre.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/.travis.yml +8 -4
- data/CHANGES.md +20 -0
- data/Gemfile +4 -3
- data/README.md +8 -8
- data/Rakefile +42 -2
- data/example/rails2/Gemfile +13 -0
- data/example/rails2/README +4 -0
- data/example/rails2/Rakefile +11 -0
- data/example/rails2/app/controllers/application_controller.rb +119 -0
- data/example/rails2/app/views/application/helper.html.erb +1 -0
- data/example/rails2/config/boot.rb +130 -0
- data/example/rails2/config/environment.rb +15 -0
- data/example/rails2/config/environments/development.rb +17 -0
- data/example/rails2/config/environments/production.rb +28 -0
- data/example/rails2/config/environments/test.rb +30 -0
- data/example/rails2/config/initializers/cookie_verification_secret.rb +7 -0
- data/example/rails2/config/initializers/new_rails_defaults.rb +21 -0
- data/example/rails2/config/initializers/session_store.rb +15 -0
- data/example/rails2/config/preinitializer.rb +23 -0
- data/example/rails2/config/rest-core.yaml +12 -0
- data/example/rails2/config/routes.rb +43 -0
- data/example/rails2/log +0 -0
- data/example/rails2/test/functional/application_controller_test.rb +183 -0
- data/example/rails2/test/test_helper.rb +18 -0
- data/example/rails2/test/unit/rails_util_test.rb +44 -0
- data/example/rails3/Gemfile +13 -0
- data/example/rails3/README +4 -0
- data/example/rails3/Rakefile +7 -0
- data/example/rails3/app/controllers/application_controller.rb +119 -0
- data/example/rails3/app/views/application/helper.html.erb +1 -0
- data/example/rails3/config/application.rb +23 -0
- data/example/rails3/config/environment.rb +5 -0
- data/example/rails3/config/environments/development.rb +26 -0
- data/example/rails3/config/environments/production.rb +49 -0
- data/example/rails3/config/environments/test.rb +30 -0
- data/example/rails3/config/initializers/secret_token.rb +7 -0
- data/example/rails3/config/initializers/session_store.rb +8 -0
- data/example/rails3/config/rest-core.yaml +12 -0
- data/example/rails3/config/routes.rb +5 -0
- data/example/rails3/config.ru +4 -0
- data/example/rails3/test/functional/application_controller_test.rb +183 -0
- data/example/rails3/test/test_helper.rb +18 -0
- data/example/rails3/test/unit/rails_util_test.rb +44 -0
- data/example/sinatra/config.ru +16 -0
- data/lib/rest-core/app/ask.rb +0 -2
- data/lib/rest-core/client/facebook/rails_util.rb +342 -0
- data/lib/rest-core/client/{rest-graph.rb → facebook.rb} +21 -28
- data/lib/rest-core/client/github.rb +1 -1
- data/lib/rest-core/client/linkedin.rb +3 -1
- data/lib/rest-core/client/twitter.rb +2 -2
- data/lib/rest-core/client.rb +2 -2
- data/lib/rest-core/client_oauth1.rb +3 -3
- data/lib/rest-core/middleware/oauth2_query.rb +3 -3
- data/{test/common.rb → lib/rest-core/test.rb} +7 -3
- data/lib/rest-core/util/config.rb +22 -17
- data/lib/rest-core/util/vendor.rb +31 -0
- data/lib/rest-core/version.rb +1 -1
- data/lib/rest-core.rb +5 -0
- data/rest-core.gemspec +135 -108
- data/test/client/facebook/config/rest-core.yaml +8 -0
- data/test/{test_api.rb → client/facebook/test_api.rb} +22 -23
- data/test/{test_cache.rb → client/facebook/test_cache.rb} +4 -8
- data/test/{test_default.rb → client/facebook/test_default.rb} +6 -10
- data/test/client/facebook/test_error.rb +65 -0
- data/test/{test_handler.rb → client/facebook/test_handler.rb} +12 -15
- data/test/{test_load_config.rb → client/facebook/test_load_config.rb} +6 -9
- data/test/{test_misc.rb → client/facebook/test_misc.rb} +15 -18
- data/test/{test_oauth.rb → client/facebook/test_oauth.rb} +4 -8
- data/test/{test_old.rb → client/facebook/test_old.rb} +16 -18
- data/test/{test_page.rb → client/facebook/test_page.rb} +5 -9
- data/test/{test_parse.rb → client/facebook/test_parse.rb} +13 -16
- data/test/client/facebook/test_serialize.rb +42 -0
- data/test/client/facebook/test_timeout.rb +22 -0
- data/test/test_oauth1_header.rb +1 -5
- metadata +99 -58
- data/test/config/rest-core.yaml +0 -7
- data/test/test_error.rb +0 -66
- data/test/test_serialize.rb +0 -44
- data/test/test_timeout.rb +0 -25
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
after do
|
10
6
|
WebMock.reset!
|
11
7
|
RR.verify
|
@@ -13,9 +9,9 @@ describe RestGraph do
|
|
13
9
|
|
14
10
|
should 'generate correct url' do
|
15
11
|
TestHelper.normalize_url(
|
16
|
-
|
17
|
-
should
|
18
|
-
|
12
|
+
RestCore::Facebook.new(:access_token => 'awesome').
|
13
|
+
url('path', :query => 'str')).should.eq \
|
14
|
+
'https://graph.facebook.com/path?access_token=awesome&query=str'
|
19
15
|
end
|
20
16
|
|
21
17
|
should 'request to correct server' do
|
@@ -28,9 +24,10 @@ describe RestGraph do
|
|
28
24
|
{'User-Agent' => 'Ruby'})). # this is by ruby
|
29
25
|
to_return(:body => '{"data": []}')
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
RestCore::Facebook.new(:site => 'http://nothing.godfat.org/',
|
28
|
+
:lang => 'zh-tw',
|
29
|
+
:accept => 'text/plain').
|
30
|
+
get('me').should.eq({'data' => []})
|
34
31
|
end
|
35
32
|
|
36
33
|
should 'pass custom headers' do
|
@@ -44,16 +41,16 @@ describe RestGraph do
|
|
44
41
|
{'User-Agent' => 'Ruby'})). # this is by ruby
|
45
42
|
to_return(:body => '{"data": []}')
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
should
|
44
|
+
RestCore::Facebook.new.request(
|
45
|
+
{:headers => {'X-Forwarded-For' => '127.0.0.1'}},
|
46
|
+
[:get, 'http://example.com']).should.eq({'data' => []})
|
50
47
|
end
|
51
48
|
|
52
49
|
should 'post right' do
|
53
50
|
stub_request(:post, 'https://graph.facebook.com/feed/me').
|
54
51
|
with(:body => 'message=hi%20there').to_return(:body => 'ok')
|
55
52
|
|
56
|
-
|
53
|
+
RestCore::Facebook.new(:json_decode => false).
|
57
54
|
post('feed/me', :message => 'hi there').should == 'ok'
|
58
55
|
end
|
59
56
|
|
@@ -62,8 +59,9 @@ describe RestGraph do
|
|
62
59
|
'https://graph.facebook.com/me?access_token=1|2').
|
63
60
|
to_return(:body => 'ok')
|
64
61
|
|
65
|
-
rg =
|
66
|
-
|
62
|
+
rg = RestCore::Facebook.new(
|
63
|
+
:json_decode => false, :access_token => 'wrong',
|
64
|
+
:app_id => '1', :secret => '2')
|
67
65
|
rg.get('me', {}, :secret => true).should == 'ok'
|
68
66
|
rg.url('me', {}, :secret => true).should ==
|
69
67
|
'https://graph.facebook.com/me?access_token=1%7C2'
|
@@ -75,9 +73,9 @@ describe RestGraph do
|
|
75
73
|
stub_request(:get, 'https://graph.facebook.com/woot').
|
76
74
|
to_return(:body => 'bad json')
|
77
75
|
|
78
|
-
rg =
|
79
|
-
rg.get('woot', {}, :
|
80
|
-
rg.
|
76
|
+
rg = RestCore::Facebook.new(:json_decode => true)
|
77
|
+
rg.get('woot', {}, :json_decode => false).should == 'bad json'
|
78
|
+
rg.json_decode.should == true
|
81
79
|
end
|
82
80
|
|
83
81
|
should 'not raise exception when encountering error' do
|
@@ -85,7 +83,7 @@ describe RestGraph do
|
|
85
83
|
stub_request(:delete, 'https://graph.facebook.com/123').to_return(
|
86
84
|
:body => '[]', :status => status)
|
87
85
|
|
88
|
-
|
86
|
+
RestCore::Facebook.new.delete('123').should == []
|
89
87
|
}
|
90
88
|
end
|
91
89
|
|
@@ -93,6 +91,7 @@ describe RestGraph do
|
|
93
91
|
stub(o = Object.new).to_s{ 'i am mock' }
|
94
92
|
stub_request(:get, "https://graph.facebook.com/search?q=i%20am%20mock").
|
95
93
|
to_return(:body => 'ok')
|
96
|
-
|
94
|
+
RestCore::Facebook.new(:json_decode => false).
|
95
|
+
get('search', :q => o).should.eq 'ok'
|
97
96
|
end
|
98
97
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
after do
|
10
6
|
WebMock.reset!
|
11
7
|
RR.verify
|
@@ -16,7 +12,7 @@ describe RestGraph do
|
|
16
12
|
@url, @body = "https://graph.facebook.com/cache", '{"message":"ok"}'
|
17
13
|
@cache_key = Digest::MD5.hexdigest(@url)
|
18
14
|
@cache = {}
|
19
|
-
@rg =
|
15
|
+
@rg = RestCore::Facebook.new(:cache => @cache, :json_decode => false)
|
20
16
|
stub_request(:get, @url).to_return(:body => @body).times(1)
|
21
17
|
end
|
22
18
|
|
@@ -48,7 +44,7 @@ describe RestGraph do
|
|
48
44
|
stub_request(meth, url).to_return(:body => body).times(3)
|
49
45
|
|
50
46
|
cache = {}
|
51
|
-
rg =
|
47
|
+
rg = RestCore::Facebook.new(:cache => cache)
|
52
48
|
3.times{
|
53
49
|
if meth == :delete
|
54
50
|
rg.send(meth, 'cache').should == {'message' => 'ok'}
|
@@ -1,21 +1,17 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
should 'honor default attributes' do
|
10
|
-
|
6
|
+
RestCore::Facebook.members.reject{ |name|
|
11
7
|
name.to_s =~ /method$|handler$|detector$/ }.each{ |name|
|
12
|
-
|
13
|
-
|
8
|
+
RestCore::Facebook.new.send(name).should ==
|
9
|
+
RestCore::Facebook.new.send("default_#{name}")
|
14
10
|
}
|
15
11
|
end
|
16
12
|
|
17
13
|
should 'use module to override default attributes' do
|
18
|
-
klass =
|
14
|
+
klass = RestCore::Facebook.dup
|
19
15
|
klass.send(:include, Module.new do
|
20
16
|
def default_app_id
|
21
17
|
'1829'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
require 'rest-core/test'
|
3
|
+
|
4
|
+
describe RestCore::Facebook::Error do
|
5
|
+
after do
|
6
|
+
WebMock.reset!
|
7
|
+
RR.verify
|
8
|
+
end
|
9
|
+
|
10
|
+
should 'have the right ancestors' do
|
11
|
+
RestCore::Facebook::Error::AccessToken.should < RestCore::Facebook::Error
|
12
|
+
|
13
|
+
RestCore::Facebook::Error::InvalidAccessToken.should <
|
14
|
+
RestCore::Facebook::Error::AccessToken
|
15
|
+
|
16
|
+
RestCore::Facebook::Error::MissingAccessToken.should <
|
17
|
+
RestCore::Facebook::Error::AccessToken
|
18
|
+
end
|
19
|
+
|
20
|
+
def error2env hash
|
21
|
+
{RestCore::RESPONSE_BODY => hash,
|
22
|
+
RestCore::REQUEST_PATH => '/' ,
|
23
|
+
RestCore::REQUEST_QUERY => {}}
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'parse right' do
|
27
|
+
%w[OAuthInvalidTokenException OAuthException].each{ |type|
|
28
|
+
RestCore::Facebook::Error.call(error2env('error' => {'type' => type})).
|
29
|
+
should.kind_of?(RestCore::Facebook::Error::InvalidAccessToken)
|
30
|
+
}
|
31
|
+
|
32
|
+
RestCore::Facebook::Error.call(
|
33
|
+
error2env('error'=>{'type' =>'QueryParseException',
|
34
|
+
'message'=>'An active access token..'})).
|
35
|
+
should.kind_of?(RestCore::Facebook::Error::MissingAccessToken)
|
36
|
+
|
37
|
+
RestCore::Facebook::Error.call(
|
38
|
+
error2env('error'=>{'type' =>'QueryParseException',
|
39
|
+
'message'=>'Oh active access token..'})).
|
40
|
+
should.not.kind_of?(RestCore::Facebook::Error::MissingAccessToken)
|
41
|
+
|
42
|
+
RestCore::Facebook::Error.call(error2env('error_code' => 190)).
|
43
|
+
should.kind_of?(RestCore::Facebook::Error::InvalidAccessToken)
|
44
|
+
|
45
|
+
RestCore::Facebook::Error.call(error2env('error_code' => 104)).
|
46
|
+
should.kind_of?(RestCore::Facebook::Error::MissingAccessToken)
|
47
|
+
|
48
|
+
RestCore::Facebook::Error.call(error2env('error_code' => 999)).
|
49
|
+
should.not.kind_of?(RestCore::Facebook::Error::AccessToken)
|
50
|
+
|
51
|
+
error = RestCore::Facebook::Error.call(error2env(['not a hash']))
|
52
|
+
error.should.not.kind_of?(RestCore::Facebook::Error::AccessToken)
|
53
|
+
error.should .kind_of?(RestCore::Facebook::Error)
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'nuke cache upon errors' do
|
57
|
+
stub_request(:get, 'https://graph.facebook.com/me').
|
58
|
+
to_return(:body => '{"error":"wrong"}').times(2)
|
59
|
+
|
60
|
+
rg = RestCore::Facebook.new(:cache => {},
|
61
|
+
:error_handler => lambda{|env|env})
|
62
|
+
rg.get('me'); rg.get('me')
|
63
|
+
rg.cache.values.should == []
|
64
|
+
end
|
65
|
+
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
after do
|
10
6
|
WebMock.reset!
|
11
7
|
RR.verify
|
@@ -17,7 +13,7 @@ describe RestGraph do
|
|
17
13
|
to_return(:body => '{}')
|
18
14
|
|
19
15
|
logger = []
|
20
|
-
rg =
|
16
|
+
rg = RestCore::Facebook.new(:log_method => lambda{ |s| logger << [s] })
|
21
17
|
rg.get('me')
|
22
18
|
|
23
19
|
logger.size.should == 1
|
@@ -35,13 +31,14 @@ describe RestGraph do
|
|
35
31
|
end
|
36
32
|
|
37
33
|
should 'call error_handler if error occurred' do
|
38
|
-
|
34
|
+
RestCore::Facebook.new(:error_handler => @id).get('me').
|
35
|
+
should.eq @error_hash
|
39
36
|
end
|
40
37
|
|
41
|
-
should 'raise ::
|
38
|
+
should 'raise ::RestCore::Facebook::Error in default error_handler' do
|
42
39
|
begin
|
43
|
-
|
44
|
-
rescue ::
|
40
|
+
RestCore::Facebook.new.get('me')
|
41
|
+
rescue ::RestCore::Facebook::Error => e
|
45
42
|
e.error .should == @error_hash
|
46
43
|
e.message.should ==
|
47
44
|
"#{@error_hash.inspect} from https://graph.facebook.com/me"
|
@@ -69,14 +66,14 @@ describe RestGraph do
|
|
69
66
|
end
|
70
67
|
|
71
68
|
should 'call error_handler if error occurred' do
|
72
|
-
|
69
|
+
RestCore::Facebook.new(:error_handler => @id).fql(@bad_fql_query).
|
73
70
|
should == @fql_error_hash
|
74
71
|
end
|
75
72
|
|
76
|
-
should 'raise ::
|
73
|
+
should 'raise ::RestCore::Facebook::Error in default error_handler' do
|
77
74
|
begin
|
78
|
-
|
79
|
-
rescue ::
|
75
|
+
RestCore::Facebook.new.fql(@bad_fql_query)
|
76
|
+
rescue ::RestCore::Facebook::Error => e
|
80
77
|
e.error .should == @fql_error_hash
|
81
78
|
e.message.should.start_with?(
|
82
79
|
"#{@fql_error_hash.inspect} from " \
|
@@ -1,9 +1,5 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
4
|
require 'rest-core/util/config'
|
9
5
|
::Rails = Object.new
|
@@ -11,7 +7,7 @@ require 'rest-core/util/config'
|
|
11
7
|
describe RestCore::Config do
|
12
8
|
|
13
9
|
before do
|
14
|
-
@klass =
|
10
|
+
@klass = RestCore::Facebook.dup
|
15
11
|
end
|
16
12
|
|
17
13
|
after do
|
@@ -21,14 +17,14 @@ describe RestCore::Config do
|
|
21
17
|
def check
|
22
18
|
@klass.default_app_id .should == 41829
|
23
19
|
@klass.default_secret .should == 'r41829'.reverse
|
24
|
-
@klass.
|
20
|
+
@klass.default_json_decode.should == false
|
25
21
|
@klass.default_lang .should == 'zh-tw'
|
26
22
|
end
|
27
23
|
|
28
24
|
should 'honor rails config' do
|
29
25
|
mock(Rails).env { 'test' }
|
30
26
|
mock(Rails).root{ File.dirname(__FILE__) }
|
31
|
-
RestCore::Config.load_for_rails(@klass)
|
27
|
+
RestCore::Config.load_for_rails(@klass, 'facebook')
|
32
28
|
check
|
33
29
|
end
|
34
30
|
|
@@ -36,7 +32,8 @@ describe RestCore::Config do
|
|
36
32
|
RestCore::Config.load(
|
37
33
|
@klass,
|
38
34
|
"#{File.dirname(__FILE__)}/config/rest-core.yaml",
|
39
|
-
'test'
|
35
|
+
'test',
|
36
|
+
'facebook')
|
40
37
|
check
|
41
38
|
end
|
42
39
|
end
|
@@ -1,23 +1,19 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
after do
|
10
6
|
WebMock.reset!
|
11
7
|
RR.verify
|
12
8
|
end
|
13
9
|
|
14
10
|
should 'return true in authorized? if there is an access_token' do
|
15
|
-
|
16
|
-
|
11
|
+
RestCore::Facebook.new(:access_token => '1').authorized?.should == true
|
12
|
+
RestCore::Facebook.new(:access_token => nil).authorized?.should == false
|
17
13
|
end
|
18
14
|
|
19
15
|
should 'treat oauth_token as access_token as well' do
|
20
|
-
rg =
|
16
|
+
rg = RestCore::Facebook.new
|
21
17
|
hate_facebook = 'why the hell two different name?'
|
22
18
|
rg.data['oauth_token'] = hate_facebook
|
23
19
|
rg.authorized?.should == true
|
@@ -25,8 +21,8 @@ describe RestGraph do
|
|
25
21
|
end
|
26
22
|
|
27
23
|
should 'build correct headers' do
|
28
|
-
rg =
|
29
|
-
|
24
|
+
rg = RestCore::Facebook.new(:accept => 'text/html',
|
25
|
+
:lang => 'zh-tw')
|
30
26
|
|
31
27
|
headers = rg.ask.call(rg.send(:build_env))[RestCore::REQUEST_HEADERS]
|
32
28
|
headers['Accept' ].should == 'text/html'
|
@@ -34,19 +30,19 @@ describe RestGraph do
|
|
34
30
|
end
|
35
31
|
|
36
32
|
should 'build empty query string' do
|
37
|
-
rg =
|
33
|
+
rg = RestCore::Facebook.new
|
38
34
|
(rg.ask.call(rg.send(:build_env))[RestCore::REQUEST_QUERY] || {}).
|
39
35
|
should == {}
|
40
36
|
end
|
41
37
|
|
42
38
|
should 'create access_token in query string' do
|
43
|
-
rg =
|
39
|
+
rg = RestCore::Facebook.new(:access_token => 'token')
|
44
40
|
(rg.ask.call(rg.send(:build_env))[RestCore::REQUEST_QUERY] || {}).
|
45
41
|
should == {'access_token' => 'token'}
|
46
42
|
end
|
47
43
|
|
48
44
|
should 'build correct query string' do
|
49
|
-
rg =
|
45
|
+
rg = RestCore::Facebook.new(:access_token => 'token')
|
50
46
|
TestHelper.normalize_url(rg.url('', :message => 'hi!!')).
|
51
47
|
should == "#{rg.site}?access_token=token&message=hi%21%21"
|
52
48
|
|
@@ -57,19 +53,20 @@ describe RestGraph do
|
|
57
53
|
end
|
58
54
|
|
59
55
|
should 'auto decode json' do
|
60
|
-
rg =
|
56
|
+
rg = RestCore::Facebook.new(:json_decode => true)
|
61
57
|
stub_request(:get, rg.site).to_return(:body => '[]')
|
62
58
|
rg.get('').should == []
|
63
59
|
end
|
64
60
|
|
65
61
|
should 'not auto decode json' do
|
66
|
-
rg =
|
62
|
+
rg = RestCore::Facebook.new(:json_decode => false)
|
67
63
|
stub_request(:get, rg.site).to_return(:body => '[]')
|
68
64
|
rg.get('').should == '[]'
|
69
65
|
end
|
70
66
|
|
71
67
|
should 'give attributes' do
|
72
|
-
|
73
|
-
|
68
|
+
RestCore::Facebook.new(:json_decode => false).attributes.
|
69
|
+
keys.map(&:to_s).sort.should.eq \
|
70
|
+
RestCore::Facebook.members.map(&:to_s).sort
|
74
71
|
end
|
75
72
|
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
before do
|
10
|
-
@rg =
|
6
|
+
@rg = RestCore::Facebook.new(:app_id => '29', :secret => '18')
|
11
7
|
@uri = 'http://zzz.tw'
|
12
8
|
end
|
13
9
|
|
@@ -35,7 +31,7 @@ describe RestGraph do
|
|
35
31
|
end
|
36
32
|
|
37
33
|
should 'not append access_token in authorize_url even presented' do
|
38
|
-
|
34
|
+
RestCore::Facebook.new(:access_token => 'do not use me').authorize_url.
|
39
35
|
should == 'https://graph.facebook.com/oauth/authorize'
|
40
36
|
end
|
41
37
|
|
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
after do
|
10
6
|
WebMock.reset!
|
11
7
|
RR.verify
|
@@ -17,14 +13,14 @@ describe RestGraph do
|
|
17
13
|
stub_request(:get, "https://api.facebook.com/method/fql.query?#{query}").
|
18
14
|
to_return(:body => '[]')
|
19
15
|
|
20
|
-
|
16
|
+
RestCore::Facebook.new.fql(fql).should == []
|
21
17
|
|
22
18
|
token = 'token'.reverse
|
23
19
|
stub_request(:get, "https://api.facebook.com/method/fql.query?#{query}" \
|
24
20
|
"&access_token=#{token}").
|
25
21
|
to_return(:body => '[]')
|
26
22
|
|
27
|
-
|
23
|
+
RestCore::Facebook.new(:access_token => token).fql(fql).should == []
|
28
24
|
end
|
29
25
|
|
30
26
|
should 'do fql.mutilquery correctly' do
|
@@ -45,7 +41,7 @@ describe RestGraph do
|
|
45
41
|
}
|
46
42
|
|
47
43
|
stub_multi.call
|
48
|
-
|
44
|
+
RestCore::Facebook.new.fql_multi(:f0 => f0, :f1 => f1).should == []
|
49
45
|
end
|
50
46
|
|
51
47
|
should 'cache fake post in fql' do
|
@@ -56,25 +52,27 @@ describe RestGraph do
|
|
56
52
|
with(:body => {:query => query}).
|
57
53
|
to_return(:body => body)
|
58
54
|
|
59
|
-
|
55
|
+
RestCore::Facebook.new(:cache => (cache = {})).
|
56
|
+
fql(query, {}, :post => true).
|
60
57
|
first['name'] .should == 'Mark Zuckerberg'
|
61
58
|
cache.size .should == 1
|
62
59
|
cache.values.first.should == body
|
63
60
|
|
64
61
|
WebMock.reset! # should hit the cache
|
65
62
|
|
66
|
-
|
63
|
+
RestCore::Facebook.new(:cache => cache).fql(query, {}, :post => true).
|
67
64
|
first['name'] .should == 'Mark Zuckerberg'
|
68
65
|
cache.size .should == 1
|
69
66
|
cache.values.first.should == body
|
70
67
|
|
71
68
|
# query changed
|
72
69
|
should.raise(WebMock::NetConnectNotAllowedError) do
|
73
|
-
|
70
|
+
RestCore::Facebook.new(:cache => cache).
|
71
|
+
fql(query.upcase, {}, :post => true)
|
74
72
|
end
|
75
73
|
|
76
74
|
# cache should work for normal get
|
77
|
-
|
75
|
+
RestCore::Facebook.new(:cache => cache).fql(query).
|
78
76
|
first['name'] .should == 'Mark Zuckerberg'
|
79
77
|
cache.size .should == 1
|
80
78
|
cache.values.first.should == body
|
@@ -86,8 +84,8 @@ describe RestGraph do
|
|
86
84
|
'https://api.facebook.com/method/notes.create?format=json').
|
87
85
|
to_return(:body => body)
|
88
86
|
|
89
|
-
|
90
|
-
should
|
87
|
+
RestCore::Facebook.new.
|
88
|
+
old_rest('notes.create', {}, :json_decode => false).should.eq body
|
91
89
|
end
|
92
90
|
|
93
91
|
should 'exchange sessions for access token' do
|
@@ -97,8 +95,8 @@ describe RestGraph do
|
|
97
95
|
'sessions=bad%20bed').
|
98
96
|
to_return(:body => '[{"access_token":"bogus"}]')
|
99
97
|
|
100
|
-
|
101
|
-
|
98
|
+
RestCore::Facebook.new(:app_id => 'id',
|
99
|
+
:secret => 'di').
|
102
100
|
exchange_sessions(:sessions => 'bad bed').
|
103
101
|
first['access_token'].should == 'bogus'
|
104
102
|
end
|
@@ -109,7 +107,7 @@ describe RestGraph do
|
|
109
107
|
'access_token=123%7Cs&format=json&properties=app_id'
|
110
108
|
).to_return(:body => '{"app_id":"123"}')
|
111
109
|
|
112
|
-
|
110
|
+
RestCore::Facebook.new(:app_id => '123', :secret => 's').
|
113
111
|
secret_old_rest('admin.getAppProperties', :properties => 'app_id').
|
114
112
|
should == {'app_id' => '123'}
|
115
113
|
end
|
@@ -1,18 +1,14 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'common'
|
4
|
-
else
|
5
|
-
require File.dirname(__FILE__) + '/common'
|
6
|
-
end
|
2
|
+
require 'rest-core/test'
|
7
3
|
|
8
|
-
describe
|
4
|
+
describe RestCore::Facebook do
|
9
5
|
after do
|
10
6
|
WebMock.reset!
|
11
7
|
RR.verify
|
12
8
|
end
|
13
9
|
|
14
10
|
should 'get the next/prev page' do
|
15
|
-
rg =
|
11
|
+
rg = RestCore::Facebook.new(:site => '', :cache => false)
|
16
12
|
%w[next previous].each{ |type|
|
17
13
|
kind = "#{type}_page"
|
18
14
|
rg.send(kind, {}) .should == nil
|
@@ -25,7 +21,7 @@ describe RestGraph do
|
|
25
21
|
end
|
26
22
|
|
27
23
|
should 'merge all pages into one' do
|
28
|
-
rg =
|
24
|
+
rg = RestCore::Facebook.new(:site => '', :cache => false)
|
29
25
|
%w[next previous].each{ |type|
|
30
26
|
kind = "#{type}_page"
|
31
27
|
data = {'paging' => {type => 'zzz'}, 'data' => ['z']}
|
@@ -54,7 +50,7 @@ describe RestGraph do
|
|
54
50
|
end
|
55
51
|
|
56
52
|
should 'for_pages with callback' do
|
57
|
-
rg =
|
53
|
+
rg = RestCore::Facebook.new(:site => '', :cache => false)
|
58
54
|
%w[next previous].each{ |type|
|
59
55
|
kind = "#{type}_page"
|
60
56
|
data = {'paging' => {type => 'zzz'}, 'data' => ['z']}
|