Sha256: c28851b1988e18433f82294d8d8e096c06338c56173711f02034010d7972f732

Contents?: true

Size: 939 Bytes

Versions: 5

Compression:

Stored size: 939 Bytes

Contents

module A2z
  module Responses
    class ItemLookup
      attr_accessor :operation_request, :item
      
      def initialize
        @valid = true
      end
      
      def valid=(value)
        @valid = !!value
      end
      
      def valid?
        @valid
      end
      
      # TODO capture data['Items']['Request']['Errors'] into an attr_accessor value
      # TODO consider capturing data['Items']['Request'] into an attr_accessor value
      def self.from_response(data)
        new.tap do |item_lookup|
          item_lookup.operation_request = OperationRequest.from_response(data['OperationRequest']) if data['OperationRequest']
          item_lookup.item              = Item.from_response(data['Items']['Item']) if data['Items'] && data['Items']['Item']
          item_lookup.valid             = data['Items']['Request']['IsValid'] == 'True' rescue false
          item_lookup.freeze
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
a2z-0.1.3 lib/a2z/responses/item_lookup.rb
a2z-0.1.2 lib/a2z/responses/item_lookup.rb
a2z-0.1.1 lib/a2z/responses/item_lookup.rb
a2z-0.1.0 lib/a2z/responses/item_lookup.rb
a2z-0.0.4 lib/a2z/responses/item_lookup.rb