Sha256: 9d96a9f00d991b1d1045dc50be797afa46c54e5e8a390adffda9d59d42f04910
Contents?: true
Size: 677 Bytes
Versions: 5
Compression:
Stored size: 677 Bytes
Contents
module MailerLite module Middleware # This class will underscore all response keys from CamelCase. class UnderscoreKeys < Faraday::Response::Middleware private def on_complete(response) response[:body] = updated_response(response[:body]) end def updated_response(response) if response.is_a?(Hash) underscore_hash_keys(response) else response end end def underscore_hash_keys(hash) hash.each_with_object({}) do |(k, v), new_hash| key = MailerLite::Utils.underscore(k.to_s) new_hash[key] = updated_response(v) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems