rest-more 2.0.4 → 3.0.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 +6 -6
- data/.gitignore +1 -2
- data/.gitmodules +1 -1
- data/.travis.yml +5 -4
- data/CHANGES.md +1 -1
- data/Gemfile +16 -10
- data/README.md +209 -44
- data/Rakefile +11 -22
- data/doc/{tutorial/facebook.md → facebook.md} +1 -1
- data/example/multi.rb +3 -3
- data/example/rails3/Gemfile +18 -8
- data/example/rails3/app/controllers/application_controller.rb +2 -5
- data/example/rails3/config/application.rb +1 -1
- data/example/rails3/test/functional/application_controller_test.rb +0 -12
- data/example/rails3/test/test_helper.rb +12 -5
- data/example/rails3/test/unit/rails_util_test.rb +1 -6
- data/example/simple.rb +2 -2
- data/lib/rest-core/client/firebase.rb +50 -0
- data/lib/rest-core/client/instagram.rb +59 -0
- data/lib/rest-core/client/linkedin.rb +0 -4
- data/lib/rest-more.rb +8 -6
- data/lib/rest-more/test.rb +0 -11
- data/lib/rest-more/version.rb +1 -1
- data/rest-more.gemspec +20 -17
- data/task/README.md +54 -0
- data/task/gemgem.rb +151 -156
- data/test/dropbox/test_api.rb +1 -1
- data/test/facebook/test_api.rb +6 -7
- data/test/facebook/test_error.rb +1 -1
- data/test/facebook/test_handler.rb +2 -2
- data/test/facebook/test_load_config.rb +1 -1
- data/test/facebook/test_misc.rb +4 -14
- data/test/facebook/test_oauth.rb +1 -1
- data/test/facebook/test_old.rb +1 -1
- data/test/facebook/test_page.rb +4 -5
- data/test/facebook/test_parse.rb +0 -7
- data/test/facebook/test_serialize.rb +1 -1
- data/test/facebook/test_timeout.rb +4 -4
- data/test/instagram/test_api.rb +54 -0
- data/test/twitter/test_api.rb +1 -1
- metadata +26 -23
- data/example/rainbows.rb +0 -67
- data/task/.gitignore +0 -1
data/test/dropbox/test_api.rb
CHANGED
data/test/facebook/test_api.rb
CHANGED
@@ -4,13 +4,12 @@ require 'rest-more/test'
|
|
4
4
|
describe RC::Facebook do
|
5
5
|
after do
|
6
6
|
WebMock.reset!
|
7
|
-
|
7
|
+
Muack.verify
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'generate correct url' do
|
11
|
-
TestHelper.normalize_url(
|
12
11
|
RC::Facebook.new(:access_token => 'awesome').
|
13
|
-
url('path', :query => 'str')
|
12
|
+
url('path', :query => 'str').should.eq \
|
14
13
|
'https://graph.facebook.com/path?access_token=awesome&query=str'
|
15
14
|
end
|
16
15
|
|
@@ -18,8 +17,8 @@ describe RC::Facebook do
|
|
18
17
|
stub_request(:get, 'http://nothing.godfat.org/me').with(
|
19
18
|
:headers => {'Accept' => 'text/plain',
|
20
19
|
'Accept-Language' => 'zh-tw',
|
21
|
-
'Accept-Encoding' =>
|
22
|
-
'User-Agent' => 'Ruby'
|
20
|
+
'Accept-Encoding' => /^gzip, ?deflate$/, # this is by ruby
|
21
|
+
'User-Agent' => 'Ruby' # this is by ruby
|
23
22
|
}).to_return(:body => '{"data": []}')
|
24
23
|
|
25
24
|
RC::Facebook.new(:site => 'http://nothing.godfat.org/',
|
@@ -32,8 +31,8 @@ describe RC::Facebook do
|
|
32
31
|
stub_request(:get, 'http://example.com/').with(
|
33
32
|
:headers => {'Accept' => 'application/json',
|
34
33
|
'Accept-Language' => 'en-us',
|
35
|
-
'Accept-Encoding' =>
|
36
|
-
'User-Agent' => 'Ruby',
|
34
|
+
'Accept-Encoding' => /^gzip, ?deflate$/, # this is by ruby
|
35
|
+
'User-Agent' => 'Ruby', # this is by ruby
|
37
36
|
'X-Forwarded-For' => '127.0.0.1',
|
38
37
|
}).to_return(:body => '{"data": []}')
|
39
38
|
|
data/test/facebook/test_error.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rest-more/test'
|
|
4
4
|
describe RC::Facebook do
|
5
5
|
after do
|
6
6
|
WebMock.reset!
|
7
|
-
|
7
|
+
Muack.verify
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'log method' do
|
@@ -16,7 +16,7 @@ describe RC::Facebook do
|
|
16
16
|
rg = RC::Facebook.new(:log_method => lambda{ |s| logger << [s] })
|
17
17
|
rg.get('me').tap{}
|
18
18
|
|
19
|
-
logger.size.should.eq
|
19
|
+
logger.size.should.eq 1
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/test/facebook/test_misc.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rest-more/test'
|
|
4
4
|
describe RC::Facebook do
|
5
5
|
after do
|
6
6
|
WebMock.reset!
|
7
|
-
|
7
|
+
Muack.verify
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'return true in authorized? if there is an access_token' do
|
@@ -31,30 +31,20 @@ describe RC::Facebook do
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
should 'build empty query string' do
|
35
|
-
# TODO: WTF is this trying to test!?
|
36
|
-
rg = RC::Facebook.new
|
37
|
-
rg.dry.call(rg.send(:build_env)){ |res|
|
38
|
-
(res[RC::REQUEST_QUERY] || {}).should.eq({})
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
34
|
should 'create access_token in query string' do
|
43
35
|
rg = RC::Facebook.new(:access_token => 'token')
|
44
36
|
rg.dry.call(rg.send(:build_env)){ |res|
|
45
|
-
|
46
|
-
(res[RC::REQUEST_QUERY] || {}).should.eq({'access_token' => 'token'})
|
37
|
+
res[RC::REQUEST_QUERY].should.eq({'access_token' => 'token'})
|
47
38
|
}
|
48
39
|
end
|
49
40
|
|
50
41
|
should 'build correct query string' do
|
51
42
|
rg = RC::Facebook.new(:access_token => 'token')
|
52
|
-
|
43
|
+
rg.url('', :message => 'hi!!').
|
53
44
|
should.eq "#{rg.site}?access_token=token&message=hi%21%21"
|
54
45
|
|
55
46
|
rg.access_token = nil
|
56
|
-
|
57
|
-
:subject => '(&oh&)')).
|
47
|
+
rg.url('', :message => 'hi!!', :subject => '(&oh&)').
|
58
48
|
should.eq "#{rg.site}?message=hi%21%21&subject=%28%26oh%26%29"
|
59
49
|
end
|
60
50
|
|
data/test/facebook/test_oauth.rb
CHANGED
@@ -12,7 +12,7 @@ describe RC::Facebook do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
should '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
|
data/test/facebook/test_old.rb
CHANGED
data/test/facebook/test_page.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rest-more/test'
|
|
4
4
|
describe RC::Facebook do
|
5
5
|
after do
|
6
6
|
WebMock.reset!
|
7
|
-
|
7
|
+
Muack.verify
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'get the next/prev page' do
|
@@ -26,9 +26,9 @@ describe RC::Facebook do
|
|
26
26
|
kind = "#{type}_page"
|
27
27
|
data = {'paging' => {type => 'zzz'}, 'data' => ['z']}
|
28
28
|
|
29
|
-
f.for_pages(data, -1, {}, kind).should
|
30
|
-
f.for_pages(data, 0, {}, kind).should
|
31
|
-
f.for_pages(data, 1, {}, kind).should
|
29
|
+
f.for_pages(data, -1, {}, kind).should.eq nil
|
30
|
+
f.for_pages(data, 0, {}, kind).should.eq nil
|
31
|
+
f.for_pages(data, 1, {}, kind).should.eq data
|
32
32
|
|
33
33
|
(2..4).each{ |pages|
|
34
34
|
# merge data
|
@@ -49,7 +49,6 @@ describe RC::Facebook do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
should 'for_pages with callback' do
|
52
|
-
t = Thread.current
|
53
52
|
f = RC::Facebook.new(:site => '', :cache => false)
|
54
53
|
%w[next previous].each{ |type|
|
55
54
|
kind = "#{type}_page"
|
data/test/facebook/test_parse.rb
CHANGED
@@ -134,13 +134,6 @@ describe RC::Facebook do
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
should 'fallback to ruby-hmac if Digest.new raise an runtime error' do
|
138
|
-
key, data = 'top', 'secret'
|
139
|
-
digest = OpenSSL::HMAC.digest('sha256', key, data)
|
140
|
-
mock(OpenSSL::HMAC).digest('sha256', key, data){ raise 'boom' }
|
141
|
-
RC::Hmac.sha256(key, data).should.eq digest
|
142
|
-
end
|
143
|
-
|
144
137
|
should 'generate correct fbs with correct sig' do
|
145
138
|
RC::Facebook.new(:access_token => 'fake', :secret => 's').fbs.
|
146
139
|
should.eq \
|
@@ -4,14 +4,14 @@ require 'rest-more/test'
|
|
4
4
|
describe RC::Facebook do
|
5
5
|
after do
|
6
6
|
WebMock.reset!
|
7
|
-
|
7
|
+
Muack.verify
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'respect timeout' do
|
11
11
|
stub_request(:get, 'https://graph.facebook.com/me').
|
12
12
|
to_return(:body => '{}')
|
13
|
-
any_instance_of(RC::Timeout::
|
14
|
-
mock
|
13
|
+
any_instance_of(RC::Timeout::Timer){ |timer|
|
14
|
+
mock(timer).on_timeout
|
15
15
|
}
|
16
16
|
RC::Facebook.new.get('me').should.eq({})
|
17
17
|
end
|
@@ -19,7 +19,7 @@ describe RC::Facebook do
|
|
19
19
|
should 'override timeout' do
|
20
20
|
stub_request(:get, 'https://graph.facebook.com/me').
|
21
21
|
to_return(:body => 'true')
|
22
|
-
mock
|
22
|
+
mock(RC::Timeout::Timer).new(99, is_a(Timeout::Error))
|
23
23
|
RC::Facebook.new(:timeout => 1).get('me', {}, :timeout => 99).
|
24
24
|
should.eq true
|
25
25
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
require 'rest-more/test'
|
3
|
+
|
4
|
+
describe RC::Instagram do
|
5
|
+
after do
|
6
|
+
WebMock.reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
json = <<-JSON
|
10
|
+
{"meta":{"code":200},
|
11
|
+
"data":[{"username":"restmore",
|
12
|
+
"profile_picture":"http://images.ak.instagram.com/profile.jpg",
|
13
|
+
"full_name":"Rest More", "id":"123"}],
|
14
|
+
"access_token":"A"}
|
15
|
+
JSON
|
16
|
+
|
17
|
+
client = RC::Instagram.new(:client_id => 'Z', :client_secret => 'S',
|
18
|
+
:access_token => 'X')
|
19
|
+
|
20
|
+
should 'have correct authorize url' do
|
21
|
+
client.authorize_url.should.eq \
|
22
|
+
'https://api.instagram.com/oauth/authorize?' \
|
23
|
+
'client_id=Z&response_type=code'
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'authorize! and get the access token' do
|
27
|
+
stub_request(:post, 'https://api.instagram.com/oauth/access_token').
|
28
|
+
with(:body => {'client_id' => 'Z', 'client_secret' => 'S',
|
29
|
+
'grant_type' => 'authorization_code', 'code' => 'C'}).
|
30
|
+
to_return(:body => json)
|
31
|
+
|
32
|
+
begin
|
33
|
+
client.authorize!(:code => 'C').should.kind_of?(Hash)
|
34
|
+
client.access_token. should.eq 'A'
|
35
|
+
ensure
|
36
|
+
client.data = nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'retrieve user profile based on username' do
|
41
|
+
stub_request(:get, 'https://api.instagram.com/v1/users/search?' \
|
42
|
+
'client_id=Z&q=restmore').
|
43
|
+
to_return(:body => json)
|
44
|
+
|
45
|
+
client.get('v1/users/search', :q => 'restmore').should.eq(
|
46
|
+
{'meta' => {'code' => 200},
|
47
|
+
'data' => [{'username' => 'restmore',
|
48
|
+
'profile_picture' =>
|
49
|
+
'http://images.ak.instagram.com/profile.jpg',
|
50
|
+
'full_name' => 'Rest More',
|
51
|
+
'id' => '123'}],
|
52
|
+
'access_token' => 'A'})
|
53
|
+
end
|
54
|
+
end
|
data/test/twitter/test_api.rb
CHANGED
metadata
CHANGED
@@ -1,44 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Cardinal Blue
|
8
7
|
- Lin Jen-Shin (godfat)
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-05-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-core
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
19
|
+
version: 3.0.0
|
21
20
|
type: :runtime
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- -
|
24
|
+
- - ">="
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
description:
|
26
|
+
version: 3.0.0
|
27
|
+
description: |-
|
28
|
+
Various REST clients such as Facebook and Twitter built with [rest-core][].
|
29
29
|
|
30
|
-
|
31
|
-
[rest-core]: https://github.com/cardinalblue/rest-core'
|
30
|
+
[rest-core]: https://github.com/godfat/rest-core
|
32
31
|
email:
|
33
|
-
-
|
32
|
+
- godfat (XD) godfat.org
|
34
33
|
executables:
|
35
34
|
- rib-rest-core
|
36
35
|
extensions: []
|
37
36
|
extra_rdoc_files: []
|
38
37
|
files:
|
39
|
-
- .gitignore
|
40
|
-
- .gitmodules
|
41
|
-
- .travis.yml
|
38
|
+
- ".gitignore"
|
39
|
+
- ".gitmodules"
|
40
|
+
- ".travis.yml"
|
42
41
|
- CHANGES.md
|
43
42
|
- Gemfile
|
44
43
|
- LICENSE
|
@@ -46,7 +45,7 @@ files:
|
|
46
45
|
- Rakefile
|
47
46
|
- TODO.md
|
48
47
|
- bin/rib-rest-core
|
49
|
-
- doc/
|
48
|
+
- doc/facebook.md
|
50
49
|
- example/multi.rb
|
51
50
|
- example/rails3/Gemfile
|
52
51
|
- example/rails3/README
|
@@ -67,14 +66,15 @@ files:
|
|
67
66
|
- example/rails3/test/functional/application_controller_test.rb
|
68
67
|
- example/rails3/test/test_helper.rb
|
69
68
|
- example/rails3/test/unit/rails_util_test.rb
|
70
|
-
- example/rainbows.rb
|
71
69
|
- example/simple.rb
|
72
70
|
- example/sinatra/config.ru
|
73
71
|
- lib/rest-core/client/dropbox.rb
|
74
72
|
- lib/rest-core/client/facebook.rb
|
75
73
|
- lib/rest-core/client/facebook/rails_util.rb
|
74
|
+
- lib/rest-core/client/firebase.rb
|
76
75
|
- lib/rest-core/client/github.rb
|
77
76
|
- lib/rest-core/client/github/rails_util.rb
|
77
|
+
- lib/rest-core/client/instagram.rb
|
78
78
|
- lib/rest-core/client/linkedin.rb
|
79
79
|
- lib/rest-core/client/linkedin/rails_util.rb
|
80
80
|
- lib/rest-core/client/twitter.rb
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- lib/rest-more/version.rb
|
87
87
|
- lib/rib/app/rest-core.rb
|
88
88
|
- rest-more.gemspec
|
89
|
-
- task
|
89
|
+
- task/README.md
|
90
90
|
- task/gemgem.rb
|
91
91
|
- test/dropbox/test_api.rb
|
92
92
|
- test/facebook/config/rest-core.yaml
|
@@ -102,9 +102,11 @@ files:
|
|
102
102
|
- test/facebook/test_parse.rb
|
103
103
|
- test/facebook/test_serialize.rb
|
104
104
|
- test/facebook/test_timeout.rb
|
105
|
+
- test/instagram/test_api.rb
|
105
106
|
- test/twitter/test_api.rb
|
106
|
-
homepage: https://github.com/
|
107
|
-
licenses:
|
107
|
+
homepage: https://github.com/godfat/rest-more
|
108
|
+
licenses:
|
109
|
+
- Apache License 2.0
|
108
110
|
metadata: {}
|
109
111
|
post_install_message:
|
110
112
|
rdoc_options: []
|
@@ -112,20 +114,20 @@ require_paths:
|
|
112
114
|
- lib
|
113
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
116
|
requirements:
|
115
|
-
- -
|
117
|
+
- - ">="
|
116
118
|
- !ruby/object:Gem::Version
|
117
119
|
version: '0'
|
118
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
121
|
requirements:
|
120
|
-
- -
|
122
|
+
- - ">="
|
121
123
|
- !ruby/object:Gem::Version
|
122
124
|
version: '0'
|
123
125
|
requirements: []
|
124
126
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.2.2
|
126
128
|
signing_key:
|
127
129
|
specification_version: 4
|
128
|
-
summary: Various REST clients such as Facebook and Twitter built with [rest-core][]
|
130
|
+
summary: Various REST clients such as Facebook and Twitter built with [rest-core][].
|
129
131
|
test_files:
|
130
132
|
- test/dropbox/test_api.rb
|
131
133
|
- test/facebook/test_api.rb
|
@@ -140,4 +142,5 @@ test_files:
|
|
140
142
|
- test/facebook/test_parse.rb
|
141
143
|
- test/facebook/test_serialize.rb
|
142
144
|
- test/facebook/test_timeout.rb
|
145
|
+
- test/instagram/test_api.rb
|
143
146
|
- test/twitter/test_api.rb
|
data/example/rainbows.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
|
2
|
-
worker_processes 4 # assuming four CPU cores
|
3
|
-
preload_app true
|
4
|
-
|
5
|
-
Rainbows! do
|
6
|
-
use :EventMachine, :em_client_class => lambda{
|
7
|
-
RainbowsEventMachineThreadPoolClient
|
8
|
-
# or
|
9
|
-
# RainbowsEventMachineFiberSpawnClient
|
10
|
-
}
|
11
|
-
worker_connections 100
|
12
|
-
|
13
|
-
client_max_body_size 20*1024*1024 # 20 megabytes
|
14
|
-
client_header_buffer_size 8*1024 # 8 kilobytes
|
15
|
-
end
|
16
|
-
|
17
|
-
after_fork{ |_, _|
|
18
|
-
EM.threadpool_size = 32
|
19
|
-
class RainbowsEventMachineThreadPoolClient < Rainbows::EventMachine::Client
|
20
|
-
def app_call input
|
21
|
-
set_comm_inactivity_timeout 0
|
22
|
-
@env[RACK_INPUT] = input
|
23
|
-
@env[REMOTE_ADDR] = @_io.kgio_addr
|
24
|
-
@env[ASYNC_CALLBACK] = method(:write_async_response)
|
25
|
-
@env[ASYNC_CLOSE] = EM::DefaultDeferrable.new
|
26
|
-
@deferred = true
|
27
|
-
EM.defer{
|
28
|
-
status, headers, body = catch(:async) {
|
29
|
-
APP.call(@env.merge!(RACK_DEFAULTS))
|
30
|
-
}
|
31
|
-
if nil == status || -1 == status
|
32
|
-
@deferred = true
|
33
|
-
else
|
34
|
-
@deferred = nil
|
35
|
-
ev_write_response(status, headers, body, @hp.next?)
|
36
|
-
end
|
37
|
-
}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class RainbowsEventMachineFiberSpawnClient < Rainbows::EventMachine::Client
|
42
|
-
def app_call input
|
43
|
-
set_comm_inactivity_timeout 0
|
44
|
-
@env[RACK_INPUT] = input
|
45
|
-
@env[REMOTE_ADDR] = @_io.kgio_addr
|
46
|
-
@env[ASYNC_CALLBACK] = method(:write_async_response)
|
47
|
-
@env[ASYNC_CLOSE] = EM::DefaultDeferrable.new
|
48
|
-
f = Fiber.new{
|
49
|
-
status, headers, body = catch(:async) {
|
50
|
-
APP.call(@env.merge!(RACK_DEFAULTS))
|
51
|
-
}
|
52
|
-
if nil == status || -1 == status
|
53
|
-
@deferred = true
|
54
|
-
else
|
55
|
-
@deferred = nil
|
56
|
-
ev_write_response(status, headers, body, @hp.next?)
|
57
|
-
end
|
58
|
-
}
|
59
|
-
f.resume
|
60
|
-
@deferred = true if f.alive?
|
61
|
-
end
|
62
|
-
end
|
63
|
-
}
|
64
|
-
|
65
|
-
EM.error_handler{ |e|
|
66
|
-
puts "Error: EM.error_handler: #{e.inspect} #{e.backtrace.inspect}"
|
67
|
-
}
|