Class: Common::Client::Middleware::Request::Camelcase
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Common::Client::Middleware::Request::Camelcase
- Defined in:
- lib/common/client/middleware/request/camelcase.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #camelcase(parsed_json) ⇒ Object private
- #lower_camel_stringify(hash) ⇒ Object private
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 |
# File 'lib/common/client/middleware/request/camelcase.rb', line 8 def call(env) env[:body] = camelcase(env[:body]) unless env.request_headers['Content-Type'] == 'text/plain' @app.call(env) end |
#camelcase(parsed_json) ⇒ Object (private)
15 16 17 18 19 20 21 22 |
# File 'lib/common/client/middleware/request/camelcase.rb', line 15 def camelcase(parsed_json) case parsed_json when Array parsed_json.map { |hash| lower_camel_stringify(hash) } when Hash lower_camel_stringify(parsed_json) end end |
#lower_camel_stringify(hash) ⇒ Object (private)
24 25 26 |
# File 'lib/common/client/middleware/request/camelcase.rb', line 24 def lower_camel_stringify(hash) hash.deep_transform_keys { |k| k.to_s.camelize(:lower) } end |