rest-core 0.2.3 → 0.3.0.pre.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.travis.yml +8 -4
  2. data/CHANGES.md +20 -0
  3. data/Gemfile +4 -3
  4. data/README.md +8 -8
  5. data/Rakefile +42 -2
  6. data/example/rails2/Gemfile +13 -0
  7. data/example/rails2/README +4 -0
  8. data/example/rails2/Rakefile +11 -0
  9. data/example/rails2/app/controllers/application_controller.rb +119 -0
  10. data/example/rails2/app/views/application/helper.html.erb +1 -0
  11. data/example/rails2/config/boot.rb +130 -0
  12. data/example/rails2/config/environment.rb +15 -0
  13. data/example/rails2/config/environments/development.rb +17 -0
  14. data/example/rails2/config/environments/production.rb +28 -0
  15. data/example/rails2/config/environments/test.rb +30 -0
  16. data/example/rails2/config/initializers/cookie_verification_secret.rb +7 -0
  17. data/example/rails2/config/initializers/new_rails_defaults.rb +21 -0
  18. data/example/rails2/config/initializers/session_store.rb +15 -0
  19. data/example/rails2/config/preinitializer.rb +23 -0
  20. data/example/rails2/config/rest-core.yaml +12 -0
  21. data/example/rails2/config/routes.rb +43 -0
  22. data/example/rails2/log +0 -0
  23. data/example/rails2/test/functional/application_controller_test.rb +183 -0
  24. data/example/rails2/test/test_helper.rb +18 -0
  25. data/example/rails2/test/unit/rails_util_test.rb +44 -0
  26. data/example/rails3/Gemfile +13 -0
  27. data/example/rails3/README +4 -0
  28. data/example/rails3/Rakefile +7 -0
  29. data/example/rails3/app/controllers/application_controller.rb +119 -0
  30. data/example/rails3/app/views/application/helper.html.erb +1 -0
  31. data/example/rails3/config/application.rb +23 -0
  32. data/example/rails3/config/environment.rb +5 -0
  33. data/example/rails3/config/environments/development.rb +26 -0
  34. data/example/rails3/config/environments/production.rb +49 -0
  35. data/example/rails3/config/environments/test.rb +30 -0
  36. data/example/rails3/config/initializers/secret_token.rb +7 -0
  37. data/example/rails3/config/initializers/session_store.rb +8 -0
  38. data/example/rails3/config/rest-core.yaml +12 -0
  39. data/example/rails3/config/routes.rb +5 -0
  40. data/example/rails3/config.ru +4 -0
  41. data/example/rails3/test/functional/application_controller_test.rb +183 -0
  42. data/example/rails3/test/test_helper.rb +18 -0
  43. data/example/rails3/test/unit/rails_util_test.rb +44 -0
  44. data/example/sinatra/config.ru +16 -0
  45. data/lib/rest-core/app/ask.rb +0 -2
  46. data/lib/rest-core/client/facebook/rails_util.rb +342 -0
  47. data/lib/rest-core/client/{rest-graph.rb → facebook.rb} +21 -28
  48. data/lib/rest-core/client/github.rb +1 -1
  49. data/lib/rest-core/client/linkedin.rb +3 -1
  50. data/lib/rest-core/client/twitter.rb +2 -2
  51. data/lib/rest-core/client.rb +2 -2
  52. data/lib/rest-core/client_oauth1.rb +3 -3
  53. data/lib/rest-core/middleware/oauth2_query.rb +3 -3
  54. data/{test/common.rb → lib/rest-core/test.rb} +7 -3
  55. data/lib/rest-core/util/config.rb +22 -17
  56. data/lib/rest-core/util/vendor.rb +31 -0
  57. data/lib/rest-core/version.rb +1 -1
  58. data/lib/rest-core.rb +5 -0
  59. data/rest-core.gemspec +135 -108
  60. data/test/client/facebook/config/rest-core.yaml +8 -0
  61. data/test/{test_api.rb → client/facebook/test_api.rb} +22 -23
  62. data/test/{test_cache.rb → client/facebook/test_cache.rb} +4 -8
  63. data/test/{test_default.rb → client/facebook/test_default.rb} +6 -10
  64. data/test/client/facebook/test_error.rb +65 -0
  65. data/test/{test_handler.rb → client/facebook/test_handler.rb} +12 -15
  66. data/test/{test_load_config.rb → client/facebook/test_load_config.rb} +6 -9
  67. data/test/{test_misc.rb → client/facebook/test_misc.rb} +15 -18
  68. data/test/{test_oauth.rb → client/facebook/test_oauth.rb} +4 -8
  69. data/test/{test_old.rb → client/facebook/test_old.rb} +16 -18
  70. data/test/{test_page.rb → client/facebook/test_page.rb} +5 -9
  71. data/test/{test_parse.rb → client/facebook/test_parse.rb} +13 -16
  72. data/test/client/facebook/test_serialize.rb +42 -0
  73. data/test/client/facebook/test_timeout.rb +22 -0
  74. data/test/test_oauth1_header.rb +1 -5
  75. metadata +99 -58
  76. data/test/config/rest-core.yaml +0 -7
  77. data/test/test_error.rb +0 -66
  78. data/test/test_serialize.rb +0 -44
  79. data/test/test_timeout.rb +0 -25
