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.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gs/bin/rake +12 -8
  3. data/.gs/specifications/rake-10.5.0.gemspec +24 -28
  4. data/.tool-versions +1 -0
  5. data/lib/mercadopago/custom_checkout/version.rb +1 -1
  6. data/mercadopago-custom-checkout.gemspec +3 -3
  7. metadata +14 -125
  8. data/.gs/cache/faraday-0.9.2.gem +0 -0
  9. data/.gs/cache/minitest-5.9.0.gem +0 -0
  10. data/.gs/cache/multi_json-1.12.1.gem +0 -0
  11. data/.gs/cache/multipart-post-2.0.0.gem +0 -0
  12. data/.gs/gems/faraday-0.9.2/LICENSE.md +0 -20
  13. data/.gs/gems/faraday-0.9.2/README.md +0 -245
  14. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_http.rb +0 -237
  15. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
  16. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
  17. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_synchrony.rb +0 -100
  18. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/excon.rb +0 -81
  19. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/httpclient.rb +0 -117
  20. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb +0 -130
  21. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/net_http_persistent.rb +0 -49
  22. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/patron.rb +0 -78
  23. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/rack.rb +0 -58
  24. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/test.rb +0 -162
  25. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/typhoeus.rb +0 -123
  26. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter.rb +0 -46
  27. data/.gs/gems/faraday-0.9.2/lib/faraday/autoload.rb +0 -84
  28. data/.gs/gems/faraday-0.9.2/lib/faraday/connection.rb +0 -437
  29. data/.gs/gems/faraday-0.9.2/lib/faraday/error.rb +0 -53
  30. data/.gs/gems/faraday-0.9.2/lib/faraday/middleware.rb +0 -37
  31. data/.gs/gems/faraday-0.9.2/lib/faraday/options.rb +0 -359
  32. data/.gs/gems/faraday-0.9.2/lib/faraday/parameters.rb +0 -197
  33. data/.gs/gems/faraday-0.9.2/lib/faraday/rack_builder.rb +0 -213
  34. data/.gs/gems/faraday-0.9.2/lib/faraday/request/authorization.rb +0 -42
  35. data/.gs/gems/faraday-0.9.2/lib/faraday/request/basic_authentication.rb +0 -13
  36. data/.gs/gems/faraday-0.9.2/lib/faraday/request/instrumentation.rb +0 -36
  37. data/.gs/gems/faraday-0.9.2/lib/faraday/request/multipart.rb +0 -63
  38. data/.gs/gems/faraday-0.9.2/lib/faraday/request/retry.rb +0 -154
  39. data/.gs/gems/faraday-0.9.2/lib/faraday/request/token_authentication.rb +0 -15
  40. data/.gs/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb +0 -36
  41. data/.gs/gems/faraday-0.9.2/lib/faraday/request.rb +0 -92
  42. data/.gs/gems/faraday-0.9.2/lib/faraday/response/logger.rb +0 -59
  43. data/.gs/gems/faraday-0.9.2/lib/faraday/response/raise_error.rb +0 -21
  44. data/.gs/gems/faraday-0.9.2/lib/faraday/response.rb +0 -93
  45. data/.gs/gems/faraday-0.9.2/lib/faraday/upload_io.rb +0 -67
  46. data/.gs/gems/faraday-0.9.2/lib/faraday/utils.rb +0 -309
  47. data/.gs/gems/faraday-0.9.2/lib/faraday.rb +0 -268
  48. data/.gs/gems/minitest-5.9.0/.autotest +0 -34
  49. data/.gs/gems/minitest-5.9.0/History.rdoc +0 -1176
  50. data/.gs/gems/minitest-5.9.0/Manifest.txt +0 -26
  51. data/.gs/gems/minitest-5.9.0/README.rdoc +0 -656
  52. data/.gs/gems/minitest-5.9.0/Rakefile +0 -72
  53. data/.gs/gems/minitest-5.9.0/design_rationale.rb +0 -52
  54. data/.gs/gems/minitest-5.9.0/lib/hoe/minitest.rb +0 -26
  55. data/.gs/gems/minitest-5.9.0/lib/minitest/assertions.rb +0 -674
  56. data/.gs/gems/minitest-5.9.0/lib/minitest/autorun.rb +0 -13
  57. data/.gs/gems/minitest-5.9.0/lib/minitest/benchmark.rb +0 -424
  58. data/.gs/gems/minitest-5.9.0/lib/minitest/expectations.rb +0 -284
  59. data/.gs/gems/minitest-5.9.0/lib/minitest/hell.rb +0 -17
  60. data/.gs/gems/minitest-5.9.0/lib/minitest/mock.rb +0 -232
  61. data/.gs/gems/minitest-5.9.0/lib/minitest/parallel.rb +0 -69
  62. data/.gs/gems/minitest-5.9.0/lib/minitest/pride.rb +0 -4
  63. data/.gs/gems/minitest-5.9.0/lib/minitest/pride_plugin.rb +0 -142
  64. data/.gs/gems/minitest-5.9.0/lib/minitest/spec.rb +0 -331
  65. data/.gs/gems/minitest-5.9.0/lib/minitest/test.rb +0 -284
  66. data/.gs/gems/minitest-5.9.0/lib/minitest/unit.rb +0 -45
  67. data/.gs/gems/minitest-5.9.0/lib/minitest.rb +0 -815
  68. data/.gs/gems/minitest-5.9.0/test/minitest/metametameta.rb +0 -90
  69. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_benchmark.rb +0 -137
  70. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_mock.rb +0 -512
  71. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_reporter.rb +0 -281
  72. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_spec.rb +0 -967
  73. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_test.rb +0 -1983
  74. data/.gs/gems/multi_json-1.12.1/CHANGELOG.md +0 -245
  75. data/.gs/gems/multi_json-1.12.1/CONTRIBUTING.md +0 -46
  76. data/.gs/gems/multi_json-1.12.1/LICENSE.md +0 -20
  77. data/.gs/gems/multi_json-1.12.1/README.md +0 -121
  78. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapter.rb +0 -49
  79. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb +0 -15
  80. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb +0 -20
  81. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb +0 -25
  82. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb +0 -23
  83. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb +0 -11
  84. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb +0 -11
  85. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb +0 -32
  86. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb +0 -25
  87. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb +0 -23
  88. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb +0 -19
  89. data/.gs/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb +0 -43
  90. data/.gs/gems/multi_json-1.12.1/lib/multi_json/options.rb +0 -39
  91. data/.gs/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb +0 -29
  92. data/.gs/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb +0 -17
  93. data/.gs/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb +0 -606
  94. data/.gs/gems/multi_json-1.12.1/lib/multi_json/version.rb +0 -17
  95. data/.gs/gems/multi_json-1.12.1/lib/multi_json.rb +0 -161
  96. data/.gs/gems/multi_json-1.12.1/multi_json.gemspec +0 -20
  97. data/.gs/gems/multipart-post-2.0.0/.gitignore +0 -6
  98. data/.gs/gems/multipart-post-2.0.0/.travis.yml +0 -7
  99. data/.gs/gems/multipart-post-2.0.0/Gemfile +0 -14
  100. data/.gs/gems/multipart-post-2.0.0/History.txt +0 -60
  101. data/.gs/gems/multipart-post-2.0.0/Manifest.txt +0 -9
  102. data/.gs/gems/multipart-post-2.0.0/README.md +0 -77
  103. data/.gs/gems/multipart-post-2.0.0/Rakefile +0 -9
  104. data/.gs/gems/multipart-post-2.0.0/lib/composite_io.rb +0 -108
  105. data/.gs/gems/multipart-post-2.0.0/lib/multipart_post.rb +0 -9
  106. data/.gs/gems/multipart-post-2.0.0/lib/multipartable.rb +0 -29
  107. data/.gs/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +0 -27
  108. data/.gs/gems/multipart-post-2.0.0/lib/parts.rb +0 -96
  109. data/.gs/gems/multipart-post-2.0.0/multipart-post.gemspec +0 -22
  110. data/.gs/gems/multipart-post-2.0.0/test/multibyte.txt +0 -1
  111. data/.gs/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +0 -110
  112. data/.gs/gems/multipart-post-2.0.0/test/test_composite_io.rb +0 -115
  113. data/.gs/gems/multipart-post-2.0.0/test/test_parts.rb +0 -86
  114. data/.gs/specifications/faraday-0.9.2.gemspec +0 -31
  115. data/.gs/specifications/minitest-5.9.0.gemspec +0 -39
  116. data/.gs/specifications/multi_json-1.12.1.gemspec +0 -33
  117. data/.gs/specifications/multipart-post-2.0.0.gemspec +0 -22
  118. data/.ruby-version +0 -1
