rest-core 1.0.2 → 1.0.3
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/CHANGES.md +17 -0
- data/README.md +3 -2
- data/TODO.md +0 -2
- data/example/auto.rb +1 -1
- data/example/coolio.rb +1 -1
- data/example/eventmachine.rb +1 -1
- data/example/multi.rb +1 -1
- data/example/rest-client.rb +1 -1
- data/lib/rest-core/app/em-http-request-async.rb +1 -1
- data/lib/rest-core/app/em-http-request-fiber.rb +1 -1
- data/lib/rest-core/client/universal.rb +1 -1
- data/lib/rest-core/client.rb +5 -20
- data/lib/rest-core/middleware/cache.rb +1 -0
- data/lib/rest-core/middleware/oauth1_header.rb +4 -2
- data/lib/rest-core/version.rb +1 -1
- data/rest-core.gemspec +2 -2
- data/test/test_cache.rb +18 -0
- data/test/test_client.rb +17 -10
- data/test/test_client_oauth1.rb +1 -2
- data/test/test_error_detector.rb +2 -3
- data/test/test_error_detector_http.rb +2 -3
- data/test/test_oauth1_header.rb +6 -0
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## rest-core 1.0.3 -- 2012-08-15
|
4
|
+
|
5
|
+
### Enhancement
|
6
|
+
|
7
|
+
* [Client] `client.head` now returns the headers instead of response body.
|
8
|
+
It doesn't make sense to return the response body, because there's no
|
9
|
+
such things in a HEAD request.
|
10
|
+
|
11
|
+
### Bugs fixes
|
12
|
+
|
13
|
+
* [Cache] The cache object you passed in would only need to respond to
|
14
|
+
`[]` and `[]=`. If the cache object accepts an `:expires_in` option,
|
15
|
+
then it must also respond to `store`, too.
|
16
|
+
|
17
|
+
* [Oauth1Header] Fixed a long standing bug that tilde (~) shouldn't be
|
18
|
+
escaped. Many thanks to @brucehsu for discovering this!
|
19
|
+
|
3
20
|
## rest-core 1.0.2 -- 2012-06-05
|
4
21
|
|
5
22
|
### Enhancement
|
data/README.md
CHANGED
@@ -80,7 +80,7 @@ You can use `RestCore::Builder` to build your own dedicated client:
|
|
80
80
|
require 'rest-core'
|
81
81
|
|
82
82
|
YourClient = RestCore::Builder.client do
|
83
|
-
s =
|
83
|
+
s = RestCore
|
84
84
|
use s::DefaultSite , 'https://api.github.com/users/'
|
85
85
|
use s::JsonDecode , true
|
86
86
|
use s::CommonLogger, method(:puts)
|
@@ -122,7 +122,7 @@ cool.io. Below is an example for eventmachine:
|
|
122
122
|
require 'rest-core'
|
123
123
|
|
124
124
|
AsynchronousClient = RestCore::Builder.client do
|
125
|
-
s =
|
125
|
+
s = RestCore
|
126
126
|
use s::DefaultSite , 'https://api.github.com/users/'
|
127
127
|
use s::JsonDecode , true
|
128
128
|
use s::CommonLogger, method(:puts)
|
@@ -318,6 +318,7 @@ To be added.
|
|
318
318
|
* Mariusz Pruszynski (@snicky)
|
319
319
|
* Mr. Big Cat (@miaout17)
|
320
320
|
* Nicolas Fouché (@nfo)
|
321
|
+
* Szu-Kai Hsu (@brucehsu)
|
321
322
|
|
322
323
|
## LICENSE:
|
323
324
|
|
data/TODO.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# TODO
|
2
2
|
|
3
|
-
* Auto should also pick RestClient if it's not inside a fiber
|
4
3
|
* HTTP method in Requested log
|
5
4
|
* middleware revisit (how to initialize?)
|
6
5
|
* test utility
|
@@ -8,7 +7,6 @@
|
|
8
7
|
# BUG
|
9
8
|
|
10
9
|
* inheritance should work; assign builder?
|
11
|
-
* no error handling in cool.io
|
12
10
|
|
13
11
|
# FEATURE
|
14
12
|
|
data/example/auto.rb
CHANGED
@@ -4,7 +4,7 @@ require 'eventmachine'
|
|
4
4
|
require 'cool.io'
|
5
5
|
|
6
6
|
YourClient = RestCore::Builder.client do
|
7
|
-
s =
|
7
|
+
s = RestCore
|
8
8
|
use s::DefaultSite , 'https://api.github.com/users/'
|
9
9
|
use s::JsonDecode , true
|
10
10
|
use s::CommonLogger, method(:puts)
|
data/example/coolio.rb
CHANGED
data/example/eventmachine.rb
CHANGED
data/example/multi.rb
CHANGED
@@ -6,7 +6,7 @@ RestCore::EmHttpRequest # there might be a autoload bug?
|
|
6
6
|
# stack level too deep (SystemStackError)
|
7
7
|
|
8
8
|
YourClient = RestCore::Builder.client do
|
9
|
-
s =
|
9
|
+
s = RestCore
|
10
10
|
use s::DefaultSite , 'https://api.github.com/users/'
|
11
11
|
use s::JsonDecode , true
|
12
12
|
use s::CommonLogger, method(:puts)
|
data/example/rest-client.rb
CHANGED
data/lib/rest-core/client.rb
CHANGED
@@ -89,21 +89,6 @@ module RestCore::Client
|
|
89
89
|
DRY => true}.merge(opts))))
|
90
90
|
end
|
91
91
|
|
92
|
-
# extra options:
|
93
|
-
# json_decode: Bool # decode with json or not in this API request
|
94
|
-
# # default: json_decode in rest-graph instance
|
95
|
-
# timeout: Int # the timeout for this API request
|
96
|
-
# # default: timeout in rest-graph instance
|
97
|
-
# secret: Bool # use secret_acccess_token or not
|
98
|
-
# # default: false
|
99
|
-
# cache: Bool # use cache or not; if it's false, update cache, too
|
100
|
-
# # default: true
|
101
|
-
# expires_in: Int # control when would the cache be expired
|
102
|
-
# # default: nil
|
103
|
-
# async: Bool # use eventmachine for http client or not
|
104
|
-
# # default: false, but true in aget family
|
105
|
-
# headers: Hash # additional hash you want to pass
|
106
|
-
# # default: {}
|
107
92
|
def get path, query={}, opts={}, &cb
|
108
93
|
request(
|
109
94
|
{REQUEST_METHOD => :get ,
|
@@ -122,7 +107,7 @@ module RestCore::Client
|
|
122
107
|
request(
|
123
108
|
{REQUEST_METHOD => :head ,
|
124
109
|
REQUEST_PATH => path ,
|
125
|
-
REQUEST_QUERY => query }.merge(opts), &cb)
|
110
|
+
REQUEST_QUERY => query }.merge(opts), RESPONSE_HEADERS, &cb)
|
126
111
|
end
|
127
112
|
|
128
113
|
def options path, query={}, opts={}, &cb
|
@@ -156,13 +141,13 @@ module RestCore::Client
|
|
156
141
|
REQUEST_PAYLOAD => payload}.merge(opts), &cb)
|
157
142
|
end
|
158
143
|
|
159
|
-
def request env, app=app
|
144
|
+
def request env, key=RESPONSE_BODY, app=app
|
160
145
|
if block_given?
|
161
146
|
request_full(env, app){ |response|
|
162
|
-
yield(response[
|
147
|
+
yield(response[key])
|
163
148
|
}
|
164
149
|
else
|
165
|
-
request_full(env, app)[
|
150
|
+
request_full(env, app)[key]
|
166
151
|
end
|
167
152
|
end
|
168
153
|
|
@@ -195,7 +180,7 @@ module RestCore::Client
|
|
195
180
|
|
196
181
|
|
197
182
|
|
198
|
-
|
183
|
+
private
|
199
184
|
def string_keys hash
|
200
185
|
hash.inject({}){ |r, (k, v)|
|
201
186
|
if v.kind_of?(Hash)
|
@@ -2,10 +2,12 @@
|
|
2
2
|
require 'rest-core/middleware'
|
3
3
|
require 'rest-core/util/hmac'
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'uri'
|
6
6
|
require 'openssl'
|
7
7
|
|
8
8
|
class RestCore::Oauth1Header
|
9
|
+
UNRESERVED = /[^a-zA-Z0-9\-\.\_\~]/
|
10
|
+
|
9
11
|
def self.members
|
10
12
|
[:request_token_path, :access_token_path, :authorize_path,
|
11
13
|
:consumer_key, :consumer_secret,
|
@@ -112,6 +114,6 @@ class RestCore::Oauth1Header
|
|
112
114
|
end
|
113
115
|
|
114
116
|
def escape string
|
115
|
-
|
117
|
+
URI.escape(string, UNRESERVED)
|
116
118
|
end
|
117
119
|
end
|
data/lib/rest-core/version.rb
CHANGED
data/rest-core.gemspec
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "rest-core"
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = [
|
9
9
|
"Cardinal Blue",
|
10
10
|
"Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2012-
|
11
|
+
s.date = "2012-08-15"
|
12
12
|
s.description = "Modular Ruby clients interface for REST APIs\n\nThere has been an explosion in the number of REST APIs available today.\nTo address the need for a way to access these APIs easily and elegantly,\nwe have developed [rest-core][], which consists of composable middleware\nthat allows you to build a REST client for any REST API. Or in the case of\ncommon APIs such as Facebook, Github, and Twitter, you can simply use the\ndedicated clients provided by [rest-more][].\n\n[rest-core]: https://github.com/cardinalblue/rest-core\n[rest-more]: https://github.com/cardinalblue/rest-more"
|
13
13
|
s.email = ["dev (XD) cardinalblue.com"]
|
14
14
|
s.files = [
|
data/test/test_cache.rb
CHANGED
@@ -66,4 +66,22 @@ describe RC::Cache do
|
|
66
66
|
EM.stop }}}
|
67
67
|
c.cache.size.should.eq 1
|
68
68
|
end
|
69
|
+
|
70
|
+
should 'only [] and []= should be implemented' do
|
71
|
+
cache = Class.new do
|
72
|
+
def initialize ; @h = {} ; end
|
73
|
+
def [] key ; @h[key] ; end
|
74
|
+
def []= key, value; @h[key] = value * 2; end
|
75
|
+
end.new
|
76
|
+
c = RC::Builder.client do
|
77
|
+
use RC::Cache, cache, 0
|
78
|
+
run Class.new{
|
79
|
+
def call env
|
80
|
+
env.merge(RC::RESPONSE_BODY => env[RC::REQUEST_PATH])
|
81
|
+
end
|
82
|
+
}
|
83
|
+
end.new
|
84
|
+
c.get('4')
|
85
|
+
c.get('4').should.eq '44'
|
86
|
+
end
|
69
87
|
end
|
data/test/test_client.rb
CHANGED
@@ -8,20 +8,28 @@ describe RC::Simple do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'do simple request' do
|
11
|
-
|
12
|
-
|
13
|
-
stub_request(method,
|
14
|
-
RC::Simple.new.send(method,
|
11
|
+
url = 'http://localhost/'
|
12
|
+
[:get, :post, :delete, :put, :patch, :options].each do |method|
|
13
|
+
stub_request(method, url).to_return(:body => '[]')
|
14
|
+
RC::Simple.new.send(method, url).should.eq '[]'
|
15
15
|
end
|
16
|
+
|
17
|
+
stub_request(:head, url).to_return(:headers => {'A' => 'B'})
|
18
|
+
RC::Simple.new.head(url).should.eq({'A' => 'B'})
|
16
19
|
end
|
17
20
|
|
18
21
|
should 'call the callback' do
|
19
|
-
|
20
|
-
|
21
|
-
stub_request(method,
|
22
|
-
(client = RC::Simple.new).send(method,
|
22
|
+
url = 'http://localhost/'
|
23
|
+
[:get, :post, :delete, :put, :patch, :options].each do |method|
|
24
|
+
stub_request(method, url).to_return(:body => '123')
|
25
|
+
(client = RC::Simple.new).send(method, url){ |res|
|
23
26
|
res.should.eq '123' }.should.eq client
|
24
27
|
end
|
28
|
+
|
29
|
+
stub_request(:head, url).to_return(:headers => {'A' => 'B'})
|
30
|
+
(client = RC::Simple.new).head(url){ |res|
|
31
|
+
res.should.eq({'A' => 'B'})
|
32
|
+
}.should.eq client
|
25
33
|
end
|
26
34
|
|
27
35
|
should 'have correct to_i' do
|
@@ -31,8 +39,7 @@ describe RC::Simple do
|
|
31
39
|
|
32
40
|
should 'use defaults' do
|
33
41
|
client = RestCore::Builder.client do
|
34
|
-
|
35
|
-
use s::Timeout, 4
|
42
|
+
use RC::Timeout, 4
|
36
43
|
end
|
37
44
|
c = client.new
|
38
45
|
c.timeout.should.eq 4 # default goes to middleware
|
data/test/test_client_oauth1.rb
CHANGED
data/test/test_error_detector.rb
CHANGED
@@ -4,9 +4,8 @@ require 'rest-core/test'
|
|
4
4
|
describe RC::ErrorDetector do
|
5
5
|
should 'lighten' do
|
6
6
|
client = RC::Builder.client do
|
7
|
-
|
8
|
-
|
9
|
-
run s::Dry
|
7
|
+
use RC::ErrorDetector
|
8
|
+
run RC::Dry
|
10
9
|
end.new.lighten
|
11
10
|
|
12
11
|
client.attributes.should.key?(:error_detector)
|
@@ -4,9 +4,8 @@ require 'rest-core/test'
|
|
4
4
|
describe RC::ErrorDetectorHttp do
|
5
5
|
should 'lighten' do
|
6
6
|
client = RC::Builder.client do
|
7
|
-
|
8
|
-
|
9
|
-
run s::Dry
|
7
|
+
use RC::ErrorDetectorHttp
|
8
|
+
run RC::Dry
|
10
9
|
end.new.lighten
|
11
10
|
|
12
11
|
client.attributes.should.key?(:error_detector)
|
data/test/test_oauth1_header.rb
CHANGED
@@ -83,5 +83,11 @@ describe RestCore::Oauth1Header do
|
|
83
83
|
@env.merge!(RC::REQUEST_PAYLOAD => {'pay' => 'load'})
|
84
84
|
check
|
85
85
|
end
|
86
|
+
|
87
|
+
should 'not escape ~' do
|
88
|
+
@base_string << '%26tilde%3D~'
|
89
|
+
@env.merge!(RC::REQUEST_PAYLOAD => {'tilde' => '~'})
|
90
|
+
check
|
91
|
+
end
|
86
92
|
end
|
87
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|