Class: Bearcat::LegacyContentTypeMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Bearcat::LegacyContentTypeMiddleware
- Defined in:
- lib/bearcat/client.rb
Overview
This is unfortunate⦠Some of the specs pass URL-Encoded keys
(eg `{ "x[y]" => 3 }`) themselves, leading me to believe that
some apps may as well. Bearcat itself (outside of specs) does
not participate in this, but CanvasSync does.
This Regex can be used to find most cases fairly reliably: ["']\w+\[
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(*args) ⇒ LegacyContentTypeMiddleware
constructor
A new instance of LegacyContentTypeMiddleware.
Constructor Details
#initialize(*args) ⇒ LegacyContentTypeMiddleware
Returns a new instance of LegacyContentTypeMiddleware.
174 175 176 177 178 |
# File 'lib/bearcat/client.rb', line 174 def initialize(*args) super @json_middleware = Faraday::Request::Json.new(*args) @urlenc_middleware = Faraday::Request::UrlEncoded.new(*args) end |
Instance Method Details
#call(env) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/bearcat/client.rb', line 180 def call(env) b = env[:body] if b.is_a?(Hash) && b.keys.any? {|k| k.to_s.include?("[") } @urlenc_middleware.call(env) else @json_middleware.call(env) end end |