@@ -1,213 +0,0 @@
1
- module Faraday
2
- # A Builder that processes requests into responses by passing through an inner
3
- # middleware stack (heavily inspired by Rack).
4
- #
5
- # Faraday::Connection.new(:url => 'http://sushi.com') do |builder|
6
- # builder.request :url_encoded # Faraday::Request::UrlEncoded
7
- # builder.adapter :net_http # Faraday::Adapter::NetHttp
8
- # end
9
- class RackBuilder
10
- attr_accessor :handlers
11
-
12
- # Error raised when trying to modify the stack after calling `lock!`
13
- class StackLocked < RuntimeError; end
14
-
15
- # borrowed from ActiveSupport::Dependencies::Reference &
16
- # ActionDispatch::MiddlewareStack::Middleware
17
- class Handler
18
- @@constants_mutex = Mutex.new
19
- @@constants = Hash.new { |h, k|
20
- value = k.respond_to?(:constantize) ? k.constantize : Object.const_get(k)
21
- @@constants_mutex.synchronize { h[k] = value }
22
- }
23
-
24
- attr_reader :name
25
-
26
- def initialize(klass, *args, &block)
27
- @name = klass.to_s
28
- if klass.respond_to?(:name)
29
- @@constants_mutex.synchronize { @@constants[@name] = klass }
30
- end
31
- @args, @block = args, block
32
- end
33
-
34
- def klass() @@constants[@name] end
35
- def inspect() @name end
36
-
37
- def ==(other)
38
- if other.is_a? Handler
39
- self.name == other.name
40
- elsif other.respond_to? :name
41
- klass == other
42
- else
43
- @name == other.to_s
44
- end
45
- end
46
-
47
- def build(app)
48
- klass.new(app, *@args, &@block)
49
- end
50
- end
51
-
52
- def initialize(handlers = [])
53
- @handlers = handlers
54
- if block_given?
55
- build(&Proc.new)
56
- elsif @handlers.empty?
57
- # default stack, if nothing else is configured
58
- self.request :url_encoded
59
- self.adapter Faraday.default_adapter
60
- end
61
- end
62
-
63
- def build(options = {})
64
- raise_if_locked
65
- @handlers.clear unless options[:keep]
66
- yield(self) if block_given?
67
- end
68
-
69
- def [](idx)
70
- @handlers[idx]
71
- end
72
-
73
- # Locks the middleware stack to ensure no further modifications are possible.
74
- def lock!
75
- @handlers.freeze
76
- end
77
-
78
- def locked?
79
- @handlers.frozen?
80
- end
81
-
82
- def use(klass, *args, &block)
83
- if klass.is_a? Symbol
84
- use_symbol(Faraday::Middleware, klass, *args, &block)
85
- else
86
- raise_if_locked
87
- @handlers << self.class::Handler.new(klass, *args, &block)
88
- end
89
- end
90
-
91
- def request(key, *args, &block)
92
- use_symbol(Faraday::Request, key, *args, &block)
93
- end
94
-
95
- def response(key, *args, &block)
96
- use_symbol(Faraday::Response, key, *args, &block)
97
- end
98
-
99
- def adapter(key, *args, &block)
100
- use_symbol(Faraday::Adapter, key, *args, &block)
101
- end
102
-
103
- ## methods to push onto the various positions in the stack:
104
-
105
- def insert(index, *args, &block)
106
- raise_if_locked
107
- index = assert_index(index)
108
- handler = self.class::Handler.new(*args, &block)
109
- @handlers.insert(index, handler)
110
- end
111
-
112
- alias_method :insert_before, :insert
113
-
114
- def insert_after(index, *args, &block)
115
- index = assert_index(index)
116
- insert(index + 1, *args, &block)
117
- end
118
-
119
- def swap(index, *args, &block)
120
- raise_if_locked
121
- index = assert_index(index)
122
- @handlers.delete_at(index)
123
- insert(index, *args, &block)
124
- end
125
-
126
- def delete(handler)
127
- raise_if_locked
128
- @handlers.delete(handler)
129
- end
130
-
131
- # Processes a Request into a Response by passing it through this Builder's
132
- # middleware stack.
133
- #
134
- # connection - Faraday::Connection
135
- # request - Faraday::Request
136
- #
137
- # Returns a Faraday::Response.
138
- def build_response(connection, request)
139
- app.call(build_env(connection, request))
140
- end
141
-
142
- # The "rack app" wrapped in middleware. All requests are sent here.
143
- #
144
- # The builder is responsible for creating the app object. After this,
145
- # the builder gets locked to ensure no further modifications are made
146
- # to the middleware stack.
147
- #
148
- # Returns an object that responds to `call` and returns a Response.
149
- def app
150
- @app ||= begin
151
- lock!
152
- to_app(lambda { |env|
153
- response = Response.new
154
- env.response = response
155
- response.finish(env) unless env.parallel?
156
- response
157
- })
158
- end
159
- end
160
-
161
- def to_app(inner_app)
162
- # last added handler is the deepest and thus closest to the inner app
163
- @handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) }
164
- end
165
-
166
- def ==(other)
167
- other.is_a?(self.class) && @handlers == other.handlers
168
- end
169
-
170
- def dup
171
- self.class.new(@handlers.dup)
172
- end
173
-
174
- # ENV Keys
175
- # :method - a symbolized request method (:get, :post)
176
- # :body - the request body that will eventually be converted to a string.
177
- # :url - URI instance for the current request.
178
- # :status - HTTP response status code
179
- # :request_headers - hash of HTTP Headers to be sent to the server
180
- # :response_headers - Hash of HTTP headers from the server
181
- # :parallel_manager - sent if the connection is in parallel mode
182
- # :request - Hash of options for configuring the request.
183
- # :timeout - open/read timeout Integer in seconds
184
- # :open_timeout - read timeout Integer in seconds
185
- # :proxy - Hash of proxy options
186
- # :uri - Proxy Server URI
187
- # :user - Proxy server username
188
- # :password - Proxy server password
189
- # :ssl - Hash of options for configuring SSL requests.
190
- def build_env(connection, request)
191
- Env.new(request.method, request.body,
192
- connection.build_exclusive_url(request.path, request.params, request.options.params_encoder),
193
- request.options, request.headers, connection.ssl,
194
- connection.parallel_manager)
195
- end
196
-
197
- private
198
-
199
- def raise_if_locked
200
- raise StackLocked, "can't modify middleware stack after making a request" if locked?
201
- end
202
-
203
- def use_symbol(mod, key, *args, &block)
204
- use(mod.lookup_middleware(key), *args, &block)
205
- end
206
-
207
- def assert_index(index)
208
- idx = index.is_a?(Integer) ? index : @handlers.index(index)
209
- raise "No such handler: #{index.inspect}" unless idx
210
- idx
211
- end
212
- end
213
- end
@@ -1,42 +0,0 @@
1
- module Faraday
2
- class Request::Authorization < Faraday::Middleware
3
- KEY = "Authorization".freeze unless defined? KEY
4
-
5
- # Public
6
- def self.header(type, token)
7
- case token
8
- when String, Symbol
9
- "#{type} #{token}"
10
- when Hash
11
- build_hash(type.to_s, token)
12
- else
13
- raise ArgumentError, "Can't build an Authorization #{type} header from #{token.inspect}"
14
- end
15
- end
16
-
17
- # Internal
18
- def self.build_hash(type, hash)
19
- offset = KEY.size + type.size + 3
20
- comma = ",\n#{' ' * offset}"
21
- values = []
22
- hash.each do |key, value|
23
- values << "#{key}=#{value.to_s.inspect}"
24
- end
25
- "#{type} #{values * comma}"
26
- end
27
-
28
- def initialize(app, type, token)
29
- @header_value = self.class.header(type, token)
30
- super(app)
31
- end
32
-
33
- # Public
34
- def call(env)
35
- unless env.request_headers[KEY]
36
- env.request_headers[KEY] = @header_value
37
- end
38
- @app.call(env)
39
- end
40
- end
41
- end
42
-
@@ -1,13 +0,0 @@
1
- require 'base64'
2
-
3
- module Faraday
4
- class Request::BasicAuthentication < Request.load_middleware(:authorization)
5
- # Public
6
- def self.header(login, pass)
7
- value = Base64.encode64([login, pass].join(':'))
8
- value.gsub!("\n", '')
9
- super(:Basic, value)
10
- end
11
- end
12
- end
13
-
@@ -1,36 +0,0 @@
1
- module Faraday
2
- class Request::Instrumentation < Faraday::Middleware
3
- class Options < Faraday::Options.new(:name, :instrumenter)
4
- def name
5
- self[:name] ||= 'request.faraday'
6
- end
7
-
8
- def instrumenter
9
- self[:instrumenter] ||= ActiveSupport::Notifications
10
- end
11
- end
12
-
13
- # Public: Instruments requests using Active Support.
14
- #
15
- # Measures time spent only for synchronous requests.
16
- #
17
- # Examples
18
- #
19
- # ActiveSupport::Notifications.subscribe('request.faraday') do |name, starts, ends, _, env|
20
- # url = env[:url]
21
- # http_method = env[:method].to_s.upcase
22
- # duration = ends - starts
23
- # $stderr.puts '[%s] %s %s (%.3f s)' % [url.host, http_method, url.request_uri, duration]
24
- # end
25
- def initialize(app, options = nil)
26
- super(app)
27
- @name, @instrumenter = Options.from(options).values_at(:name, :instrumenter)
28
- end
29
-
30
- def call(env)
31
- @instrumenter.instrument(@name, env) do
32
- @app.call(env)
33
- end
34
- end
35
- end
36
- end
@@ -1,63 +0,0 @@
1
- require File.expand_path("../url_encoded", __FILE__)
2
-
3
- module Faraday
4
- class Request::Multipart < Request::UrlEncoded
5
- self.mime_type = 'multipart/form-data'.freeze
6
- DEFAULT_BOUNDARY = "-----------RubyMultipartPost".freeze unless defined? DEFAULT_BOUNDARY
7
-
8
- def call(env)
9
- match_content_type(env) do |params|
10
- env.request.boundary ||= DEFAULT_BOUNDARY
11
- env.request_headers[CONTENT_TYPE] += "; boundary=#{env.request.boundary}"
12
- env.body = create_multipart(env, params)
13
- end
14
- @app.call env
15
- end
16
-
17
- def process_request?(env)
18
- type = request_type(env)
19
- env.body.respond_to?(:each_key) and !env.body.empty? and (
20
- (type.empty? and has_multipart?(env.body)) or
21
- type == self.class.mime_type
22
- )
23
- end
24
-
25
- def has_multipart?(obj)
26
- # string is an enum in 1.8, returning list of itself
27
- if obj.respond_to?(:each) && !obj.is_a?(String)
28
- (obj.respond_to?(:values) ? obj.values : obj).each do |val|
29
- return true if (val.respond_to?(:content_type) || has_multipart?(val))
30
- end
31
- end
32
- false
33
- end
34
-
35
- def create_multipart(env, params)
36
- boundary = env.request.boundary
37
- parts = process_params(params) do |key, value|
38
- Faraday::Parts::Part.new(boundary, key, value)
39
- end
40
- parts << Faraday::Parts::EpiloguePart.new(boundary)
41
-
42
- body = Faraday::CompositeReadIO.new(parts)
43
- env.request_headers[Faraday::Env::ContentLength] = body.length.to_s
44
- return body
45
- end
46
-
47
- def process_params(params, prefix = nil, pieces = nil, &block)
48
- params.inject(pieces || []) do |all, (key, value)|
49
- key = "#{prefix}[#{key}]" if prefix
50
-
51
- case value
52
- when Array
53
- values = value.inject([]) { |a,v| a << [nil, v] }
54
- process_params(values, key, all, &block)
55
- when Hash
56
- process_params(value, key, all, &block)
57
- else
58
- all << block.call(key, value)
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,154 +0,0 @@
1
- module Faraday
2
- # Catches exceptions and retries each request a limited number of times.
3
- #
4
- # By default, it retries 2 times and handles only timeout exceptions. It can
5
- # be configured with an arbitrary number of retries, a list of exceptions to
6
- # handle, a retry interval, a percentage of randomness to add to the retry
7
- # interval, and a backoff factor.
8
- #
9
- # Examples
10
- #
11
- # Faraday.new do |conn|
12
- # conn.request :retry, max: 2, interval: 0.05,
13
- # interval_randomness: 0.5, backoff_factor: 2
14
- # exceptions: [CustomException, 'Timeout::Error']
15
- # conn.adapter ...
16
- # end
17
- #
18
- # This example will result in a first interval that is random between 0.05 and 0.075 and a second
19
- # interval that is random between 0.1 and 0.15
20
- #
21
- class Request::Retry < Faraday::Middleware
22
-
23
- IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put]
24
-
25
- class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
26
- :backoff_factor, :exceptions, :methods, :retry_if)
27
- DEFAULT_CHECK = lambda { |env,exception| false }
28
-
29
- def self.from(value)
30
- if Fixnum === value
31
- new(value)
32
- else
33
- super(value)
34
- end
35
- end
36
-
37
- def max
38
- (self[:max] ||= 2).to_i
39
- end
40
-
41
- def interval
42
- (self[:interval] ||= 0).to_f
43
- end
44
-
45
- def max_interval
46
- (self[:max_interval] ||= Float::MAX).to_f
47
- end
48
-
49
- def interval_randomness
50
- (self[:interval_randomness] ||= 0).to_f
51
- end
52
-
53
- def backoff_factor
54
- (self[:backoff_factor] ||= 1).to_f
55
- end
56
-
57
- def exceptions
58
- Array(self[:exceptions] ||= [Errno::ETIMEDOUT, 'Timeout::Error',
59
- Error::TimeoutError])
60
- end
61
-
62
- def methods
63
- Array(self[:methods] ||= IDEMPOTENT_METHODS)
64
- end
65
-
66
- def retry_if
67
- self[:retry_if] ||= DEFAULT_CHECK
68
- end
69
-
70
- end
71
-
72
- # Public: Initialize middleware
73
- #
74
- # Options:
75
- # max - Maximum number of retries (default: 2)
76
- # interval - Pause in seconds between retries (default: 0)
77
- # interval_randomness - The maximum random interval amount expressed
78
- # as a float between 0 and 1 to use in addition to the
79
- # interval. (default: 0)
80
- # max_interval - An upper limit for the interval (default: Float::MAX)
81
- # backoff_factor - The amount to multiple each successive retry's
82
- # interval amount by in order to provide backoff
83
- # (default: 1)
84
- # exceptions - The list of exceptions to handle. Exceptions can be
85
- # given as Class, Module, or String. (default:
86
- # [Errno::ETIMEDOUT, Timeout::Error,
87
- # Error::TimeoutError])
88
- # methods - A list of HTTP methods to retry without calling retry_if. Pass
89
- # an empty Array to call retry_if for all exceptions.
90
- # (defaults to the idempotent HTTP methods in IDEMPOTENT_METHODS)
91
- # retry_if - block that will receive the env object and the exception raised
92
- # and should decide if the code should retry still the action or
93
- # not independent of the retry count. This would be useful
94
- # if the exception produced is non-recoverable or if the
95
- # the HTTP method called is not idempotent.
96
- # (defaults to return false)
97
- def initialize(app, options = nil)
98
- super(app)
99
- @options = Options.from(options)
100
- @errmatch = build_exception_matcher(@options.exceptions)
101
- end
102
-
103
- def sleep_amount(retries)
104
- retry_index = @options.max - retries
105
- current_interval = @options.interval * (@options.backoff_factor ** retry_index)
106
- current_interval = [current_interval, @options.max_interval].min
107
- random_interval = rand * @options.interval_randomness.to_f * @options.interval
108
- current_interval + random_interval
109
- end
110
-
111
- def call(env)
112
- retries = @options.max
113
- request_body = env[:body]
114
- begin
115
- env[:body] = request_body # after failure env[:body] is set to the response body
116
- @app.call(env)
117
- rescue @errmatch => exception
118
- if retries > 0 && retry_request?(env, exception)
119
- retries -= 1
120
- sleep sleep_amount(retries + 1)
121
- retry
122
- end
123
- raise
124
- end
125
- end
126
-
127
- # Private: construct an exception matcher object.
128
- #
129
- # An exception matcher for the rescue clause can usually be any object that
130
- # responds to `===`, but for Ruby 1.8 it has to be a Class or Module.
131
- def build_exception_matcher(exceptions)
132
- matcher = Module.new
133
- (class << matcher; self; end).class_eval do
134
- define_method(:===) do |error|
135
- exceptions.any? do |ex|
136
- if ex.is_a? Module
137
- error.is_a? ex
138
- else
139
- error.class.to_s == ex.to_s
140
- end
141
- end
142
- end
143
- end
144
- matcher
145
- end
146
-
147
- private
148
-
149
- def retry_request?(env, exception)
150
- @options.methods.include?(env[:method]) || @options.retry_if.call(env, exception)
151
- end
152
-
153
- end
154
- end
@@ -1,15 +0,0 @@
1
- module Faraday
2
- class Request::TokenAuthentication < Request.load_middleware(:authorization)
3
- # Public
4
- def self.header(token, options = nil)
5
- options ||= {}
6
- options[:token] = token
7
- super(:Token, options)
8
- end
9
-
10
- def initialize(app, token, options = nil)
11
- super(app, token, options)
12
- end
13
- end
14
- end
15
-
@@ -1,36 +0,0 @@
1
- module Faraday
2
- class Request::UrlEncoded < Faraday::Middleware
3
- CONTENT_TYPE = 'Content-Type'.freeze unless defined? CONTENT_TYPE
4
-
5
- class << self
6
- attr_accessor :mime_type
7
- end
8
- self.mime_type = 'application/x-www-form-urlencoded'.freeze
9
-
10
- def call(env)
11
- match_content_type(env) do |data|
12
- params = Faraday::Utils::ParamsHash[data]
13
- env.body = params.to_query(env.params_encoder)
14
- end
15
- @app.call env
16
- end
17
-
18
- def match_content_type(env)
19
- if process_request?(env)
20
- env.request_headers[CONTENT_TYPE] ||= self.class.mime_type
21
- yield(env.body) unless env.body.respond_to?(:to_str)
22
- end
23
- end
24
-
25
- def process_request?(env)
26
- type = request_type(env)
27
- env.body and (type.empty? or type == self.class.mime_type)
28
- end
29
-
30
- def request_type(env)
31
- type = env.request_headers[CONTENT_TYPE].to_s
32
- type = type.split(';', 2).first if type.index(';')
33
- type
34
- end
35
- end
36
- end
@@ -1,92 +0,0 @@
1
- module Faraday
2
- # Used to setup urls, params, headers, and the request body in a sane manner.
3
- #
4
- # @connection.post do |req|
5
- # req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
6
- # req.headers['b'] = '2' # Header
7
- # req.params['c'] = '3' # GET Param
8
- # req['b'] = '2' # also Header
9
- # req.body = 'abc'
10
- # end
11
- #
12
- class Request < Struct.new(:method, :path, :params, :headers, :body, :options)
13
- extend MiddlewareRegistry
14
-
15
- register_middleware File.expand_path('../request', __FILE__),
16
- :url_encoded => [:UrlEncoded, 'url_encoded'],
17
- :multipart => [:Multipart, 'multipart'],
18
- :retry => [:Retry, 'retry'],
19
- :authorization => [:Authorization, 'authorization'],
20
- :basic_auth => [:BasicAuthentication, 'basic_authentication'],
21
- :token_auth => [:TokenAuthentication, 'token_authentication'],
22
- :instrumentation => [:Instrumentation, 'instrumentation']
23
-
24
- def self.create(request_method)
25
- new(request_method).tap do |request|
26
- yield(request) if block_given?
27
- end
28
- end
29
-
30
- # Public: Replace params, preserving the existing hash type
31
- def params=(hash)
32
- if params
33
- params.replace hash
34
- else
35
- super
36
- end
37
- end
38
-
39
- # Public: Replace request headers, preserving the existing hash type
40
- def headers=(hash)
41
- if headers
42
- headers.replace hash
43
- else
44
- super
45
- end
46
- end
47
-
48
- def url(path, params = nil)
49
- if path.respond_to? :query
50
- if query = path.query
51
- path = path.dup
52
- path.query = nil
53
- end
54
- else
55
- path, query = path.split('?', 2)
56
- end
57
- self.path = path
58
- self.params.merge_query query, options.params_encoder
59
- self.params.update(params) if params
60
- end
61
-
62
- def [](key)
63
- headers[key]
64
- end
65
-
66
- def []=(key, value)
67
- headers[key] = value
68
- end
69
-
70
- # ENV Keys
71
- # :method - a symbolized request method (:get, :post)
72
- # :body - the request body that will eventually be converted to a string.
73
- # :url - URI instance for the current request.
74
- # :status - HTTP response status code
75
- # :request_headers - hash of HTTP Headers to be sent to the server
76
- # :response_headers - Hash of HTTP headers from the server
77
- # :parallel_manager - sent if the connection is in parallel mode
78
- # :request - Hash of options for configuring the request.
79
- # :timeout - open/read timeout Integer in seconds
80
- # :open_timeout - read timeout Integer in seconds
81
- # :proxy - Hash of proxy options
82
- # :uri - Proxy Server URI
83
- # :user - Proxy server username
84
- # :password - Proxy server password
85
- # :ssl - Hash of options for configuring SSL requests.
86
- def to_env(connection)
87
- Env.new(method, body, connection.build_exclusive_url(path, params),
88
- options, headers, connection.ssl, connection.parallel_manager)
89
- end
90
- end
91
- end
92
-