Sha256: e794f91c6f1a310aca61e3b7c1b852a8ec2641b0ffeb7812826da6405f58cc2e

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module EveOnline
  module Account
    # https://eveonline-third-party-documentation.readthedocs.org/en/latest/xmlapi/account_apikeyinfo/
    class ApiKeyInfo < Base
      API_ENDPOINT = 'https://api.eveonline.com/account/APIKeyInfo.xml.aspx'

      attr_reader :key_id, :v_code

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

      def characters
        case row
        when Hash
          [EveOnline::Character.new(row)]
        when Array
          output = []
          row.each do |character|
            output << EveOnline::Character.new(character)
          end
          output
        else
          raise ArgumentError
        end
      end

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

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

      def expires
        @expires ||= \
          ActiveSupport::TimeZone['UTC'].parse(key.fetch('@expires'))
      end

      def type
        @type ||= key.fetch('@type')
      end

      def access_mask
        @access_mask ||= key.fetch('@accessMask').to_i
      end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eve_online-0.6.0 lib/eve_online/account/api_key_info.rb
eve_online-0.5.0 lib/eve_online/account/api_key_info.rb