Sha256: c1642ff46d1200cebc8d58c718b662c591d160381af3e1480fec2530ae160fcc

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

module EveOnline
  module Characters
    # https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/character/char_marketorders.html
    class MarketOrders < BaseXML
      API_ENDPOINT = 'https://api.eveonline.com/char/MarketOrders.xml.aspx'.freeze

      ACCESS_MASK = 4_096

      attr_reader :key_id, :v_code, :character_id, :order_id

      def initialize(key_id, v_code, options = {})
        super()
        @key_id = key_id
        @v_code = v_code
        @character_id = options.fetch(:character_id, nil)
        @order_id = options.fetch(:order_id, nil)
      end

      def orders
        case row
        when Hash
          [MarketOrder.new(row)]
        when Array
          output = []
          row.each do |order|
            output << MarketOrder.new(order)
          end
          output
        else
          raise ArgumentError
        end
      end
      memoize :orders

      def url
        output = "#{ API_ENDPOINT }?keyID=#{ key_id }&vCode=#{ v_code }"
        output = "#{ output }&characterID=#{ character_id }" if character_id
        output = "#{ output }&orderID=#{ order_id }" if order_id
        output
      end

      private

      def rowset
        result.fetch('rowset')
      end
      memoize :rowset

      def row
        rowset.fetch('row')
      end
      memoize :row
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eve_online-0.11.0 lib/eve_online/characters/market_orders.rb
eve_online-0.10.0 lib/eve_online/characters/market_orders.rb
eve_online-0.9.0 lib/eve_online/characters/market_orders.rb