rest-more 3.2.0 → 3.3.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.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/lib/rest-core/client/dropbox.rb +4 -5
- data/lib/rest-core/client/facebook.rb +6 -7
- data/lib/rest-core/client/github.rb +5 -6
- data/lib/rest-core/client/instagram.rb +4 -5
- data/lib/rest-core/client/linkedin.rb +5 -6
- data/lib/rest-core/client/stackexchange.rb +5 -6
- data/lib/rest-core/client/twitter.rb +4 -5
- data/lib/rest-more/version.rb +1 -1
- data/rest-more.gemspec +7 -7
- data/task/gemgem.rb +1 -5
- data/test/dropbox/test_dropbox.rb +2 -2
- data/test/facebook/test_api.rb +8 -8
- data/test/facebook/test_default.rb +2 -2
- data/test/facebook/test_error.rb +3 -3
- data/test/facebook/test_handler.rb +5 -5
- data/test/facebook/test_misc.rb +8 -8
- data/test/facebook/test_oauth.rb +3 -3
- data/test/facebook/test_old.rb +5 -5
- data/test/facebook/test_page.rb +3 -3
- data/test/facebook/test_parse.rb +11 -12
- data/test/facebook/test_serialize.rb +2 -2
- data/test/facebook/test_timeout.rb +2 -2
- data/test/github/test_github.rb +1 -1
- data/test/instagram/test_instagram.rb +3 -3
- data/test/stackexchange/test_stackexchange.rb +1 -1
- data/test/twitter/test_twitter.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b39d49bb082449d7cc14d9c296b5b11b464eefe
|
|
4
|
+
data.tar.gz: c329a58ec85fea8020a2e72b0461da6df5d48651
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f390c57bc49b63ba559056cc1b51d2ca32484a1d5100354084ef89d740b53138029260311b9a8bbb70c644eec70ea53d3fdc3b82e96b75d8852d1376b0e01ad
|
|
7
|
+
data.tar.gz: 94171dcccda4f3e7821da7b009e0ab776b97f115dc0d294656e93fc6b83b1bc7a1557eeb8fb1f61b243d6b7729ab7b73adf848b2ad5faafc43c2c38711a5c723
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -14,7 +14,7 @@ Gemgem.init(dir) do |s|
|
|
|
14
14
|
s.version = RestMore::VERSION
|
|
15
15
|
s.homepage = 'https://github.com/godfat/rest-more'
|
|
16
16
|
|
|
17
|
-
%w[rest-core].each{ |g| s.add_runtime_dependency(g, '>=3.
|
|
17
|
+
%w[rest-core].each{ |g| s.add_runtime_dependency(g, '>=3.3.0') }
|
|
18
18
|
|
|
19
19
|
# exclude rest-core
|
|
20
20
|
s.files.reject!{ |f| f.start_with?('rest-core/') }
|
|
@@ -15,11 +15,10 @@ module RestCore
|
|
|
15
15
|
'https://www.dropbox.com/1/oauth/authorize'
|
|
16
16
|
|
|
17
17
|
use CommonLogger , nil
|
|
18
|
-
use
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
18
|
+
use ErrorHandler , lambda{ |env| Dropbox::Error.call(env) }
|
|
19
|
+
use ErrorDetectorHttp
|
|
20
|
+
use JsonResponse , true
|
|
21
|
+
use Cache , nil, 600
|
|
23
22
|
end
|
|
24
23
|
end
|
|
25
24
|
|
|
@@ -14,14 +14,13 @@ module RestCore
|
|
|
14
14
|
use Oauth2Query , nil
|
|
15
15
|
|
|
16
16
|
use CommonLogger , nil
|
|
17
|
-
use
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(env[RESPONSE_BODY]['error'] || env[RESPONSE_BODY]['error_code'])}
|
|
17
|
+
use ErrorHandler , lambda{ |env| Facebook::Error.call(env) }
|
|
18
|
+
use ErrorDetector , lambda{ |env|
|
|
19
|
+
env[RESPONSE_BODY].kind_of?(Hash) &&
|
|
20
|
+
(env[RESPONSE_BODY]['error'] || env[RESPONSE_BODY]['error_code'])}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
use JsonResponse , true
|
|
23
|
+
use Cache , nil, 600
|
|
25
24
|
|
|
26
25
|
use Defaults , :old_site => 'https://api.facebook.com/'
|
|
27
26
|
end
|
|
@@ -11,12 +11,11 @@ module RestCore
|
|
|
11
11
|
use Oauth2Query , nil
|
|
12
12
|
|
|
13
13
|
use CommonLogger , nil
|
|
14
|
-
use
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end
|
|
14
|
+
use ErrorHandler , lambda{ |env|
|
|
15
|
+
RuntimeError.new(env[RESPONSE_BODY]['message'])}
|
|
16
|
+
use ErrorDetectorHttp
|
|
17
|
+
use JsonResponse , true
|
|
18
|
+
use Cache , nil, 600
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
21
|
|
|
@@ -12,11 +12,10 @@ module RestCore
|
|
|
12
12
|
use Oauth2Query , nil
|
|
13
13
|
|
|
14
14
|
use CommonLogger , nil
|
|
15
|
-
use
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end
|
|
15
|
+
use ErrorHandler , lambda{ |env| RuntimeError.new(env[RESPONSE_BODY])}
|
|
16
|
+
use ErrorDetectorHttp
|
|
17
|
+
use JsonResponse , true
|
|
18
|
+
use Cache , nil, 600
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
21
|
|
|
@@ -15,12 +15,11 @@ module RestCore
|
|
|
15
15
|
'https://www.linkedin.com/uas/oauth/authorize'
|
|
16
16
|
|
|
17
17
|
use CommonLogger , nil
|
|
18
|
-
use
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
end
|
|
18
|
+
use ErrorHandler , lambda{ |env|
|
|
19
|
+
RuntimeError.new(env[RESPONSE_BODY]['message'])}
|
|
20
|
+
use ErrorDetectorHttp
|
|
21
|
+
use JsonResponse , true
|
|
22
|
+
use Cache , nil, 600
|
|
24
23
|
end
|
|
25
24
|
end
|
|
26
25
|
|
|
@@ -12,12 +12,11 @@ module RestCore
|
|
|
12
12
|
use Oauth2Query , nil
|
|
13
13
|
|
|
14
14
|
use CommonLogger , nil
|
|
15
|
-
use
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
15
|
+
use ErrorHandler , lambda{ |env|
|
|
16
|
+
RuntimeError.new(env[RESPONSE_BODY]['error_message'])}
|
|
17
|
+
use ErrorDetectorHttp
|
|
18
|
+
use JsonResponse , true
|
|
19
|
+
use Cache , nil, 600
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
|
|
@@ -13,11 +13,10 @@ module RestCore
|
|
|
13
13
|
'oauth/request_token', 'oauth/access_token', 'oauth/authorize'
|
|
14
14
|
|
|
15
15
|
use CommonLogger , nil
|
|
16
|
-
use
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
16
|
+
use ErrorHandler , lambda{ |env| Twitter::Error.call(env) }
|
|
17
|
+
use ErrorDetectorHttp
|
|
18
|
+
use JsonResponse , true
|
|
19
|
+
use Cache , nil, 600
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
|
data/lib/rest-more/version.rb
CHANGED
data/rest-more.gemspec
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: rest-more 3.
|
|
2
|
+
# stub: rest-more 3.3.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "rest-more"
|
|
6
|
-
s.version = "3.
|
|
6
|
+
s.version = "3.3.0"
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib"]
|
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
|
11
|
-
s.date = "2014-
|
|
11
|
+
s.date = "2014-08-25"
|
|
12
12
|
s.description = "Various REST clients such as Facebook and Twitter built with [rest-core][].\n\n[rest-core]: https://github.com/godfat/rest-core"
|
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
|
14
14
|
s.executables = ["rib-rest-core"]
|
|
@@ -83,7 +83,7 @@ Gem::Specification.new do |s|
|
|
|
83
83
|
"test/twitter/test_twitter.rb"]
|
|
84
84
|
s.homepage = "https://github.com/godfat/rest-more"
|
|
85
85
|
s.licenses = ["Apache License 2.0"]
|
|
86
|
-
s.rubygems_version = "2.
|
|
86
|
+
s.rubygems_version = "2.4.1"
|
|
87
87
|
s.summary = "Various REST clients such as Facebook and Twitter built with [rest-core][]."
|
|
88
88
|
s.test_files = [
|
|
89
89
|
"test/dropbox/test_dropbox.rb",
|
|
@@ -107,11 +107,11 @@ Gem::Specification.new do |s|
|
|
|
107
107
|
s.specification_version = 4
|
|
108
108
|
|
|
109
109
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
110
|
-
s.add_runtime_dependency(%q<rest-core>, [">= 3.
|
|
110
|
+
s.add_runtime_dependency(%q<rest-core>, [">= 3.3.0"])
|
|
111
111
|
else
|
|
112
|
-
s.add_dependency(%q<rest-core>, [">= 3.
|
|
112
|
+
s.add_dependency(%q<rest-core>, [">= 3.3.0"])
|
|
113
113
|
end
|
|
114
114
|
else
|
|
115
|
-
s.add_dependency(%q<rest-core>, [">= 3.
|
|
115
|
+
s.add_dependency(%q<rest-core>, [">= 3.3.0"])
|
|
116
116
|
end
|
|
117
117
|
end
|
data/task/gemgem.rb
CHANGED
|
@@ -34,7 +34,7 @@ module Gemgem
|
|
|
34
34
|
s.executables = bin_files
|
|
35
35
|
end
|
|
36
36
|
spec_create.call(spec)
|
|
37
|
-
spec.homepage
|
|
37
|
+
spec.homepage ||= "https://github.com/godfat/#{spec.name}"
|
|
38
38
|
self.spec = spec
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -227,10 +227,6 @@ end # of gem namespace
|
|
|
227
227
|
desc 'Run tests'
|
|
228
228
|
task :test do
|
|
229
229
|
next if Gemgem.test_files.empty?
|
|
230
|
-
|
|
231
|
-
require 'bacon'
|
|
232
|
-
Bacon.extend(Bacon::TestUnitOutput)
|
|
233
|
-
Bacon.summary_on_exit
|
|
234
230
|
Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
|
|
235
231
|
end
|
|
236
232
|
|
|
@@ -6,7 +6,7 @@ describe RC::Dropbox do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'get right' do
|
|
10
10
|
stub_request(:get, 'https://api.dropbox.com/1/account/info').
|
|
11
11
|
to_return(:body => '{"status": "OK"}')
|
|
12
12
|
|
|
@@ -24,7 +24,7 @@ describe RC::Dropbox do
|
|
|
24
24
|
WebMock.reset!
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
would 'raise exception when encountering error' do
|
|
28
28
|
[401, 402, 403].each{ |status| check(status, RC::Dropbox::Error) }
|
|
29
29
|
[500, 502, 503].each{ |status| check(status, RC::Dropbox::Error::
|
|
30
30
|
ServerError) }
|
data/test/facebook/test_api.rb
CHANGED
|
@@ -6,13 +6,13 @@ describe RC::Facebook do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'generate correct url' do
|
|
10
10
|
RC::Facebook.new(:access_token => 'awesome').
|
|
11
11
|
url('path', :query => 'str').should.eq \
|
|
12
12
|
'https://graph.facebook.com/path?access_token=awesome&query=str'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
would 'request to correct server' do
|
|
16
16
|
stub_request(:get, 'http://nothing.godfat.org/me').with(
|
|
17
17
|
:headers => {'Accept' => 'text/plain',
|
|
18
18
|
'Accept-Language' => 'zh-tw',
|
|
@@ -26,7 +26,7 @@ describe RC::Facebook do
|
|
|
26
26
|
get('me').should.eq({'data' => []})
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
would 'pass custom headers' do
|
|
30
30
|
stub_request(:get, 'http://example.com/').with(
|
|
31
31
|
:headers => {'Accept' => 'application/json',
|
|
32
32
|
'Accept-Language' => 'en-us',
|
|
@@ -40,7 +40,7 @@ describe RC::Facebook do
|
|
|
40
40
|
should.eq({'data' => []})
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
would 'post right' do
|
|
44
44
|
stub_request(:post, 'https://graph.facebook.com/feed/me').
|
|
45
45
|
with(:body => 'message=hi%20there').to_return(:body => 'ok')
|
|
46
46
|
|
|
@@ -48,7 +48,7 @@ describe RC::Facebook do
|
|
|
48
48
|
post('feed/me', :message => 'hi there').should == 'ok'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
would 'use secret_access_token' do
|
|
52
52
|
stub_request(:get,
|
|
53
53
|
'https://graph.facebook.com/me?access_token=1|2').
|
|
54
54
|
to_return(:body => 'ok')
|
|
@@ -63,7 +63,7 @@ describe RC::Facebook do
|
|
|
63
63
|
'/me?access_token=1%7C2'
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
would 'suppress auto-decode in an api call' do
|
|
67
67
|
stub_request(:get, 'https://graph.facebook.com/woot').
|
|
68
68
|
to_return(:body => 'bad json')
|
|
69
69
|
|
|
@@ -72,7 +72,7 @@ describe RC::Facebook do
|
|
|
72
72
|
rg.json_response.should == true
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
would 'not raise exception when encountering error' do
|
|
76
76
|
[500, 401, 402, 403].each{ |status|
|
|
77
77
|
stub_request(:delete, 'https://graph.facebook.com/123').to_return(
|
|
78
78
|
:body => '[]', :status => status)
|
|
@@ -81,7 +81,7 @@ describe RC::Facebook do
|
|
|
81
81
|
}
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
would 'convert query to string' do
|
|
85
85
|
o = Object.new
|
|
86
86
|
def o.to_s; 'i am mock'; end
|
|
87
87
|
stub_request(:get, "https://graph.facebook.com/search?q=i%20am%20mock").
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require 'rest-more/test'
|
|
3
3
|
|
|
4
4
|
describe RC::Facebook do
|
|
5
|
-
|
|
5
|
+
would 'honor default attributes' do
|
|
6
6
|
RC::Facebook.members.reject{ |name|
|
|
7
7
|
name.to_s =~ /method$|handler$|detector$/ }.each{ |name|
|
|
8
8
|
RC::Facebook.new.send(name).should ==
|
|
@@ -10,7 +10,7 @@ describe RC::Facebook do
|
|
|
10
10
|
}
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
would 'use module to override default attributes' do
|
|
14
14
|
klass = RC::Facebook.dup
|
|
15
15
|
klass.send(:include, Module.new do
|
|
16
16
|
def default_app_id
|
data/test/facebook/test_error.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe RC::Facebook::Error do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'have the right ancestors' do
|
|
10
10
|
RC::Facebook::Error::AccessToken.should.lt RC::Facebook::Error
|
|
11
11
|
|
|
12
12
|
RC::Facebook::Error::InvalidAccessToken.should.lt \
|
|
@@ -22,7 +22,7 @@ describe RC::Facebook::Error do
|
|
|
22
22
|
RC::REQUEST_QUERY => {}}
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
would 'parse right' do
|
|
26
26
|
%w[OAuthInvalidTokenException OAuthException].each{ |type|
|
|
27
27
|
RC::Facebook::Error.call(error2env('error' => {'type' => type})).
|
|
28
28
|
should.kind_of?(RC::Facebook::Error::InvalidAccessToken)
|
|
@@ -52,7 +52,7 @@ describe RC::Facebook::Error do
|
|
|
52
52
|
error.should .kind_of?(RC::Facebook::Error)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
would 'nuke cache upon errors' do
|
|
56
56
|
stub_request(:get, 'https://graph.facebook.com/me').
|
|
57
57
|
to_return(:body => '{"error":"wrong"}').times(2)
|
|
58
58
|
|
|
@@ -7,7 +7,7 @@ describe RC::Facebook do
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
describe 'log method' do
|
|
10
|
-
|
|
10
|
+
would 'log whenever doing network request' do
|
|
11
11
|
stub_request(:get, 'https://graph.facebook.com/me').
|
|
12
12
|
to_return(:body => '{}')
|
|
13
13
|
|
|
@@ -29,12 +29,12 @@ describe RC::Facebook do
|
|
|
29
29
|
to_return(:body => @error)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
would 'call error_handler if error occurred' do
|
|
33
33
|
RC::Facebook.new(:error_handler => @id).get('me').
|
|
34
34
|
should.eq @error_hash
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
would 'raise ::RC::Facebook::Error in default error_handler' do
|
|
38
38
|
begin
|
|
39
39
|
RC::Facebook.new.get('me').tap{}
|
|
40
40
|
rescue ::RC::Facebook::Error => e
|
|
@@ -65,12 +65,12 @@ describe RC::Facebook do
|
|
|
65
65
|
stub_request(:get, bad_fql_request).to_return(:body => @fql_error)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
would 'call error_handler if error occurred' do
|
|
69
69
|
RC::Facebook.new(:error_handler => @id).fql(@bad_fql_query).
|
|
70
70
|
should.eq @fql_error_hash
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
would 'raise ::RC::Facebook::Error in default error_handler' do
|
|
74
74
|
begin
|
|
75
75
|
RC::Facebook.new.fql(@bad_fql_query).tap{}
|
|
76
76
|
rescue ::RC::Facebook::Error => e
|
data/test/facebook/test_misc.rb
CHANGED
|
@@ -6,12 +6,12 @@ describe RC::Facebook do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'return true in authorized? if there is an access_token' do
|
|
10
10
|
RC::Facebook.new(:access_token => '1').authorized?.should.eq true
|
|
11
11
|
RC::Facebook.new(:access_token => nil).authorized?.should.eq false
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
would 'treat oauth_token as access_token as well' do
|
|
15
15
|
rg = RC::Facebook.new
|
|
16
16
|
hate_facebook = 'why the hell two different name?'
|
|
17
17
|
rg.data['oauth_token'] = hate_facebook
|
|
@@ -19,7 +19,7 @@ describe RC::Facebook do
|
|
|
19
19
|
rg.access_token.should.eq hate_facebook
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
would 'build correct headers' do
|
|
23
23
|
rg = RC::Facebook.new(:accept => 'text/html',
|
|
24
24
|
:lang => 'zh-tw')
|
|
25
25
|
|
|
@@ -30,14 +30,14 @@ describe RC::Facebook do
|
|
|
30
30
|
}
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
would 'create access_token in query string' do
|
|
34
34
|
rg = RC::Facebook.new(:access_token => 'token')
|
|
35
35
|
rg.dry.call(rg.send(:build_env)){ |res|
|
|
36
36
|
res[RC::REQUEST_QUERY].should.eq({'access_token' => 'token'})
|
|
37
37
|
}
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
would 'build correct query string' do
|
|
41
41
|
rg = RC::Facebook.new(:access_token => 'token')
|
|
42
42
|
rg.url('', :message => 'hi!!').
|
|
43
43
|
should.eq "#{rg.site}?access_token=token&message=hi%21%21"
|
|
@@ -47,19 +47,19 @@ describe RC::Facebook do
|
|
|
47
47
|
should.eq "#{rg.site}?message=hi%21%21&subject=%28%26oh%26%29"
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
would 'auto decode json' do
|
|
51
51
|
rg = RC::Facebook.new(:json_response => true)
|
|
52
52
|
stub_request(:get, rg.site).to_return(:body => '[]')
|
|
53
53
|
rg.get('').should.eq []
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
would 'not auto decode json' do
|
|
57
57
|
rg = RC::Facebook.new(:json_response => false)
|
|
58
58
|
stub_request(:get, rg.site).to_return(:body => '[]')
|
|
59
59
|
rg.get('').should.eq '[]'
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
would 'give attributes' do
|
|
63
63
|
RC::Facebook.new(:json_response => false).attributes.
|
|
64
64
|
keys.map(&:to_s).sort.should.eq \
|
|
65
65
|
RC::Facebook.members.map(&:to_s).sort
|
data/test/facebook/test_oauth.rb
CHANGED
|
@@ -11,13 +11,13 @@ describe RC::Facebook do
|
|
|
11
11
|
WebMock.reset!
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
would 'return correct oauth url' do
|
|
15
15
|
@rg.authorize_url(:redirect_uri => @uri).
|
|
16
16
|
should.eq 'https://www.facebook.com/dialog/oauth?' \
|
|
17
17
|
'client_id=29&redirect_uri=http%3A%2F%2Fzzz.tw'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
would 'do authorizing and parse result and save it in data' do
|
|
21
21
|
stub_request(:post, 'https://graph.facebook.com/oauth/access_token'). \
|
|
22
22
|
with(:body => {'client_id' => '29' ,
|
|
23
23
|
'client_secret' => '18' ,
|
|
@@ -32,7 +32,7 @@ describe RC::Facebook do
|
|
|
32
32
|
@rg.data.should.eq result
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
would 'not append access_token in authorize_url even presented' do
|
|
36
36
|
RC::Facebook.new(:access_token => 'do not use me').authorize_url.
|
|
37
37
|
should.eq 'https://www.facebook.com/dialog/oauth'
|
|
38
38
|
end
|
data/test/facebook/test_old.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe RC::Facebook do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'do fql query with/without access_token' do
|
|
10
10
|
fql = 'SELECT name FROM likes where id="123"'
|
|
11
11
|
query = "format=json&query=#{RC::Middleware.escape(fql)}"
|
|
12
12
|
stub_request(:get, "https://api.facebook.com/method/fql.query?#{query}").
|
|
@@ -22,7 +22,7 @@ describe RC::Facebook do
|
|
|
22
22
|
RC::Facebook.new(:access_token => token).fql(fql).should.eq []
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
would 'do fql.mutilquery correctly' do
|
|
26
26
|
f0 = 'SELECT display_name FROM application WHERE app_id="233082465238"'
|
|
27
27
|
f1 = 'SELECT display_name FROM application WHERE app_id="110225210740"'
|
|
28
28
|
f0q, f1q = "\"#{f0.gsub('"', '\\"')}\"", "\"#{f1.gsub('"', '\\"')}\""
|
|
@@ -45,7 +45,7 @@ describe RC::Facebook do
|
|
|
45
45
|
RC::Facebook.new.fql_multi(:f0 => f0, :f1 => f1).should.eq []
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
would 'do facebook old rest api' do
|
|
49
49
|
body = 'hate facebook inconsistent'
|
|
50
50
|
stub_request(:get,
|
|
51
51
|
'https://api.facebook.com/method/notes.create?format=json').
|
|
@@ -55,7 +55,7 @@ describe RC::Facebook do
|
|
|
55
55
|
old_rest('notes.create', {}, :json_response => false).should.eq body
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
would 'exchange sessions for access token' do
|
|
59
59
|
stub_request(:post,
|
|
60
60
|
'https://graph.facebook.com/oauth/exchange_sessions?' \
|
|
61
61
|
'type=client_cred&client_id=id&client_secret=di&' \
|
|
@@ -67,7 +67,7 @@ describe RC::Facebook do
|
|
|
67
67
|
first['access_token'].should.eq 'bogus'
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
would 'use an secret access_token' do
|
|
71
71
|
stub_request(:get,
|
|
72
72
|
'https://api.facebook.com/method/admin.getAppProperties?' \
|
|
73
73
|
'access_token=123%7Cs&format=json&properties=app_id'
|
data/test/facebook/test_page.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe RC::Facebook do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'get the next/prev page' do
|
|
10
10
|
f = RC::Facebook.new(:site => '', :cache => false)
|
|
11
11
|
%w[next previous].each{ |type|
|
|
12
12
|
kind = "#{type}_page"
|
|
@@ -19,7 +19,7 @@ describe RC::Facebook do
|
|
|
19
19
|
}
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
would 'merge all pages into one' do
|
|
23
23
|
f = RC::Facebook.new(:site => '', :cache => false)
|
|
24
24
|
%w[next previous].each{ |type|
|
|
25
25
|
kind = "#{type}_page"
|
|
@@ -47,7 +47,7 @@ describe RC::Facebook do
|
|
|
47
47
|
}
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
would 'for_pages with callback' do
|
|
51
51
|
f = RC::Facebook.new(:site => '', :cache => false)
|
|
52
52
|
%w[next previous].each{ |type|
|
|
53
53
|
kind = "#{type}_page"
|
data/test/facebook/test_parse.rb
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
require 'rest-more/test'
|
|
3
3
|
|
|
4
4
|
describe RC::Facebook do
|
|
5
|
-
|
|
6
|
-
should 'return nil if parse error, but not when call data directly' do
|
|
5
|
+
would 'return nil if parse error, but not when call data directly' do
|
|
7
6
|
rg = RC::Facebook.new
|
|
8
7
|
rg.parse_cookies!({}).should.eq nil
|
|
9
8
|
rg.data .should.eq({})
|
|
10
9
|
end
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
would 'parse if fbs contains json as well' do
|
|
13
12
|
algorithm = 'HMAC-SHA256'
|
|
14
13
|
user = '{"country"=>"us", "age"=>{"min"=>21}}'
|
|
15
14
|
data = {'algorithm' => algorithm, 'user' => user}
|
|
@@ -18,7 +17,7 @@ describe RC::Facebook do
|
|
|
18
17
|
rg.parse_fbs!("\"#{rg.fbs}\"").should.eq data.merge('sig' => sig)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
would 'extract correct access_token or fail checking sig' do
|
|
22
21
|
access_token = '1|2-5|f.'
|
|
23
22
|
app_id = '1829'
|
|
24
23
|
secret = app_id.reverse
|
|
@@ -54,13 +53,13 @@ describe RC::Facebook do
|
|
|
54
53
|
check.call(nil, "\"#{fbs}\"")
|
|
55
54
|
end
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
would 'not pass if there is no secret, prevent from forgery' do
|
|
58
57
|
rg = RC::Facebook.new
|
|
59
58
|
rg.parse_fbs!('"feed=me&sig=bddd192cf27f22c05f61c8bea24fa4b7"').
|
|
60
59
|
should.eq nil
|
|
61
60
|
end
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
would 'parse json correctly' do
|
|
64
63
|
rg = RC::Facebook.new
|
|
65
64
|
|
|
66
65
|
rg.parse_json!('bad json') .should.eq nil
|
|
@@ -87,11 +86,11 @@ describe RC::Facebook do
|
|
|
87
86
|
"#{encode(sig)}.#{json_encoded}"
|
|
88
87
|
end
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
would 'parse invalid' do
|
|
91
90
|
RC::Facebook.new.parse_signed_request!('bad').should.eq nil
|
|
92
91
|
end
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
would 'parse' do
|
|
95
94
|
secret = 'aloha'
|
|
96
95
|
rg = RC::Facebook.new(:secret => secret)
|
|
97
96
|
rg.parse_signed_request!(setup_sr(secret, {'ooh' => 'dir',
|
|
@@ -105,7 +104,7 @@ describe RC::Facebook do
|
|
|
105
104
|
rg.data .should.eq({})
|
|
106
105
|
end
|
|
107
106
|
|
|
108
|
-
|
|
107
|
+
would 'fbsr and cookies with fbsr' do
|
|
109
108
|
secret = 'lulala'
|
|
110
109
|
code = 'lalalu'
|
|
111
110
|
access_token = 'lololo'
|
|
@@ -136,13 +135,13 @@ describe RC::Facebook do
|
|
|
136
135
|
end
|
|
137
136
|
end
|
|
138
137
|
|
|
139
|
-
|
|
138
|
+
would 'generate correct fbs with correct sig' do
|
|
140
139
|
RC::Facebook.new(:access_token => 'fake', :secret => 's').fbs.
|
|
141
140
|
should.eq \
|
|
142
141
|
"access_token=fake&sig=#{Digest::MD5.hexdigest('access_token=fakes')}"
|
|
143
142
|
end
|
|
144
143
|
|
|
145
|
-
|
|
144
|
+
would 'parse fbs from facebook response which lacks sig...' do
|
|
146
145
|
rg = RC::Facebook.new(:access_token => 'a', :secret => 'z')
|
|
147
146
|
rg.parse_fbs!(rg.fbs) .should.kind_of?(Hash)
|
|
148
147
|
rg.data.empty?.should.eq false
|
|
@@ -150,7 +149,7 @@ describe RC::Facebook do
|
|
|
150
149
|
rg.data.empty?.should.eq true
|
|
151
150
|
end
|
|
152
151
|
|
|
153
|
-
|
|
152
|
+
would 'generate correct fbs with additional parameters' do
|
|
154
153
|
rg = RC::Facebook.new(:access_token => 'a', :secret => 'z')
|
|
155
154
|
rg.data['expires'] = '1234'
|
|
156
155
|
rg.parse_fbs!(rg.fbs).should.kind_of?(Hash)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require 'rest-more/test'
|
|
3
3
|
|
|
4
4
|
describe RC::Facebook do
|
|
5
|
-
|
|
5
|
+
would 'be serialized with lighten' do
|
|
6
6
|
require 'yaml'
|
|
7
7
|
[YAML, Marshal].each{ |engine|
|
|
8
8
|
test = lambda{ |obj| engine.load(engine.dump(obj)) }
|
|
@@ -15,7 +15,7 @@ describe RC::Facebook do
|
|
|
15
15
|
}
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
would 'lighten takes options to change attributes' do
|
|
19
19
|
RC::Facebook.new.lighten(:timeout => 100 ).timeout.should.eq 100
|
|
20
20
|
RC::Facebook.new.lighten(:lang => 'zh-TW').lang.should.eq 'zh-TW'
|
|
21
21
|
end
|
|
@@ -7,7 +7,7 @@ describe RC::Facebook do
|
|
|
7
7
|
Muack.verify
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
would 'respect timeout' do
|
|
11
11
|
stub_request(:get, 'https://graph.facebook.com/me').
|
|
12
12
|
to_return(:body => '{}')
|
|
13
13
|
any_instance_of(RC::Timeout::Timer){ |timer|
|
|
@@ -16,7 +16,7 @@ describe RC::Facebook do
|
|
|
16
16
|
RC::Facebook.new.get('me').should.eq({})
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
would 'override timeout' do
|
|
20
20
|
stub_request(:get, 'https://graph.facebook.com/me').
|
|
21
21
|
to_return(:body => 'true')
|
|
22
22
|
mock(RC::Timeout::Timer).new(99, is_a(Timeout::Error))
|
data/test/github/test_github.rb
CHANGED
|
@@ -17,13 +17,13 @@ describe RC::Instagram do
|
|
|
17
17
|
client = RC::Instagram.new(:client_id => 'Z', :client_secret => 'S',
|
|
18
18
|
:access_token => 'X')
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
would 'have correct authorize url' do
|
|
21
21
|
client.authorize_url.should.eq \
|
|
22
22
|
'https://api.instagram.com/oauth/authorize?' \
|
|
23
23
|
'client_id=Z&response_type=code'
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
would 'authorize! and get the access token' do
|
|
27
27
|
stub_request(:post, 'https://api.instagram.com/oauth/access_token').
|
|
28
28
|
with(:body => {'client_id' => 'Z', 'client_secret' => 'S',
|
|
29
29
|
'grant_type' => 'authorization_code', 'code' => 'C'}).
|
|
@@ -37,7 +37,7 @@ describe RC::Instagram do
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
would 'retrieve user profile based on username' do
|
|
41
41
|
stub_request(:get, 'https://api.instagram.com/v1/users/search?' \
|
|
42
42
|
'client_id=Z&q=restmore').
|
|
43
43
|
to_return(:body => json)
|
|
@@ -6,7 +6,7 @@ describe RC::Twitter do
|
|
|
6
6
|
WebMock.reset!
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
would 'get right' do
|
|
10
10
|
stub_request(:get,
|
|
11
11
|
'https://api.twitter.com/1.1/account/verify_credentials.json').
|
|
12
12
|
to_return(:body => '{"status": "OK"}')
|
|
@@ -25,7 +25,7 @@ describe RC::Twitter do
|
|
|
25
25
|
WebMock.reset!
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
would 'raise exception when encountering error' do
|
|
29
29
|
[401, 402, 403].each{ |status| check(status, RestCore::Twitter::Error) }
|
|
30
30
|
[500, 502, 503].each{ |status| check(status, RestCore::Twitter::Error::
|
|
31
31
|
ServerError) }
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rest-more
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lin Jen-Shin (godfat)
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-core
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 3.
|
|
19
|
+
version: 3.3.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 3.
|
|
26
|
+
version: 3.3.0
|
|
27
27
|
description: |-
|
|
28
28
|
Various REST clients such as Facebook and Twitter built with [rest-core][].
|
|
29
29
|
|
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
123
|
version: '0'
|
|
124
124
|
requirements: []
|
|
125
125
|
rubyforge_project:
|
|
126
|
-
rubygems_version: 2.
|
|
126
|
+
rubygems_version: 2.4.1
|
|
127
127
|
signing_key:
|
|
128
128
|
specification_version: 4
|
|
129
129
|
summary: Various REST clients such as Facebook and Twitter built with [rest-core][].
|