Sha256: 07deea4362117e5201e861d72a5e84fcda3d84acfed85cbadb4ea5d763a7fccd

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

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

      ACCESS_MASK = 1

      attr_reader :key_id, :v_code, :character_id

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

      def as_json
        {
          account_id: account_id,
          account_key: account_key,
          balance: balance,
          current_time: current_time,
          cached_until: cached_until
        }
      end

      def account_id
        row.fetch('@accountID').to_i
      end

      def account_key
        row.fetch('@accountKey').to_i
      end

      def balance
        row.fetch('@balance').to_f
      end

      def url
        output = "#{ API_ENDPOINT }?keyID=#{ key_id }&vCode=#{ v_code }"
        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/account_balance.rb
eve_online-0.10.0 lib/eve_online/characters/account_balance.rb