class MailerLite::Middleware::UnderscoreKeys
This class will underscore all response keys from CamelCase.
Public Instance Methods
on_complete(response)
click to toggle source
# File lib/mailerlite/middleware/underscore_keys.rb, line 7 def on_complete(response) response[:body] = updated_response(response[:body]) end
Private Instance Methods
underscore_hash_keys(hash)
click to toggle source
# File lib/mailerlite/middleware/underscore_keys.rb, line 21 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
updated_response(response)
click to toggle source
# File lib/mailerlite/middleware/underscore_keys.rb, line 13 def updated_response(response) if response.is_a?(Hash) underscore_hash_keys(response) else response end end