Class: Bearcat::LegacyContentTypeMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
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

Constructor Details

#initialize(*args) ⇒ LegacyContentTypeMiddleware

Returns a new instance of LegacyContentTypeMiddleware.



134
135
136
137
138
# File 'lib/bearcat/client.rb', line 134

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



140
141
142
143
144
145
146
147
# File 'lib/bearcat/client.rb', line 140

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