@@ -1,11 +1,7 @@
1
1
 
2
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
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
- RestGraph.new(:access_token => 'awesome').url('path', :query => 'str')).
17
- should ==
18
- 'https://graph.facebook.com/path?access_token=awesome&query=str'
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
- RestGraph.new(:site => 'http://nothing.godfat.org/',
32
- :lang => 'zh-tw',
33
- :accept => 'text/plain').get('me').should == {'data' => []}
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
- RestGraph.new.request({:headers => {'X-Forwarded-For' => '127.0.0.1'}},
48
- [:get, 'http://example.com']).
49
- should == {'data' => []}
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
- RestGraph.new(:auto_decode => false).
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 = RestGraph.new(:auto_decode => false, :access_token => 'wrong',
66
- :app_id => '1', :secret => '2')
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 = RestGraph.new(:auto_decode => true)
79
- rg.get('woot', {}, :auto_decode => false).should == 'bad json'
80
- rg.auto_decode.should == true
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
- RestGraph.new.delete('123').should == []
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
- RestGraph.new(:auto_decode => false).get('search', :q => o).should == 'ok'
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
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 = RestGraph.new(:cache => @cache, :auto_decode => false)
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 = RestGraph.new(:cache => cache)
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
4
+ describe RestCore::Facebook do
9
5
  should 'honor default attributes' do
10
- RestGraph.members.reject{ |name|
6
+ RestCore::Facebook.members.reject{ |name|
11
7
  name.to_s =~ /method$|handler$|detector$/ }.each{ |name|
12
- RestGraph.new.send(name).should ==
13
- RestGraph.new.send("default_#{name}")
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 = RestGraph.dup
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
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 = RestGraph.new(:log_method => lambda{ |s| logger << [s] })
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
- RestGraph.new(:error_handler => @id).get('me').should == @error_hash
34
+ RestCore::Facebook.new(:error_handler => @id).get('me').
35
+ should.eq @error_hash
39
36
  end
40
37
 
41
- should 'raise ::RestGraph::Error in default error_handler' do
38
+ should 'raise ::RestCore::Facebook::Error in default error_handler' do
42
39
  begin
43
- RestGraph.new.get('me')
44
- rescue ::RestGraph::Error => e
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
- RestGraph.new(:error_handler => @id).fql(@bad_fql_query).
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 ::RestGraph::Error in default error_handler' do
73
+ should 'raise ::RestCore::Facebook::Error in default error_handler' do
77
74
  begin
78
- RestGraph.new.fql(@bad_fql_query)
79
- rescue ::RestGraph::Error => e
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
- if respond_to?(:require_relative, true)
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 = RestGraph.dup
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.default_auto_decode.should == false
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
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
- RestGraph.new(:access_token => '1').authorized?.should == true
16
- RestGraph.new(:access_token => nil).authorized?.should == false
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 = RestGraph.new
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 = RestGraph.new(:accept => 'text/html',
29
- :lang => 'zh-tw')
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 = RestGraph.new
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 = RestGraph.new(:access_token => 'token')
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 = RestGraph.new(:access_token => 'token')
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 = RestGraph.new(:auto_decode => true)
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 = RestGraph.new(:auto_decode => false)
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
- RestGraph.new(:auto_decode => false).attributes.keys.map(&:to_s).sort.
73
- should == RestGraph.members.map(&:to_s).sort
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
4
+ describe RestCore::Facebook do
9
5
  before do
10
- @rg = RestGraph.new(:app_id => '29', :secret => '18')
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
- RestGraph.new(:access_token => 'do not use me').authorize_url.
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
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
- RestGraph.new.fql(fql).should == []
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
- RestGraph.new(:access_token => token).fql(fql).should == []
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
- RestGraph.new.fql_multi(:f0 => f0, :f1 => f1).should == []
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
- RestGraph.new(:cache => (cache = {})).fql(query, {}, :post => true).
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
- RestGraph.new(:cache => cache).fql(query, {}, :post => true).
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
- RestGraph.new(:cache => cache).fql(query.upcase, {}, :post => true)
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
- RestGraph.new(:cache => cache).fql(query).
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
- RestGraph.new.old_rest('notes.create', {}, :auto_decode => false).
90
- should == body
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
- RestGraph.new(:app_id => 'id',
101
- :secret => 'di').
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
- RestGraph.new(:app_id => '123', :secret => 's').
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
- if respond_to?(:require_relative, true)
3
- require_relative 'common'
4
- else
5
- require File.dirname(__FILE__) + '/common'
6
- end
2
+ require 'rest-core/test'
7
3
 
8
- describe RestGraph do
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 = RestGraph.new(:site => '', :cache => false)
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 = RestGraph.new(:site => '', :cache => false)
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 = RestGraph.new(:site => '', :cache => false)
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']}