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,359 +0,0 @@
|
|
1
|
-
module Faraday
|
2
|
-
# Subclasses Struct with some special helpers for converting from a Hash to
|
3
|
-
# a Struct.
|
4
|
-
class Options < Struct
|
5
|
-
# Public
|
6
|
-
def self.from(value)
|
7
|
-
value ? new.update(value) : new
|
8
|
-
end
|
9
|
-
|
10
|
-
# Public
|
11
|
-
def each
|
12
|
-
return to_enum(:each) unless block_given?
|
13
|
-
members.each do |key|
|
14
|
-
yield(key.to_sym, send(key))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Public
|
19
|
-
def update(obj)
|
20
|
-
obj.each do |key, value|
|
21
|
-
if sub_options = self.class.options_for(key)
|
22
|
-
value = sub_options.from(value) if value
|
23
|
-
elsif Hash === value
|
24
|
-
hash = {}
|
25
|
-
value.each do |hash_key, hash_value|
|
26
|
-
hash[hash_key] = hash_value
|
27
|
-
end
|
28
|
-
value = hash
|
29
|
-
end
|
30
|
-
|
31
|
-
self.send("#{key}=", value) unless value.nil?
|
32
|
-
end
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
alias merge! update
|
37
|
-
|
38
|
-
# Public
|
39
|
-
def delete(key)
|
40
|
-
value = send(key)
|
41
|
-
send("#{key}=", nil)
|
42
|
-
value
|
43
|
-
end
|
44
|
-
|
45
|
-
# Public
|
46
|
-
def clear
|
47
|
-
members.each { |member| delete(member) }
|
48
|
-
end
|
49
|
-
|
50
|
-
# Public
|
51
|
-
def merge(value)
|
52
|
-
dup.update(value)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Public
|
56
|
-
def fetch(key, *args)
|
57
|
-
unless symbolized_key_set.include?(key.to_sym)
|
58
|
-
key_setter = "#{key}="
|
59
|
-
if args.size > 0
|
60
|
-
send(key_setter, args.first)
|
61
|
-
elsif block_given?
|
62
|
-
send(key_setter, Proc.new.call(key))
|
63
|
-
else
|
64
|
-
raise self.class.fetch_error_class, "key not found: #{key.inspect}"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
send(key)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Public
|
71
|
-
def values_at(*keys)
|
72
|
-
keys.map { |key| send(key) }
|
73
|
-
end
|
74
|
-
|
75
|
-
# Public
|
76
|
-
def keys
|
77
|
-
members.reject { |member| send(member).nil? }
|
78
|
-
end
|
79
|
-
|
80
|
-
# Public
|
81
|
-
def empty?
|
82
|
-
keys.empty?
|
83
|
-
end
|
84
|
-
|
85
|
-
# Public
|
86
|
-
def each_key
|
87
|
-
return to_enum(:each_key) unless block_given?
|
88
|
-
keys.each do |key|
|
89
|
-
yield(key)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Public
|
94
|
-
def key?(key)
|
95
|
-
keys.include?(key)
|
96
|
-
end
|
97
|
-
|
98
|
-
alias has_key? key?
|
99
|
-
|
100
|
-
# Public
|
101
|
-
def each_value
|
102
|
-
return to_enum(:each_value) unless block_given?
|
103
|
-
values.each do |value|
|
104
|
-
yield(value)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Public
|
109
|
-
def value?(value)
|
110
|
-
values.include?(value)
|
111
|
-
end
|
112
|
-
|
113
|
-
alias has_value? value?
|
114
|
-
|
115
|
-
# Public
|
116
|
-
def to_hash
|
117
|
-
hash = {}
|
118
|
-
members.each do |key|
|
119
|
-
value = send(key)
|
120
|
-
hash[key.to_sym] = value unless value.nil?
|
121
|
-
end
|
122
|
-
hash
|
123
|
-
end
|
124
|
-
|
125
|
-
# Internal
|
126
|
-
def inspect
|
127
|
-
values = []
|
128
|
-
members.each do |member|
|
129
|
-
value = send(member)
|
130
|
-
values << "#{member}=#{value.inspect}" if value
|
131
|
-
end
|
132
|
-
values = values.empty? ? ' (empty)' : (' ' << values.join(", "))
|
133
|
-
|
134
|
-
%(#<#{self.class}#{values}>)
|
135
|
-
end
|
136
|
-
|
137
|
-
# Internal
|
138
|
-
def self.options(mapping)
|
139
|
-
attribute_options.update(mapping)
|
140
|
-
end
|
141
|
-
|
142
|
-
# Internal
|
143
|
-
def self.options_for(key)
|
144
|
-
attribute_options[key]
|
145
|
-
end
|
146
|
-
|
147
|
-
# Internal
|
148
|
-
def self.attribute_options
|
149
|
-
@attribute_options ||= {}
|
150
|
-
end
|
151
|
-
|
152
|
-
def self.memoized(key)
|
153
|
-
memoized_attributes[key.to_sym] = Proc.new
|
154
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
155
|
-
def #{key}() self[:#{key}]; end
|
156
|
-
RUBY
|
157
|
-
end
|
158
|
-
|
159
|
-
def self.memoized_attributes
|
160
|
-
@memoized_attributes ||= {}
|
161
|
-
end
|
162
|
-
|
163
|
-
def [](key)
|
164
|
-
key = key.to_sym
|
165
|
-
if method = self.class.memoized_attributes[key]
|
166
|
-
super(key) || (self[key] = instance_eval(&method))
|
167
|
-
else
|
168
|
-
super
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def symbolized_key_set
|
173
|
-
@symbolized_key_set ||= Set.new(keys.map { |k| k.to_sym })
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.inherited(subclass)
|
177
|
-
super
|
178
|
-
subclass.attribute_options.update(attribute_options)
|
179
|
-
subclass.memoized_attributes.update(memoized_attributes)
|
180
|
-
end
|
181
|
-
|
182
|
-
def self.fetch_error_class
|
183
|
-
@fetch_error_class ||= if Object.const_defined?(:KeyError)
|
184
|
-
::KeyError
|
185
|
-
else
|
186
|
-
::IndexError
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
class RequestOptions < Options.new(:params_encoder, :proxy, :bind,
|
192
|
-
:timeout, :open_timeout, :boundary,
|
193
|
-
:oauth)
|
194
|
-
|
195
|
-
def []=(key, value)
|
196
|
-
if key && key.to_sym == :proxy
|
197
|
-
super(key, value ? ProxyOptions.from(value) : nil)
|
198
|
-
else
|
199
|
-
super(key, value)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
class SSLOptions < Options.new(:verify, :ca_file, :ca_path, :verify_mode,
|
205
|
-
:cert_store, :client_cert, :client_key, :certificate, :private_key, :verify_depth, :version)
|
206
|
-
|
207
|
-
def verify?
|
208
|
-
verify != false
|
209
|
-
end
|
210
|
-
|
211
|
-
def disable?
|
212
|
-
!verify?
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
class ProxyOptions < Options.new(:uri, :user, :password)
|
217
|
-
extend Forwardable
|
218
|
-
def_delegators :uri, :scheme, :scheme=, :host, :host=, :port, :port=, :path, :path=
|
219
|
-
|
220
|
-
def self.from(value)
|
221
|
-
case value
|
222
|
-
when String
|
223
|
-
value = {:uri => Utils.URI(value)}
|
224
|
-
when URI
|
225
|
-
value = {:uri => value}
|
226
|
-
when Hash, Options
|
227
|
-
if uri = value.delete(:uri)
|
228
|
-
value[:uri] = Utils.URI(uri)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
super(value)
|
232
|
-
end
|
233
|
-
|
234
|
-
memoized(:user) { uri.user && Utils.unescape(uri.user) }
|
235
|
-
memoized(:password) { uri.password && Utils.unescape(uri.password) }
|
236
|
-
end
|
237
|
-
|
238
|
-
class ConnectionOptions < Options.new(:request, :proxy, :ssl, :builder, :url,
|
239
|
-
:parallel_manager, :params, :headers, :builder_class)
|
240
|
-
|
241
|
-
options :request => RequestOptions, :ssl => SSLOptions
|
242
|
-
|
243
|
-
memoized(:request) { self.class.options_for(:request).new }
|
244
|
-
|
245
|
-
memoized(:ssl) { self.class.options_for(:ssl).new }
|
246
|
-
|
247
|
-
memoized(:builder_class) { RackBuilder }
|
248
|
-
|
249
|
-
def new_builder(block)
|
250
|
-
builder_class.new(&block)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
class Env < Options.new(:method, :body, :url, :request, :request_headers,
|
255
|
-
:ssl, :parallel_manager, :params, :response, :response_headers, :status)
|
256
|
-
|
257
|
-
ContentLength = 'Content-Length'.freeze
|
258
|
-
StatusesWithoutBody = Set.new [204, 304]
|
259
|
-
SuccessfulStatuses = 200..299
|
260
|
-
|
261
|
-
# A Set of HTTP verbs that typically send a body. If no body is set for
|
262
|
-
# these requests, the Content-Length header is set to 0.
|
263
|
-
MethodsWithBodies = Set.new [:post, :put, :patch, :options]
|
264
|
-
|
265
|
-
options :request => RequestOptions,
|
266
|
-
:request_headers => Utils::Headers, :response_headers => Utils::Headers
|
267
|
-
|
268
|
-
extend Forwardable
|
269
|
-
|
270
|
-
def_delegators :request, :params_encoder
|
271
|
-
|
272
|
-
# Public
|
273
|
-
def self.from(value)
|
274
|
-
env = super(value)
|
275
|
-
if value.respond_to?(:custom_members)
|
276
|
-
env.custom_members.update(value.custom_members)
|
277
|
-
end
|
278
|
-
env
|
279
|
-
end
|
280
|
-
|
281
|
-
# Public
|
282
|
-
def [](key)
|
283
|
-
if in_member_set?(key)
|
284
|
-
super(key)
|
285
|
-
else
|
286
|
-
custom_members[key]
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
# Public
|
291
|
-
def []=(key, value)
|
292
|
-
if in_member_set?(key)
|
293
|
-
super(key, value)
|
294
|
-
else
|
295
|
-
custom_members[key] = value
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
# Public
|
300
|
-
def success?
|
301
|
-
SuccessfulStatuses.include?(status)
|
302
|
-
end
|
303
|
-
|
304
|
-
# Public
|
305
|
-
def needs_body?
|
306
|
-
!body && MethodsWithBodies.include?(method)
|
307
|
-
end
|
308
|
-
|
309
|
-
# Public
|
310
|
-
def clear_body
|
311
|
-
request_headers[ContentLength] = '0'
|
312
|
-
self.body = ''
|
313
|
-
end
|
314
|
-
|
315
|
-
# Public
|
316
|
-
def parse_body?
|
317
|
-
!StatusesWithoutBody.include?(status)
|
318
|
-
end
|
319
|
-
|
320
|
-
# Public
|
321
|
-
def parallel?
|
322
|
-
!!parallel_manager
|
323
|
-
end
|
324
|
-
|
325
|
-
def inspect
|
326
|
-
attrs = [nil]
|
327
|
-
members.each do |mem|
|
328
|
-
if value = send(mem)
|
329
|
-
attrs << "@#{mem}=#{value.inspect}"
|
330
|
-
end
|
331
|
-
end
|
332
|
-
if !custom_members.empty?
|
333
|
-
attrs << "@custom=#{custom_members.inspect}"
|
334
|
-
end
|
335
|
-
%(#<#{self.class}#{attrs.join(" ")}>)
|
336
|
-
end
|
337
|
-
|
338
|
-
# Internal
|
339
|
-
def custom_members
|
340
|
-
@custom_members ||= {}
|
341
|
-
end
|
342
|
-
|
343
|
-
# Internal
|
344
|
-
if members.first.is_a?(Symbol)
|
345
|
-
def in_member_set?(key)
|
346
|
-
self.class.member_set.include?(key.to_sym)
|
347
|
-
end
|
348
|
-
else
|
349
|
-
def in_member_set?(key)
|
350
|
-
self.class.member_set.include?(key.to_s)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
# Internal
|
355
|
-
def self.member_set
|
356
|
-
@member_set ||= Set.new(members)
|
357
|
-
end
|
358
|
-
end
|
359
|
-
end
|
@@ -1,197 +0,0 @@
|
|
1
|
-
require "forwardable"
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
module NestedParamsEncoder
|
5
|
-
class << self
|
6
|
-
extend Forwardable
|
7
|
-
def_delegators :'Faraday::Utils', :escape, :unescape
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.encode(params)
|
11
|
-
return nil if params == nil
|
12
|
-
|
13
|
-
if !params.is_a?(Array)
|
14
|
-
if !params.respond_to?(:to_hash)
|
15
|
-
raise TypeError,
|
16
|
-
"Can't convert #{params.class} into Hash."
|
17
|
-
end
|
18
|
-
params = params.to_hash
|
19
|
-
params = params.map do |key, value|
|
20
|
-
key = key.to_s if key.kind_of?(Symbol)
|
21
|
-
[key, value]
|
22
|
-
end
|
23
|
-
# Useful default for OAuth and caching.
|
24
|
-
# Only to be used for non-Array inputs. Arrays should preserve order.
|
25
|
-
params.sort!
|
26
|
-
end
|
27
|
-
|
28
|
-
# Helper lambda
|
29
|
-
to_query = lambda do |parent, value|
|
30
|
-
if value.is_a?(Hash)
|
31
|
-
value = value.map do |key, val|
|
32
|
-
key = escape(key)
|
33
|
-
[key, val]
|
34
|
-
end
|
35
|
-
value.sort!
|
36
|
-
buffer = ""
|
37
|
-
value.each do |key, val|
|
38
|
-
new_parent = "#{parent}%5B#{key}%5D"
|
39
|
-
buffer << "#{to_query.call(new_parent, val)}&"
|
40
|
-
end
|
41
|
-
return buffer.chop
|
42
|
-
elsif value.is_a?(Array)
|
43
|
-
buffer = ""
|
44
|
-
value.each_with_index do |val, i|
|
45
|
-
new_parent = "#{parent}%5B%5D"
|
46
|
-
buffer << "#{to_query.call(new_parent, val)}&"
|
47
|
-
end
|
48
|
-
return buffer.chop
|
49
|
-
elsif value.nil?
|
50
|
-
return parent
|
51
|
-
else
|
52
|
-
encoded_value = escape(value)
|
53
|
-
return "#{parent}=#{encoded_value}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# The params have form [['key1', 'value1'], ['key2', 'value2']].
|
58
|
-
buffer = ''
|
59
|
-
params.each do |parent, value|
|
60
|
-
encoded_parent = escape(parent)
|
61
|
-
buffer << "#{to_query.call(encoded_parent, value)}&"
|
62
|
-
end
|
63
|
-
return buffer.chop
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.decode(query)
|
67
|
-
return nil if query == nil
|
68
|
-
|
69
|
-
params = {}
|
70
|
-
query.split("&").each do |pair|
|
71
|
-
next if pair.empty?
|
72
|
-
key, value = pair.split("=", 2)
|
73
|
-
key = unescape(key)
|
74
|
-
value = unescape(value.gsub(/\+/, ' ')) if value
|
75
|
-
|
76
|
-
subkeys = key.scan(/[^\[\]]+(?:\]?\[\])?/)
|
77
|
-
context = params
|
78
|
-
subkeys.each_with_index do |subkey, i|
|
79
|
-
is_array = subkey =~ /[\[\]]+\Z/
|
80
|
-
subkey = $` if is_array
|
81
|
-
last_subkey = i == subkeys.length - 1
|
82
|
-
|
83
|
-
if !last_subkey || is_array
|
84
|
-
value_type = is_array ? Array : Hash
|
85
|
-
if context[subkey] && !context[subkey].is_a?(value_type)
|
86
|
-
raise TypeError, "expected %s (got %s) for param `%s'" % [
|
87
|
-
value_type.name,
|
88
|
-
context[subkey].class.name,
|
89
|
-
subkey
|
90
|
-
]
|
91
|
-
end
|
92
|
-
context = (context[subkey] ||= value_type.new)
|
93
|
-
end
|
94
|
-
|
95
|
-
if context.is_a?(Array) && !is_array
|
96
|
-
if !context.last.is_a?(Hash) || context.last.has_key?(subkey)
|
97
|
-
context << {}
|
98
|
-
end
|
99
|
-
context = context.last
|
100
|
-
end
|
101
|
-
|
102
|
-
if last_subkey
|
103
|
-
if is_array
|
104
|
-
context << value
|
105
|
-
else
|
106
|
-
context[subkey] = value
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
dehash(params, 0)
|
113
|
-
end
|
114
|
-
|
115
|
-
# Internal: convert a nested hash with purely numeric keys into an array.
|
116
|
-
# FIXME: this is not compatible with Rack::Utils.parse_nested_query
|
117
|
-
def self.dehash(hash, depth)
|
118
|
-
hash.each do |key, value|
|
119
|
-
hash[key] = dehash(value, depth + 1) if value.kind_of?(Hash)
|
120
|
-
end
|
121
|
-
|
122
|
-
if depth > 0 && !hash.empty? && hash.keys.all? { |k| k =~ /^\d+$/ }
|
123
|
-
hash.keys.sort.inject([]) { |all, key| all << hash[key] }
|
124
|
-
else
|
125
|
-
hash
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
module FlatParamsEncoder
|
131
|
-
class << self
|
132
|
-
extend Forwardable
|
133
|
-
def_delegators :'Faraday::Utils', :escape, :unescape
|
134
|
-
end
|
135
|
-
|
136
|
-
def self.encode(params)
|
137
|
-
return nil if params == nil
|
138
|
-
|
139
|
-
if !params.is_a?(Array)
|
140
|
-
if !params.respond_to?(:to_hash)
|
141
|
-
raise TypeError,
|
142
|
-
"Can't convert #{params.class} into Hash."
|
143
|
-
end
|
144
|
-
params = params.to_hash
|
145
|
-
params = params.map do |key, value|
|
146
|
-
key = key.to_s if key.kind_of?(Symbol)
|
147
|
-
[key, value]
|
148
|
-
end
|
149
|
-
# Useful default for OAuth and caching.
|
150
|
-
# Only to be used for non-Array inputs. Arrays should preserve order.
|
151
|
-
params.sort!
|
152
|
-
end
|
153
|
-
|
154
|
-
# The params have form [['key1', 'value1'], ['key2', 'value2']].
|
155
|
-
buffer = ''
|
156
|
-
params.each do |key, value|
|
157
|
-
encoded_key = escape(key)
|
158
|
-
value = value.to_s if value == true || value == false
|
159
|
-
if value == nil
|
160
|
-
buffer << "#{encoded_key}&"
|
161
|
-
elsif value.kind_of?(Array)
|
162
|
-
value.each do |sub_value|
|
163
|
-
encoded_value = escape(sub_value)
|
164
|
-
buffer << "#{encoded_key}=#{encoded_value}&"
|
165
|
-
end
|
166
|
-
else
|
167
|
-
encoded_value = escape(value)
|
168
|
-
buffer << "#{encoded_key}=#{encoded_value}&"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
return buffer.chop
|
172
|
-
end
|
173
|
-
|
174
|
-
def self.decode(query)
|
175
|
-
empty_accumulator = {}
|
176
|
-
return nil if query == nil
|
177
|
-
split_query = (query.split('&').map do |pair|
|
178
|
-
pair.split('=', 2) if pair && !pair.empty?
|
179
|
-
end).compact
|
180
|
-
return split_query.inject(empty_accumulator.dup) do |accu, pair|
|
181
|
-
pair[0] = unescape(pair[0])
|
182
|
-
pair[1] = true if pair[1].nil?
|
183
|
-
if pair[1].respond_to?(:to_str)
|
184
|
-
pair[1] = unescape(pair[1].to_str.gsub(/\+/, " "))
|
185
|
-
end
|
186
|
-
if accu[pair[0]].kind_of?(Array)
|
187
|
-
accu[pair[0]] << pair[1]
|
188
|
-
elsif accu[pair[0]]
|
189
|
-
accu[pair[0]] = [accu[pair[0]], pair[1]]
|
190
|
-
else
|
191
|
-
accu[pair[0]] = pair[1]
|
192
|
-
end
|
193
|
-
accu
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|