class FaradayMiddleware::Underscore

Converts parsed response bodies to underscored keys if bodies were of Hash type.

Public Class Methods

new(app = nil, options = {}) click to toggle source
Calls superclass method
# File lib/faraday/underscore.rb, line 9
def initialize(app = nil, options = {})
  super(app)
end

Public Instance Methods

parse(body) click to toggle source
# File lib/faraday/underscore.rb, line 13
def parse(body)
  convert_hash_keys body
end

Private Instance Methods

convert_hash_keys(value) click to toggle source
# File lib/faraday/underscore.rb, line 19
def convert_hash_keys(value)
  case value
  when Array
    value.map(&method(:convert_hash_keys))
  when Hash
    Hash[value.map { |k, v| [Payture::Helper.convert_to_underscore(k), convert_hash_keys(v)] }]
  else
    value
  end
end