rest-core 4.0.0 → 4.0.1
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/.travis.yml +30 -6
- data/CHANGES.md +9 -0
- data/README.md +3 -5
- data/Rakefile +9 -10
- data/lib/rest-core/middleware/cache.rb +1 -1
- data/lib/rest-core/middleware/json_response.rb +13 -5
- data/lib/rest-core/test.rb +2 -4
- data/lib/rest-core/util/json.rb +29 -0
- data/lib/rest-core/version.rb +1 -1
- data/rest-core.gemspec +5 -5
- data/task/README.md +8 -8
- data/task/gemgem.rb +29 -7
- data/test/test_json_response.rb +19 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19136f5e04b26e2f6f630b4d73f4abef7bdc5b0b
|
4
|
+
data.tar.gz: 8b6e9b3ffd8ef15a3bcf5c41a7da9f6aa125546e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f498cd18a1c646917abf8a909de19716db54b85ddeefaf917fb9c39d4cf6b186e7bfcf5e3cc1f8e62dc5c6e91244ca618f3b498b27b0b057054585ac22dbdf
|
7
|
+
data.tar.gz: eedebe88fe9065c313e292e988c8b502863062456e4dc763595f5f1975a77ffb96771ac1ce89a181cec1970c0c5f225eb1eac635aace59e50d066501efc58d6b
|
data/.travis.yml
CHANGED
@@ -1,14 +1,38 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.2
|
5
|
-
- 2.3.0
|
6
|
-
- rbx
|
7
|
-
- jruby-9
|
8
3
|
|
9
4
|
before_install:
|
10
5
|
- rvm get head
|
11
6
|
- rvm reload
|
12
7
|
- rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
|
13
|
-
install: 'bundle install --retry=3'
|
8
|
+
install: 'gem install bundler; bundle install --retry=3'
|
14
9
|
script: 'ruby -vr bundler/setup -S rake test'
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
include:
|
13
|
+
- rvm: 2.2.5
|
14
|
+
env: json_lib=json
|
15
|
+
- rvm: 2.2.5
|
16
|
+
env: json_lib=yajl
|
17
|
+
- rvm: 2.3.2
|
18
|
+
env: json_lib=json
|
19
|
+
- rvm: 2.3.2
|
20
|
+
env: json_lib=yajl
|
21
|
+
- rvm: 2.4.1
|
22
|
+
env: json_lib=json
|
23
|
+
- rvm: 2.4.1
|
24
|
+
env: json_lib=yajl
|
25
|
+
- rvm: ruby-head
|
26
|
+
env: json_lib=json
|
27
|
+
- rvm: ruby-head
|
28
|
+
env: json_lib=yajl
|
29
|
+
- rvm: jruby-9
|
30
|
+
env: JRUBY_OPTS=--debug
|
31
|
+
- rvm: rbx
|
32
|
+
|
33
|
+
allow_failures:
|
34
|
+
- rvm: 2.4.1
|
35
|
+
env: json_lib=json
|
36
|
+
- rvm: 2.4.1
|
37
|
+
env: json_lib=yajl
|
38
|
+
- rvm: rbx
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## rest-core 4.0.1 -- 2017-05-15
|
4
|
+
|
5
|
+
* [RC::Cache] Check against `Numeric` instead of `Fixnum` for Ruby 2.4
|
6
|
+
compatibility.
|
7
|
+
* [RC::JsonResponse] Fix encoding issue when trying to remove BOM.
|
8
|
+
See https://github.com/godfat/rest-core/issues/24
|
9
|
+
and https://github.com/godfat/rest-core/commit/4123ca485ecc3b9d31749423f7039bfa1652a3a3
|
10
|
+
Thanks AshwiniDoddamaniFluke
|
11
|
+
|
3
12
|
## rest-core 4.0.0 -- 2016-02-04
|
4
13
|
|
5
14
|
Now the core functionality was extracted to a new gem, rest-builder.
|
data/README.md
CHANGED
@@ -15,9 +15,7 @@ talk is in Mandarin. There's another talk about [The Promise of rest-core][]
|
|
15
15
|
* [github](https://github.com/godfat/rest-core)
|
16
16
|
* [rubygems](https://rubygems.org/gems/rest-core)
|
17
17
|
* [rdoc](http://rdoc.info/projects/godfat/rest-core)
|
18
|
-
* [
|
19
|
-
Send your questions to: <rest-core@freelists.org> and you could read
|
20
|
-
through [archives](http://www.freelists.org/archives/rest-core)
|
18
|
+
* [issues](https://github.com/godfat/rest-core/issues) (feel free to ask for support)
|
21
19
|
|
22
20
|
## DESCRIPTION:
|
23
21
|
|
@@ -720,9 +718,9 @@ the priority here is:
|
|
720
718
|
|
721
719
|
## LICENSE:
|
722
720
|
|
723
|
-
Apache License 2.0
|
721
|
+
Apache License 2.0 (Apache-2.0)
|
724
722
|
|
725
|
-
Copyright (c) 2011-
|
723
|
+
Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
|
726
724
|
|
727
725
|
Licensed under the Apache License, Version 2.0 (the "License");
|
728
726
|
you may not use this file except in compliance with the License.
|
data/Rakefile
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
|
2
2
|
begin
|
3
|
-
require "#{
|
3
|
+
require "#{__dir__}/task/gemgem"
|
4
4
|
rescue LoadError
|
5
5
|
sh 'git submodule update --init --recursive'
|
6
6
|
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Gemgem.init(dir) do |s|
|
9
|
+
Gemgem.init(__dir__, :submodules =>
|
10
|
+
%w[rest-builder
|
11
|
+
rest-builder/promise_pool]) do |s|
|
13
12
|
require 'rest-core/version'
|
14
13
|
s.name = 'rest-core'
|
15
14
|
s.version = RestCore::VERSION
|
16
|
-
%w[rest-builder].each do |g|
|
17
|
-
s.add_runtime_dependency(g)
|
18
|
-
end
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
%w[rest-builder].each(&s.method(:add_runtime_dependency))
|
17
|
+
end
|
18
|
+
|
19
|
+
task :test do
|
20
|
+
require ENV['json_lib'] if ENV['json_lib']
|
22
21
|
end
|
23
22
|
|
24
23
|
desc 'Run console'
|
@@ -28,11 +28,19 @@ module RestCore
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def process response
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
body = response[RESPONSE_BODY]
|
32
|
+
json = if body.kind_of?(String)
|
33
|
+
Json.normalize(body)
|
34
|
+
else
|
35
|
+
# Yajl supports streaming, so let's pass it directly to make
|
36
|
+
# it possible to do streaming here. Although indeed we should
|
37
|
+
# use RESPONSE_SOCKET in this case, but doing that could
|
38
|
+
# introduce some incompatibility which I don't want to take
|
39
|
+
# care of for now.
|
40
|
+
body
|
41
|
+
end
|
42
|
+
|
43
|
+
response.merge(RESPONSE_BODY => Json.decode(json))
|
36
44
|
rescue Json.const_get(:ParseError) => error
|
37
45
|
fail(response, ParseError.new(error, body))
|
38
46
|
end
|
data/lib/rest-core/test.rb
CHANGED
@@ -5,8 +5,6 @@ require 'pork/auto'
|
|
5
5
|
require 'muack'
|
6
6
|
require 'webmock'
|
7
7
|
|
8
|
-
|
9
|
-
require 'yaml'
|
10
|
-
|
8
|
+
WebMock.enable!
|
11
9
|
WebMock.disable_net_connect!(:allow_localhost => true)
|
12
|
-
Pork::
|
10
|
+
Pork::Suite.include(Muack::API, WebMock::API)
|
data/lib/rest-core/util/json.rb
CHANGED
@@ -61,5 +61,34 @@ module RestCore
|
|
61
61
|
end
|
62
62
|
|
63
63
|
select_json!(self)
|
64
|
+
|
65
|
+
def self.normalize json
|
66
|
+
empty_to_null(strip_bom(json))
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.strip_bom json
|
70
|
+
case json.encoding.name
|
71
|
+
when 'UTF-8'
|
72
|
+
# StackExchange returns the problematic BOM! in UTF-8, so we
|
73
|
+
# need to strip it or it would break JSON parsers (i.e.
|
74
|
+
# yajl-ruby and json)
|
75
|
+
json.sub(/\A\xEF\xBB\xBF/u, '')
|
76
|
+
when 'ASCII-8BIT'
|
77
|
+
# In case if Content-Type doesn't have a charset for UTF-8,
|
78
|
+
# httpclient would set the response to ASCII-8BIT in this
|
79
|
+
# case.
|
80
|
+
json.sub(/\A\xEF\xBB\xBF/n, '')
|
81
|
+
else
|
82
|
+
json
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.empty_to_null json
|
87
|
+
if json.empty?
|
88
|
+
'null'
|
89
|
+
else
|
90
|
+
json
|
91
|
+
end
|
92
|
+
end
|
64
93
|
end
|
65
94
|
end
|
data/lib/rest-core/version.rb
CHANGED
data/rest-core.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: rest-core 4.0.
|
2
|
+
# stub: rest-core 4.0.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rest-core".freeze
|
6
|
-
s.version = "4.0.
|
6
|
+
s.version = "4.0.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "2017-05-15"
|
12
12
|
s.description = "Various [rest-builder](https://github.com/godfat/rest-builder) middleware\nfor building REST clients.\n\nCheckout [rest-more](https://github.com/godfat/rest-more) for pre-built\nclients.".freeze
|
13
13
|
s.email = ["godfat (XD) godfat.org".freeze]
|
14
14
|
s.files = [
|
@@ -92,8 +92,8 @@ Gem::Specification.new do |s|
|
|
92
92
|
"test/test_timeout.rb".freeze,
|
93
93
|
"test/test_universal.rb".freeze]
|
94
94
|
s.homepage = "https://github.com/godfat/rest-core".freeze
|
95
|
-
s.licenses = ["Apache
|
96
|
-
s.rubygems_version = "2.
|
95
|
+
s.licenses = ["Apache-2.0".freeze]
|
96
|
+
s.rubygems_version = "2.6.12".freeze
|
97
97
|
s.summary = "Various [rest-builder](https://github.com/godfat/rest-builder) middleware".freeze
|
98
98
|
s.test_files = [
|
99
99
|
"test/test_auth_basic.rb".freeze,
|
data/task/README.md
CHANGED
@@ -4,16 +4,16 @@
|
|
4
4
|
|
5
5
|
Provided tasks:
|
6
6
|
|
7
|
-
rake clean #
|
7
|
+
rake clean # Trash ignored files
|
8
8
|
rake gem:build # Build gem
|
9
9
|
rake gem:install # Install gem
|
10
10
|
rake gem:release # Release gem
|
11
11
|
rake gem:spec # Generate gemspec
|
12
|
-
rake test # Run tests
|
12
|
+
rake test # Run tests
|
13
13
|
|
14
14
|
## REQUIREMENTS:
|
15
15
|
|
16
|
-
* Tested with MRI (official CRuby)
|
16
|
+
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
17
17
|
|
18
18
|
## INSTALLATION:
|
19
19
|
|
@@ -23,13 +23,13 @@ And in Rakefile:
|
|
23
23
|
|
24
24
|
``` ruby
|
25
25
|
begin
|
26
|
-
require "#{
|
26
|
+
require "#{__dir__}/task/gemgem"
|
27
27
|
rescue LoadError
|
28
|
-
sh 'git submodule update --init'
|
28
|
+
sh 'git submodule update --init --recursive'
|
29
29
|
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
30
30
|
end
|
31
31
|
|
32
|
-
Gemgem.init(
|
32
|
+
Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
|
33
33
|
s.name = 'your-gem'
|
34
34
|
s.version = '0.1.0'
|
35
35
|
end
|
@@ -37,9 +37,9 @@ end
|
|
37
37
|
|
38
38
|
## LICENSE:
|
39
39
|
|
40
|
-
Apache License 2.0
|
40
|
+
Apache License 2.0 (Apache-2.0)
|
41
41
|
|
42
|
-
Copyright (c) 2011-
|
42
|
+
Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
|
43
43
|
|
44
44
|
Licensed under the Apache License, Version 2.0 (the "License");
|
45
45
|
you may not use this file except in compliance with the License.
|
data/task/gemgem.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Gemgem
|
3
3
|
class << self
|
4
|
-
attr_accessor :dir, :spec, :spec_create
|
4
|
+
attr_accessor :dir, :spec, :submodules, :spec_create
|
5
5
|
end
|
6
6
|
|
7
7
|
module_function
|
@@ -11,12 +11,14 @@ module Gemgem
|
|
11
11
|
def pkg_dir ; "#{dir}/pkg" ; end
|
12
12
|
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
13
|
|
14
|
-
def init dir, &block
|
14
|
+
def init dir, options={}, &block
|
15
15
|
self.dir = dir
|
16
|
-
$LOAD_PATH.unshift("#{dir}/lib")
|
17
16
|
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
17
|
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
18
|
+
self.submodules = options[:submodules] || []
|
19
19
|
self.spec_create = block
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
|
20
22
|
end
|
21
23
|
|
22
24
|
def create
|
@@ -26,7 +28,7 @@ module Gemgem
|
|
26
28
|
|
27
29
|
s.description = description.join
|
28
30
|
s.summary = description.first
|
29
|
-
s.license =
|
31
|
+
s.license = license
|
30
32
|
|
31
33
|
s.date = Time.now.strftime('%Y-%m-%d')
|
32
34
|
s.files = gem_files
|
@@ -115,6 +117,7 @@ module Gemgem
|
|
115
117
|
SimpleCov.start do
|
116
118
|
add_filter('test/')
|
117
119
|
add_filter('test.rb')
|
120
|
+
submodules_libs.each(&method(:add_filter))
|
118
121
|
end
|
119
122
|
end
|
120
123
|
|
@@ -159,11 +162,15 @@ module Gemgem
|
|
159
162
|
end
|
160
163
|
|
161
164
|
def strip_home_path path
|
162
|
-
path.sub(ENV['HOME']
|
165
|
+
path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
|
163
166
|
end
|
164
167
|
|
165
168
|
def strip_cwd_path path
|
166
|
-
path.sub(Dir.pwd
|
169
|
+
path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
|
170
|
+
end
|
171
|
+
|
172
|
+
def submodules_libs
|
173
|
+
submodules.map{ |path| "#{dir}/#{path}/lib" }
|
167
174
|
end
|
168
175
|
|
169
176
|
def git *args
|
@@ -201,6 +208,11 @@ module Gemgem
|
|
201
208
|
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
202
209
|
end
|
203
210
|
|
211
|
+
def license
|
212
|
+
readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
|
213
|
+
split(/[()]/).map(&:strip).reject(&:empty?).last
|
214
|
+
end
|
215
|
+
|
204
216
|
def all_files
|
205
217
|
@all_files ||= fold_files(glob).sort
|
206
218
|
end
|
@@ -221,7 +233,8 @@ module Gemgem
|
|
221
233
|
|
222
234
|
def gem_files
|
223
235
|
@gem_files ||= all_files.reject{ |f|
|
224
|
-
f =~
|
236
|
+
f =~ submodules_pattern ||
|
237
|
+
(f =~ ignored_pattern && !git_files.include?(f))
|
225
238
|
}
|
226
239
|
end
|
227
240
|
|
@@ -253,6 +266,15 @@ module Gemgem
|
|
253
266
|
end
|
254
267
|
end
|
255
268
|
|
269
|
+
def submodules_pattern
|
270
|
+
@submodules_pattern ||= if submodules.empty?
|
271
|
+
/^$/
|
272
|
+
else
|
273
|
+
Regexp.new(submodules.map{ |path|
|
274
|
+
"^#{Regexp.escape(path)}/" }.join('|'))
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
256
278
|
def expand_patterns pathes
|
257
279
|
# http://git-scm.com/docs/gitignore
|
258
280
|
pathes.flat_map{ |path|
|
data/test/test_json_response.rb
CHANGED
@@ -9,7 +9,9 @@ describe RC::JsonResponse do
|
|
9
9
|
would 'do nothing' do
|
10
10
|
expected = {RC::RESPONSE_BODY => nil,
|
11
11
|
RC::REQUEST_HEADERS => {'Accept' => 'application/json'}}
|
12
|
-
app.call(
|
12
|
+
app.call(RC::RESPONSE_BODY => '') do |response|
|
13
|
+
response.should.eq(expected)
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
would 'decode' do
|
@@ -36,6 +38,22 @@ describe RC::JsonResponse do
|
|
36
38
|
err.cause.class.should.eq(RC::Json.const_get(:ParseError))
|
37
39
|
end
|
38
40
|
end
|
41
|
+
|
42
|
+
would 'remove UTF-8 BOM' do
|
43
|
+
body = %Q{\xEF\xBB\xBF"UTF-8"}
|
44
|
+
|
45
|
+
app.call(RC::RESPONSE_BODY => body) do |response|
|
46
|
+
expect(response[RC::RESPONSE_BODY]).eq 'UTF-8'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
would 'remove UTF-8 BOM for ASCII-8BIT' do
|
51
|
+
body = %Q{\xEF\xBB\xBF"UTF-8"}.force_encoding('ASCII-8BIT')
|
52
|
+
|
53
|
+
app.call(RC::RESPONSE_BODY => body) do |response|
|
54
|
+
expect(response[RC::RESPONSE_BODY]).eq 'UTF-8'
|
55
|
+
end
|
56
|
+
end
|
39
57
|
end
|
40
58
|
|
41
59
|
describe 'client' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
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:
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-builder
|
@@ -117,7 +117,7 @@ files:
|
|
117
117
|
- test/test_universal.rb
|
118
118
|
homepage: https://github.com/godfat/rest-core
|
119
119
|
licenses:
|
120
|
-
- Apache
|
120
|
+
- Apache-2.0
|
121
121
|
metadata: {}
|
122
122
|
post_install_message:
|
123
123
|
rdoc_options: []
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.6.12
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Various [rest-builder](https://github.com/godfat/rest-builder) middleware
|