mercadopago-custom-checkout 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gs/bin/rake +12 -8
- data/.gs/specifications/rake-10.5.0.gemspec +24 -28
- data/.tool-versions +1 -0
- data/lib/mercadopago/custom_checkout/version.rb +1 -1
- data/mercadopago-custom-checkout.gemspec +3 -3
- metadata +14 -125
- data/.gs/cache/faraday-0.9.2.gem +0 -0
- data/.gs/cache/minitest-5.9.0.gem +0 -0
- data/.gs/cache/multi_json-1.12.1.gem +0 -0
- data/.gs/cache/multipart-post-2.0.0.gem +0 -0
- data/.gs/gems/faraday-0.9.2/LICENSE.md +0 -20
- data/.gs/gems/faraday-0.9.2/README.md +0 -245
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_http.rb +0 -237
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_synchrony.rb +0 -100
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/excon.rb +0 -81
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/httpclient.rb +0 -117
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb +0 -130
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/net_http_persistent.rb +0 -49
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/patron.rb +0 -78
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/rack.rb +0 -58
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/test.rb +0 -162
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/typhoeus.rb +0 -123
- data/.gs/gems/faraday-0.9.2/lib/faraday/adapter.rb +0 -46
- data/.gs/gems/faraday-0.9.2/lib/faraday/autoload.rb +0 -84
- data/.gs/gems/faraday-0.9.2/lib/faraday/connection.rb +0 -437
- data/.gs/gems/faraday-0.9.2/lib/faraday/error.rb +0 -53
- data/.gs/gems/faraday-0.9.2/lib/faraday/middleware.rb +0 -37
- data/.gs/gems/faraday-0.9.2/lib/faraday/options.rb +0 -359
- data/.gs/gems/faraday-0.9.2/lib/faraday/parameters.rb +0 -197
- data/.gs/gems/faraday-0.9.2/lib/faraday/rack_builder.rb +0 -213
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/authorization.rb +0 -42
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/basic_authentication.rb +0 -13
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/instrumentation.rb +0 -36
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/multipart.rb +0 -63
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/retry.rb +0 -154
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/token_authentication.rb +0 -15
- data/.gs/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb +0 -36
- data/.gs/gems/faraday-0.9.2/lib/faraday/request.rb +0 -92
- data/.gs/gems/faraday-0.9.2/lib/faraday/response/logger.rb +0 -59
- data/.gs/gems/faraday-0.9.2/lib/faraday/response/raise_error.rb +0 -21
- data/.gs/gems/faraday-0.9.2/lib/faraday/response.rb +0 -93
- data/.gs/gems/faraday-0.9.2/lib/faraday/upload_io.rb +0 -67
- data/.gs/gems/faraday-0.9.2/lib/faraday/utils.rb +0 -309
- data/.gs/gems/faraday-0.9.2/lib/faraday.rb +0 -268
- data/.gs/gems/minitest-5.9.0/.autotest +0 -34
- data/.gs/gems/minitest-5.9.0/History.rdoc +0 -1176
- data/.gs/gems/minitest-5.9.0/Manifest.txt +0 -26
- data/.gs/gems/minitest-5.9.0/README.rdoc +0 -656
- data/.gs/gems/minitest-5.9.0/Rakefile +0 -72
- data/.gs/gems/minitest-5.9.0/design_rationale.rb +0 -52
- data/.gs/gems/minitest-5.9.0/lib/hoe/minitest.rb +0 -26
- data/.gs/gems/minitest-5.9.0/lib/minitest/assertions.rb +0 -674
- data/.gs/gems/minitest-5.9.0/lib/minitest/autorun.rb +0 -13
- data/.gs/gems/minitest-5.9.0/lib/minitest/benchmark.rb +0 -424
- data/.gs/gems/minitest-5.9.0/lib/minitest/expectations.rb +0 -284
- data/.gs/gems/minitest-5.9.0/lib/minitest/hell.rb +0 -17
- data/.gs/gems/minitest-5.9.0/lib/minitest/mock.rb +0 -232
- data/.gs/gems/minitest-5.9.0/lib/minitest/parallel.rb +0 -69
- data/.gs/gems/minitest-5.9.0/lib/minitest/pride.rb +0 -4
- data/.gs/gems/minitest-5.9.0/lib/minitest/pride_plugin.rb +0 -142
- data/.gs/gems/minitest-5.9.0/lib/minitest/spec.rb +0 -331
- data/.gs/gems/minitest-5.9.0/lib/minitest/test.rb +0 -284
- data/.gs/gems/minitest-5.9.0/lib/minitest/unit.rb +0 -45
- data/.gs/gems/minitest-5.9.0/lib/minitest.rb +0 -815
- data/.gs/gems/minitest-5.9.0/test/minitest/metametameta.rb +0 -90
- data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_benchmark.rb +0 -137
- data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_mock.rb +0 -512
- data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_reporter.rb +0 -281
- data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_spec.rb +0 -967
- data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_test.rb +0 -1983
- data/.gs/gems/multi_json-1.12.1/CHANGELOG.md +0 -245
- data/.gs/gems/multi_json-1.12.1/CONTRIBUTING.md +0 -46
- data/.gs/gems/multi_json-1.12.1/LICENSE.md +0 -20
- data/.gs/gems/multi_json-1.12.1/README.md +0 -121
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapter.rb +0 -49
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb +0 -15
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb +0 -20
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb +0 -25
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb +0 -23
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb +0 -11
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb +0 -11
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb +0 -32
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb +0 -25
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb +0 -23
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb +0 -19
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb +0 -43
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/options.rb +0 -39
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb +0 -29
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb +0 -17
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb +0 -606
- data/.gs/gems/multi_json-1.12.1/lib/multi_json/version.rb +0 -17
- data/.gs/gems/multi_json-1.12.1/lib/multi_json.rb +0 -161
- data/.gs/gems/multi_json-1.12.1/multi_json.gemspec +0 -20
- data/.gs/gems/multipart-post-2.0.0/.gitignore +0 -6
- data/.gs/gems/multipart-post-2.0.0/.travis.yml +0 -7
- data/.gs/gems/multipart-post-2.0.0/Gemfile +0 -14
- data/.gs/gems/multipart-post-2.0.0/History.txt +0 -60
- data/.gs/gems/multipart-post-2.0.0/Manifest.txt +0 -9
- data/.gs/gems/multipart-post-2.0.0/README.md +0 -77
- data/.gs/gems/multipart-post-2.0.0/Rakefile +0 -9
- data/.gs/gems/multipart-post-2.0.0/lib/composite_io.rb +0 -108
- data/.gs/gems/multipart-post-2.0.0/lib/multipart_post.rb +0 -9
- data/.gs/gems/multipart-post-2.0.0/lib/multipartable.rb +0 -29
- data/.gs/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +0 -27
- data/.gs/gems/multipart-post-2.0.0/lib/parts.rb +0 -96
- data/.gs/gems/multipart-post-2.0.0/multipart-post.gemspec +0 -22
- data/.gs/gems/multipart-post-2.0.0/test/multibyte.txt +0 -1
- data/.gs/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +0 -110
- data/.gs/gems/multipart-post-2.0.0/test/test_composite_io.rb +0 -115
- data/.gs/gems/multipart-post-2.0.0/test/test_parts.rb +0 -86
- data/.gs/specifications/faraday-0.9.2.gemspec +0 -31
- data/.gs/specifications/minitest-5.9.0.gemspec +0 -39
- data/.gs/specifications/multi_json-1.12.1.gemspec +0 -33
- data/.gs/specifications/multipart-post-2.0.0.gemspec +0 -22
- data/.ruby-version +0 -1
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response::Logger < Response::Middleware
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
DEFAULT_OPTIONS = { :bodies => false }
|
8
|
-
|
9
|
-
def initialize(app, logger = nil, options = {})
|
10
|
-
super(app)
|
11
|
-
@logger = logger || begin
|
12
|
-
require 'logger'
|
13
|
-
::Logger.new(STDOUT)
|
14
|
-
end
|
15
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
16
|
-
end
|
17
|
-
|
18
|
-
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
19
|
-
|
20
|
-
def call(env)
|
21
|
-
info "#{env.method} #{env.url.to_s}"
|
22
|
-
debug('request') { dump_headers env.request_headers }
|
23
|
-
debug('request') { dump_body(env[:body]) } if env[:body] && log_body?(:request)
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
def on_complete(env)
|
28
|
-
info('Status') { env.status.to_s }
|
29
|
-
debug('response') { dump_headers env.response_headers }
|
30
|
-
debug('response') { dump_body env[:body] } if env[:body] && log_body?(:response)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def dump_headers(headers)
|
36
|
-
headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
|
37
|
-
end
|
38
|
-
|
39
|
-
def dump_body(body)
|
40
|
-
if body.respond_to?(:to_str)
|
41
|
-
body.to_str
|
42
|
-
else
|
43
|
-
pretty_inspect(body)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def pretty_inspect(body)
|
48
|
-
require 'pp' unless body.respond_to?(:pretty_inspect)
|
49
|
-
body.pretty_inspect
|
50
|
-
end
|
51
|
-
|
52
|
-
def log_body?(type)
|
53
|
-
case @options[:bodies]
|
54
|
-
when Hash then @options[:bodies][type]
|
55
|
-
else @options[:bodies]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Faraday
|
2
|
-
class Response::RaiseError < Response::Middleware
|
3
|
-
ClientErrorStatuses = 400...600
|
4
|
-
|
5
|
-
def on_complete(env)
|
6
|
-
case env[:status]
|
7
|
-
when 404
|
8
|
-
raise Faraday::Error::ResourceNotFound, response_values(env)
|
9
|
-
when 407
|
10
|
-
# mimic the behavior that we get with proxy requests with HTTPS
|
11
|
-
raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
12
|
-
when ClientErrorStatuses
|
13
|
-
raise Faraday::Error::ClientError, response_values(env)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def response_values(env)
|
18
|
-
{:status => env.status, :headers => env.response_headers, :body => env.body}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response
|
5
|
-
# Used for simple response middleware.
|
6
|
-
class Middleware < Faraday::Middleware
|
7
|
-
def call(env)
|
8
|
-
@app.call(env).on_complete do |environment|
|
9
|
-
on_complete(environment)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Override this to modify the environment after the response has finished.
|
14
|
-
# Calls the `parse` method if defined
|
15
|
-
def on_complete(env)
|
16
|
-
env.body = parse(env.body) if respond_to?(:parse) && env.parse_body?
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
extend Forwardable
|
21
|
-
extend MiddlewareRegistry
|
22
|
-
|
23
|
-
register_middleware File.expand_path('../response', __FILE__),
|
24
|
-
:raise_error => [:RaiseError, 'raise_error'],
|
25
|
-
:logger => [:Logger, 'logger']
|
26
|
-
|
27
|
-
def initialize(env = nil)
|
28
|
-
@env = Env.from(env) if env
|
29
|
-
@on_complete_callbacks = []
|
30
|
-
end
|
31
|
-
|
32
|
-
attr_reader :env
|
33
|
-
|
34
|
-
def_delegators :env, :to_hash
|
35
|
-
|
36
|
-
def status
|
37
|
-
finished? ? env.status : nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def headers
|
41
|
-
finished? ? env.response_headers : {}
|
42
|
-
end
|
43
|
-
def_delegator :headers, :[]
|
44
|
-
|
45
|
-
def body
|
46
|
-
finished? ? env.body : nil
|
47
|
-
end
|
48
|
-
|
49
|
-
def finished?
|
50
|
-
!!env
|
51
|
-
end
|
52
|
-
|
53
|
-
def on_complete
|
54
|
-
if not finished?
|
55
|
-
@on_complete_callbacks << Proc.new
|
56
|
-
else
|
57
|
-
yield(env)
|
58
|
-
end
|
59
|
-
return self
|
60
|
-
end
|
61
|
-
|
62
|
-
def finish(env)
|
63
|
-
raise "response already finished" if finished?
|
64
|
-
@env = env.is_a?(Env) ? env : Env.from(env)
|
65
|
-
@on_complete_callbacks.each { |callback| callback.call(@env) }
|
66
|
-
return self
|
67
|
-
end
|
68
|
-
|
69
|
-
def success?
|
70
|
-
finished? && env.success?
|
71
|
-
end
|
72
|
-
|
73
|
-
# because @on_complete_callbacks cannot be marshalled
|
74
|
-
def marshal_dump
|
75
|
-
!finished? ? nil : {
|
76
|
-
:status => @env.status, :body => @env.body,
|
77
|
-
:response_headers => @env.response_headers
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
def marshal_load(env)
|
82
|
-
@env = Env.from(env)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Expand the env with more properties, without overriding existing ones.
|
86
|
-
# Useful for applying request params after restoring a marshalled Response.
|
87
|
-
def apply_request(request_env)
|
88
|
-
raise "response didn't finish yet" unless finished?
|
89
|
-
@env = Env.from(request_env).update(@env)
|
90
|
-
return self
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'composite_io'
|
3
|
-
require 'parts'
|
4
|
-
require 'stringio'
|
5
|
-
rescue LoadError
|
6
|
-
$stderr.puts "Install the multipart-post gem."
|
7
|
-
raise
|
8
|
-
end
|
9
|
-
|
10
|
-
module Faraday
|
11
|
-
# Similar but not compatible with ::CompositeReadIO provided by multipart-post.
|
12
|
-
class CompositeReadIO
|
13
|
-
def initialize(*parts)
|
14
|
-
@parts = parts.flatten
|
15
|
-
@ios = @parts.map { |part| part.to_io }
|
16
|
-
@index = 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def length
|
20
|
-
@parts.inject(0) { |sum, part| sum + part.length }
|
21
|
-
end
|
22
|
-
|
23
|
-
def rewind
|
24
|
-
@ios.each { |io| io.rewind }
|
25
|
-
@index = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
# Read from IOs in order until `length` bytes have been received.
|
29
|
-
def read(length = nil, outbuf = nil)
|
30
|
-
got_result = false
|
31
|
-
outbuf = outbuf ? outbuf.replace("") : ""
|
32
|
-
|
33
|
-
while io = current_io
|
34
|
-
if result = io.read(length)
|
35
|
-
got_result ||= !result.nil?
|
36
|
-
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
37
|
-
outbuf << result
|
38
|
-
length -= result.length if length
|
39
|
-
break if length == 0
|
40
|
-
end
|
41
|
-
advance_io
|
42
|
-
end
|
43
|
-
(!got_result && length) ? nil : outbuf
|
44
|
-
end
|
45
|
-
|
46
|
-
def close
|
47
|
-
@ios.each { |io| io.close }
|
48
|
-
end
|
49
|
-
|
50
|
-
def ensure_open_and_readable
|
51
|
-
# Rubinius compatibility
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def current_io
|
57
|
-
@ios[@index]
|
58
|
-
end
|
59
|
-
|
60
|
-
def advance_io
|
61
|
-
@index += 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
UploadIO = ::UploadIO
|
66
|
-
Parts = ::Parts
|
67
|
-
end
|
@@ -1,309 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
module Utils
|
5
|
-
extend self
|
6
|
-
|
7
|
-
# Adapted from Rack::Utils::HeaderHash
|
8
|
-
class Headers < ::Hash
|
9
|
-
def self.from(value)
|
10
|
-
new(value)
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(hash = nil)
|
14
|
-
super()
|
15
|
-
@names = {}
|
16
|
-
self.update(hash || {})
|
17
|
-
end
|
18
|
-
|
19
|
-
# on dup/clone, we need to duplicate @names hash
|
20
|
-
def initialize_copy(other)
|
21
|
-
super
|
22
|
-
@names = other.names.dup
|
23
|
-
end
|
24
|
-
|
25
|
-
# need to synchronize concurrent writes to the shared KeyMap
|
26
|
-
keymap_mutex = Mutex.new
|
27
|
-
|
28
|
-
# symbol -> string mapper + cache
|
29
|
-
KeyMap = Hash.new do |map, key|
|
30
|
-
value = if key.respond_to?(:to_str)
|
31
|
-
key
|
32
|
-
else
|
33
|
-
key.to_s.split('_'). # :user_agent => %w(user agent)
|
34
|
-
each { |w| w.capitalize! }. # => %w(User Agent)
|
35
|
-
join('-') # => "User-Agent"
|
36
|
-
end
|
37
|
-
keymap_mutex.synchronize { map[key] = value }
|
38
|
-
end
|
39
|
-
KeyMap[:etag] = "ETag"
|
40
|
-
|
41
|
-
def [](k)
|
42
|
-
k = KeyMap[k]
|
43
|
-
super(k) || super(@names[k.downcase])
|
44
|
-
end
|
45
|
-
|
46
|
-
def []=(k, v)
|
47
|
-
k = KeyMap[k]
|
48
|
-
k = (@names[k.downcase] ||= k)
|
49
|
-
# join multiple values with a comma
|
50
|
-
v = v.to_ary.join(', ') if v.respond_to? :to_ary
|
51
|
-
super(k, v)
|
52
|
-
end
|
53
|
-
|
54
|
-
def fetch(k, *args, &block)
|
55
|
-
k = KeyMap[k]
|
56
|
-
key = @names.fetch(k.downcase, k)
|
57
|
-
super(key, *args, &block)
|
58
|
-
end
|
59
|
-
|
60
|
-
def delete(k)
|
61
|
-
k = KeyMap[k]
|
62
|
-
if k = @names[k.downcase]
|
63
|
-
@names.delete k.downcase
|
64
|
-
super(k)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def include?(k)
|
69
|
-
@names.include? k.downcase
|
70
|
-
end
|
71
|
-
|
72
|
-
alias_method :has_key?, :include?
|
73
|
-
alias_method :member?, :include?
|
74
|
-
alias_method :key?, :include?
|
75
|
-
|
76
|
-
def merge!(other)
|
77
|
-
other.each { |k, v| self[k] = v }
|
78
|
-
self
|
79
|
-
end
|
80
|
-
alias_method :update, :merge!
|
81
|
-
|
82
|
-
def merge(other)
|
83
|
-
hash = dup
|
84
|
-
hash.merge! other
|
85
|
-
end
|
86
|
-
|
87
|
-
def replace(other)
|
88
|
-
clear
|
89
|
-
@names.clear
|
90
|
-
self.update other
|
91
|
-
self
|
92
|
-
end
|
93
|
-
|
94
|
-
def to_hash() ::Hash.new.update(self) end
|
95
|
-
|
96
|
-
def parse(header_string)
|
97
|
-
return unless header_string && !header_string.empty?
|
98
|
-
header_string.split(/\r\n/).
|
99
|
-
tap { |a| a.shift if a.first.index('HTTP/') == 0 }. # drop the HTTP status line
|
100
|
-
map { |h| h.split(/:\s+/, 2) }.reject { |p| p[0].nil? }. # split key and value, ignore blank lines
|
101
|
-
each { |key, value|
|
102
|
-
# join multiple values with a comma
|
103
|
-
if self[key]
|
104
|
-
self[key] << ', ' << value
|
105
|
-
else
|
106
|
-
self[key] = value
|
107
|
-
end
|
108
|
-
}
|
109
|
-
end
|
110
|
-
|
111
|
-
protected
|
112
|
-
|
113
|
-
def names
|
114
|
-
@names
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# hash with stringified keys
|
119
|
-
class ParamsHash < Hash
|
120
|
-
def [](key)
|
121
|
-
super(convert_key(key))
|
122
|
-
end
|
123
|
-
|
124
|
-
def []=(key, value)
|
125
|
-
super(convert_key(key), value)
|
126
|
-
end
|
127
|
-
|
128
|
-
def delete(key)
|
129
|
-
super(convert_key(key))
|
130
|
-
end
|
131
|
-
|
132
|
-
def include?(key)
|
133
|
-
super(convert_key(key))
|
134
|
-
end
|
135
|
-
|
136
|
-
alias_method :has_key?, :include?
|
137
|
-
alias_method :member?, :include?
|
138
|
-
alias_method :key?, :include?
|
139
|
-
|
140
|
-
def update(params)
|
141
|
-
params.each do |key, value|
|
142
|
-
self[key] = value
|
143
|
-
end
|
144
|
-
self
|
145
|
-
end
|
146
|
-
alias_method :merge!, :update
|
147
|
-
|
148
|
-
def merge(params)
|
149
|
-
dup.update(params)
|
150
|
-
end
|
151
|
-
|
152
|
-
def replace(other)
|
153
|
-
clear
|
154
|
-
update(other)
|
155
|
-
end
|
156
|
-
|
157
|
-
def merge_query(query, encoder = nil)
|
158
|
-
if query && !query.empty?
|
159
|
-
update((encoder || Utils.default_params_encoder).decode(query))
|
160
|
-
end
|
161
|
-
self
|
162
|
-
end
|
163
|
-
|
164
|
-
def to_query(encoder = nil)
|
165
|
-
(encoder || Utils.default_params_encoder).encode(self)
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
|
170
|
-
def convert_key(key)
|
171
|
-
key.to_s
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def build_query(params)
|
176
|
-
FlatParamsEncoder.encode(params)
|
177
|
-
end
|
178
|
-
|
179
|
-
def build_nested_query(params)
|
180
|
-
NestedParamsEncoder.encode(params)
|
181
|
-
end
|
182
|
-
|
183
|
-
ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/
|
184
|
-
|
185
|
-
def escape(s)
|
186
|
-
s.to_s.gsub(ESCAPE_RE) {|match|
|
187
|
-
'%' + match.unpack('H2' * match.bytesize).join('%').upcase
|
188
|
-
}.tr(' ', '+')
|
189
|
-
end
|
190
|
-
|
191
|
-
def unescape(s) CGI.unescape s.to_s end
|
192
|
-
|
193
|
-
DEFAULT_SEP = /[&;] */n
|
194
|
-
|
195
|
-
# Adapted from Rack
|
196
|
-
def parse_query(query)
|
197
|
-
FlatParamsEncoder.decode(query)
|
198
|
-
end
|
199
|
-
|
200
|
-
def parse_nested_query(query)
|
201
|
-
NestedParamsEncoder.decode(query)
|
202
|
-
end
|
203
|
-
|
204
|
-
def default_params_encoder
|
205
|
-
@default_params_encoder ||= NestedParamsEncoder
|
206
|
-
end
|
207
|
-
|
208
|
-
class << self
|
209
|
-
attr_writer :default_params_encoder
|
210
|
-
end
|
211
|
-
|
212
|
-
# Stolen from Rack
|
213
|
-
def normalize_params(params, name, v = nil)
|
214
|
-
name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
|
215
|
-
k = $1 || ''
|
216
|
-
after = $' || ''
|
217
|
-
|
218
|
-
return if k.empty?
|
219
|
-
|
220
|
-
if after == ""
|
221
|
-
if params[k]
|
222
|
-
params[k] = Array[params[k]] unless params[k].kind_of?(Array)
|
223
|
-
params[k] << v
|
224
|
-
else
|
225
|
-
params[k] = v
|
226
|
-
end
|
227
|
-
elsif after == "[]"
|
228
|
-
params[k] ||= []
|
229
|
-
raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
|
230
|
-
params[k] << v
|
231
|
-
elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
|
232
|
-
child_key = $1
|
233
|
-
params[k] ||= []
|
234
|
-
raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
|
235
|
-
if params[k].last.is_a?(Hash) && !params[k].last.key?(child_key)
|
236
|
-
normalize_params(params[k].last, child_key, v)
|
237
|
-
else
|
238
|
-
params[k] << normalize_params({}, child_key, v)
|
239
|
-
end
|
240
|
-
else
|
241
|
-
params[k] ||= {}
|
242
|
-
raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Hash)
|
243
|
-
params[k] = normalize_params(params[k], after, v)
|
244
|
-
end
|
245
|
-
|
246
|
-
return params
|
247
|
-
end
|
248
|
-
|
249
|
-
# Normalize URI() behavior across Ruby versions
|
250
|
-
#
|
251
|
-
# url - A String or URI.
|
252
|
-
#
|
253
|
-
# Returns a parsed URI.
|
254
|
-
def URI(url)
|
255
|
-
if url.respond_to?(:host)
|
256
|
-
url
|
257
|
-
elsif url.respond_to?(:to_str)
|
258
|
-
default_uri_parser.call(url)
|
259
|
-
else
|
260
|
-
raise ArgumentError, "bad argument (expected URI object or URI string)"
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
def default_uri_parser
|
265
|
-
@default_uri_parser ||= begin
|
266
|
-
require 'uri'
|
267
|
-
Kernel.method(:URI)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def default_uri_parser=(parser)
|
272
|
-
@default_uri_parser = if parser.respond_to?(:call) || parser.nil?
|
273
|
-
parser
|
274
|
-
else
|
275
|
-
parser.method(:parse)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
# Receives a String or URI and returns just the path with the query string sorted.
|
280
|
-
def normalize_path(url)
|
281
|
-
url = URI(url)
|
282
|
-
(url.path.start_with?('/') ? url.path : '/' + url.path) +
|
283
|
-
(url.query ? "?#{sort_query_params(url.query)}" : "")
|
284
|
-
end
|
285
|
-
|
286
|
-
# Recursive hash update
|
287
|
-
def deep_merge!(target, hash)
|
288
|
-
hash.each do |key, value|
|
289
|
-
if Hash === value and Hash === target[key]
|
290
|
-
target[key] = deep_merge(target[key], value)
|
291
|
-
else
|
292
|
-
target[key] = value
|
293
|
-
end
|
294
|
-
end
|
295
|
-
target
|
296
|
-
end
|
297
|
-
|
298
|
-
# Recursive hash merge
|
299
|
-
def deep_merge(source, hash)
|
300
|
-
deep_merge!(source.dup, hash)
|
301
|
-
end
|
302
|
-
|
303
|
-
protected
|
304
|
-
|
305
|
-
def sort_query_params(query)
|
306
|
-
query.split('&').sort.join('&')
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|