Sha256: 0002c7d356788667e21c345173d501ff89d05da9194f39961ad17ce991b86f52
Contents?: true
Size: 708 Bytes
Versions: 7
Compression:
Stored size: 708 Bytes
Contents
# frozen_string_literal: true 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
7 entries across 7 versions & 1 rubygems