module AvataxClient::ReverseCoercion
Transform a hash into a format compatible with Avatax.
Public Class Methods
included(base)
click to toggle source
# File lib/avatax_client/reverse_coercion.rb, line 5 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
to_body()
click to toggle source
Build a hash that can be used in the request body to Avatax API @return [Hash]
# File lib/avatax_client/reverse_coercion.rb, line 22 def to_body hash = to_hash hash = translate_names(hash) hash = transform_collections(hash) hash end
Private Instance Methods
transform_collections(hash)
click to toggle source
# File lib/avatax_client/reverse_coercion.rb, line 31 def transform_collections(hash) self.class.key_coercions.each do |k, v| hash[k] = if v.is_a?(Array) v.first.collection_to_body(hash[k]) elsif v.respond_to?(:to_body) v.to_body else hash[k] end end hash end
translate_names(hash)
click to toggle source
# File lib/avatax_client/reverse_coercion.rb, line 44 def translate_names(hash) self.class.inverse_translations.each do |k, v| hash[v] = hash[k] hash.delete(k) end hash end