Sha256: 78d1833ffdb58cf8bbecf7a8797797983dc59b7ed8085c77d29d725cf2606819

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

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

      attr_reader :key_id, :v_code, :character_id

      def initialize(key_id, v_code, character_id)
        super()
        @key_id = key_id
        @v_code = v_code
        @character_id = character_id
      end

      def as_json(*args)
        {
          account_id: account_id,
          account_key: account_key,
          balance: balance,
          current_time: current_time,
          cached_until: cached_until
        }
      end

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

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

      def balance
        @balance ||= row.fetch('@balance')
      end

      def row
        @row ||= rowset.fetch('row')
      end

      def rowset
        @rowset ||= result.fetch('rowset')
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eve_online-0.6.0 lib/eve_online/characters/account_balance.rb
eve_online-0.5.0 lib/eve_online/characters/account_balance.rb