Sha256: 07838c8f3073ae88734f170b3e2923240229179436373d80beac8e7a5cc34981

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

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

      ACCESS_MASK = 2

      attr_reader :key_id, :v_code, :character_id, :flat

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

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

      def url
        output = "#{ API_ENDPOINT }?keyID=#{ key_id }&vCode=#{ v_code }&flat=#{ flat }"
        output = "#{ output }&characterID=#{ character_id }" if character_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

2 entries across 2 versions & 1 rubygems

Version Path
eve_online-0.11.0 lib/eve_online/characters/asset_list.rb
eve_online-0.10.0 lib/eve_online/characters/asset_list.rb