Sha256: 9e6d294b910807e125867c9b5ff0116e7f87f811a666fb05a365430c33014436

Contents?: true

Size: 628 Bytes

Versions: 4

Compression:

Stored size: 628 Bytes

Contents

module Moneta
  module Api
    class ResponseFactory
      class << self
        # @param [Savon::Response]
        # @return [Moneta::Api::Responses::*]
        def build(response)
          klass = response.keys.first
          data = response.values.first

          prepare_data!(data)
          Object.const_get("Moneta::Api::Responses::#{ klass.to_s }").build(data)
        end

        private

        def prepare_data!(data)
          if data.is_a?(Hash)
            data.deep_transform_keys! do |key|
              key.underscore.to_sym rescue key
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
moneta-api-2.1.0 lib/moneta/api/response_factory.rb
moneta-api-2.0.0 lib/moneta/api/response_factory.rb
moneta-api-2.0.0.rc2 lib/moneta/api/response_factory.rb
moneta-api-2.0.0.rc1 lib/moneta/api/response_factory.rb