eve-api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +8 -0
- data/lib/eve-api.rb +6 -0
- data/lib/eve-api/common.rb +7 -0
- data/lib/eve-api/eve-api.rb +138 -0
- data/lib/eve-api/exceptions.rb +16 -0
- data/lib/eve-api/transport.rb +288 -0
- data/tests/general.rb +82 -0
- metadata +52 -0
    
        data/README
    ADDED
    
    
    
        data/lib/eve-api.rb
    ADDED
    
    
| @@ -0,0 +1,138 @@ | |
| 1 | 
            +
            module EveAPI
         | 
| 2 | 
            +
              
         | 
| 3 | 
            +
              class API
         | 
| 4 | 
            +
                include Common
         | 
| 5 | 
            +
                def initialize(*args)
         | 
| 6 | 
            +
                  @keystore = KeyStore.new
         | 
| 7 | 
            +
                  @keystore << User.new(extract_options_from_args!(args)) if args.length > 0
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                def keystore
         | 
| 10 | 
            +
                  @keystore
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                def users
         | 
| 13 | 
            +
                  @keystore.users
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
                def <<(user)
         | 
| 16 | 
            +
                  @keystore << user
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
              
         | 
| 20 | 
            +
              class KeyStore
         | 
| 21 | 
            +
                def initialize(*args)
         | 
| 22 | 
            +
                  @users = {}
         | 
| 23 | 
            +
                  args.each do |user|
         | 
| 24 | 
            +
                    users[user.id] = user
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
                def <<(user)
         | 
| 28 | 
            +
                  @users[user.id] = user
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
                def users
         | 
| 31 | 
            +
                  @users.values
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
                def [](id)
         | 
| 34 | 
            +
                  @users[id]
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
              class Base
         | 
| 39 | 
            +
                def initialize(options, api=nil)
         | 
| 40 | 
            +
                  @api ||= api
         | 
| 41 | 
            +
                  @api ||= Transport::API.new(options)
         | 
| 42 | 
            +
                  @options = options
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
                def id
         | 
| 45 | 
            +
                  return(@options[:id])
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
                def type
         | 
| 48 | 
            +
                  return(@options[:type])
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
                def method_missing(method, *args)
         | 
| 51 | 
            +
                  return(@options[method]) if @options.has_key?(method)
         | 
| 52 | 
            +
                  raise(Exceptions::AttributeException,"unknown attribute #{method}")
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              class User < Base
         | 
| 57 | 
            +
                include Common
         | 
| 58 | 
            +
                def initialize(*args)
         | 
| 59 | 
            +
                  super(extract_options_from_args!(args))
         | 
| 60 | 
            +
                  raise(Exceptions::InputException, "id required") unless @options[:id]
         | 
| 61 | 
            +
                  raise(Exceptions::InputException, "api_key required") unless @options[:api_key]
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
                def characters
         | 
| 64 | 
            +
                  characters = []
         | 
| 65 | 
            +
                  @api.characters.each do |raw_character_id, raw_character|
         | 
| 66 | 
            +
                    characters << Character.new(raw_character, @api)
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                  return characters
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
                
         | 
| 72 | 
            +
              class Character < Base
         | 
| 73 | 
            +
                def corporation
         | 
| 74 | 
            +
                  return(Corporation.new({:id => corporation_id, :name => corporation_name}, @api, self))
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
                def accounts
         | 
| 77 | 
            +
                  accounts = []
         | 
| 78 | 
            +
                  @api.account_balances(id, :char).each do |raw_account|
         | 
| 79 | 
            +
                    accounts << Account.new(raw_account, @api, self, :char)
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                  return accounts
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              class Corporation < Base
         | 
| 86 | 
            +
                def initialize(options, api, character)
         | 
| 87 | 
            +
                  super(options, api)
         | 
| 88 | 
            +
                  options[:character] = character
         | 
| 89 | 
            +
                  @character = character
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
                def accounts
         | 
| 92 | 
            +
                  accounts = []
         | 
| 93 | 
            +
                  @api.account_balances(@character.id, :corp).each do |raw_account|
         | 
| 94 | 
            +
                    accounts << Account.new(raw_account, @api, @character, :corp)
         | 
| 95 | 
            +
                  end
         | 
| 96 | 
            +
                  return accounts
         | 
| 97 | 
            +
                end
         | 
| 98 | 
            +
                def members
         | 
| 99 | 
            +
                  members = []
         | 
| 100 | 
            +
                  @api.member_tracking(@character.id).each do |raw_member_id, raw_member|
         | 
| 101 | 
            +
                    members << Member.new(raw_member, @api)
         | 
| 102 | 
            +
                  end
         | 
| 103 | 
            +
                  return members
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
              end
         | 
| 106 | 
            +
              
         | 
| 107 | 
            +
              class Account < Base
         | 
| 108 | 
            +
                def initialize(options, api, character, type)
         | 
| 109 | 
            +
                  super(options, api)
         | 
| 110 | 
            +
                  options[:character] = character
         | 
| 111 | 
            +
                  options[:type] = type
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
                def journal
         | 
| 114 | 
            +
                  journal = []
         | 
| 115 | 
            +
                  @api.account_journal(character.id, type, key).each do |raw_journal_entry|
         | 
| 116 | 
            +
                    journal << JournalEntry.new(raw_journal_entry, @api)
         | 
| 117 | 
            +
                  end
         | 
| 118 | 
            +
                  return journal
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
                def transactions
         | 
| 121 | 
            +
                  transactions = []
         | 
| 122 | 
            +
                  @api.account_transactions(character.id, type, key).each do |raw_transaction|
         | 
| 123 | 
            +
                    transactions << Transaction.new(raw_transaction, @api)
         | 
| 124 | 
            +
                  end
         | 
| 125 | 
            +
                  return transactions
         | 
| 126 | 
            +
                end
         | 
| 127 | 
            +
              end
         | 
| 128 | 
            +
              
         | 
| 129 | 
            +
              class JournalEntry < Base
         | 
| 130 | 
            +
              end
         | 
| 131 | 
            +
              
         | 
| 132 | 
            +
              class Transaction < Base
         | 
| 133 | 
            +
              end
         | 
| 134 | 
            +
              
         | 
| 135 | 
            +
              class Member < Base
         | 
| 136 | 
            +
              end
         | 
| 137 | 
            +
              
         | 
| 138 | 
            +
            end
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            module EveAPI
         | 
| 2 | 
            +
              module Exceptions
         | 
| 3 | 
            +
                class BaseException < Exception
         | 
| 4 | 
            +
                end
         | 
| 5 | 
            +
                class OptionsException < BaseException
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
                class InputException < BaseException
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                class CredentialsException < BaseException
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
                class APIException < BaseException
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
                class AttributeException < BaseException
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -0,0 +1,288 @@ | |
| 1 | 
            +
            require 'date'
         | 
| 2 | 
            +
            require 'rexml/document'
         | 
| 3 | 
            +
            require 'net/http'
         | 
| 4 | 
            +
            require 'uri'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module EveAPI
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              module Transport
         | 
| 9 | 
            +
                
         | 
| 10 | 
            +
                class API
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  include Common
         | 
| 13 | 
            +
                  
         | 
| 14 | 
            +
                  def initialize(*args)
         | 
| 15 | 
            +
                    @options = extract_options_from_args!(args)
         | 
| 16 | 
            +
                    @transport = HTTP.new(@options)
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def characters
         | 
| 20 | 
            +
                    result = {}
         | 
| 21 | 
            +
                    doc = @transport.call('account/Characters.xml.aspx')
         | 
| 22 | 
            +
                    doc.each_element('//rowset[@name="characters"]/row') do |row|
         | 
| 23 | 
            +
                      character = {
         | 
| 24 | 
            +
                        :id => row.attributes['characterID'].to_i,
         | 
| 25 | 
            +
                        :name => row.attributes['name'],
         | 
| 26 | 
            +
                        :corporation_id => row.attributes['corporationID'].to_i,
         | 
| 27 | 
            +
                        :corporation_name => row.attributes['corporationName']
         | 
| 28 | 
            +
                      }
         | 
| 29 | 
            +
                      result[character[:id]] = character
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                    return result
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def reftypes
         | 
| 35 | 
            +
                    result = {}
         | 
| 36 | 
            +
                    doc = @transport.call('eve/RefTypes.xml.aspx')
         | 
| 37 | 
            +
                    doc.each_element('//rowset[@name="refTypes"]/row') do |row|
         | 
| 38 | 
            +
                      reftype = {
         | 
| 39 | 
            +
                        :id => row.attributes['refTypeID'].to_i,
         | 
| 40 | 
            +
                        :name => row.attributes['refTypeName']
         | 
| 41 | 
            +
                      }
         | 
| 42 | 
            +
                      result[reftype[:id]] = reftype
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                    return result
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  def skills(character_id)
         | 
| 48 | 
            +
                    doc = @transport.call('char/CharacterSheet.xml.aspx', :characterID => character_id)
         | 
| 49 | 
            +
                    base = doc.elements['//result']
         | 
| 50 | 
            +
                    result = {
         | 
| 51 | 
            +
                      :race      => base.elements['race'].text,
         | 
| 52 | 
            +
                      :bloodline => base.elements['bloodLine'].text,
         | 
| 53 | 
            +
                      :gender    => base.elements['gender'].text,
         | 
| 54 | 
            +
                      :balance   => base.elements['balance'].text.to_f
         | 
| 55 | 
            +
                    }
         | 
| 56 | 
            +
                    attributes = base.elements['attributes'].elements
         | 
| 57 | 
            +
                    result[:attributes] = {
         | 
| 58 | 
            +
                      :intelligence => attributes['intelligence'].text.to_i,
         | 
| 59 | 
            +
                      :memory => attributes['memory'].text.to_i,
         | 
| 60 | 
            +
                      :charisma => attributes['charisma'].text.to_i,
         | 
| 61 | 
            +
                      :perception => attributes['perception'].text.to_i,
         | 
| 62 | 
            +
                      :willpower => attributes['willpower'].text.to_i
         | 
| 63 | 
            +
                    }
         | 
| 64 | 
            +
                    skills = {}
         | 
| 65 | 
            +
                    base.each_element('rowset[@name="skills"]/row') do |row|
         | 
| 66 | 
            +
                      skill = {
         | 
| 67 | 
            +
                        :id => row.attributes['typeID'].to_i,
         | 
| 68 | 
            +
                        :level => row.attributes['level'].to_i,
         | 
| 69 | 
            +
                        :skillpoints => row.attributes['skillpoints'].to_i
         | 
| 70 | 
            +
                      }
         | 
| 71 | 
            +
                      skills[skill[:id]] = skill
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                    result[:skills] = skills
         | 
| 74 | 
            +
                    return result
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  def skill_in_training(character_id)
         | 
| 78 | 
            +
                    skill = {}
         | 
| 79 | 
            +
                    doc = @transport.call('char/SkillInTraining.xml.aspx', :characterID => character_id)
         | 
| 80 | 
            +
                    result = doc.elements['//result']
         | 
| 81 | 
            +
                    skill = {
         | 
| 82 | 
            +
                      :skill_id => result.elements['trainingTypeID'].text.to_i,
         | 
| 83 | 
            +
                      :to_level => result.elements['trainingToLevel'].text.to_i,
         | 
| 84 | 
            +
                      :started_at => DateTime.parse(result.elements['trainingStartTime'].text),
         | 
| 85 | 
            +
                      :ends_at => DateTime.parse(result.elements['trainingEndTime'].text),
         | 
| 86 | 
            +
                      :skillpoints => {
         | 
| 87 | 
            +
                        :from => result.elements['trainingStartSP'].text.to_i,
         | 
| 88 | 
            +
                        :to => result.elements['trainingDestinationSP'].text.to_i
         | 
| 89 | 
            +
                      }
         | 
| 90 | 
            +
                    }
         | 
| 91 | 
            +
                    return skill
         | 
| 92 | 
            +
                  end
         | 
| 93 | 
            +
                  
         | 
| 94 | 
            +
                  def skilltree
         | 
| 95 | 
            +
                    result = {
         | 
| 96 | 
            +
                      :skillgroups => {},
         | 
| 97 | 
            +
                      :skills => {}
         | 
| 98 | 
            +
                    }
         | 
| 99 | 
            +
                    doc = @transport.call('eve/SkillTree.xml.aspx')
         | 
| 100 | 
            +
                    doc.each_element('//rowset[@name="skillGroups"]/row') do |row|
         | 
| 101 | 
            +
                      skillgroup = {
         | 
| 102 | 
            +
                        :id => row.attributes['groupID'].to_i,
         | 
| 103 | 
            +
                        :name => row.attributes['groupName'],
         | 
| 104 | 
            +
                      }
         | 
| 105 | 
            +
                      skills = []
         | 
| 106 | 
            +
                      row.each_element('rowset[@name="skills"]/row') do |skill_row|
         | 
| 107 | 
            +
                        skill = {
         | 
| 108 | 
            +
                          :id => skill_row.attributes['typeID'].to_i,
         | 
| 109 | 
            +
                          :name => skill_row.attributes['typeName'],
         | 
| 110 | 
            +
                          :rank => skill_row.elements['rank'].text.to_i,
         | 
| 111 | 
            +
                          :description => skill_row.elements['description'].text
         | 
| 112 | 
            +
                        }
         | 
| 113 | 
            +
                        prerequisites = []
         | 
| 114 | 
            +
                        skill_row.each_element('rowset[@name="requiredSkills"]/row') do |prerequisite_row|
         | 
| 115 | 
            +
                          prerequisites << prerequisite_row.attributes["typeID"].to_i
         | 
| 116 | 
            +
                        end
         | 
| 117 | 
            +
                        skill[:prerequisites] = prerequisites
         | 
| 118 | 
            +
                        skills << skill[:id]
         | 
| 119 | 
            +
                        result[:skills][skill[:id]] = skill
         | 
| 120 | 
            +
                      end
         | 
| 121 | 
            +
                      skillgroup[:skills] = skills
         | 
| 122 | 
            +
                      result[:skillgroups][skillgroup[:id]] = skillgroup
         | 
| 123 | 
            +
                      break
         | 
| 124 | 
            +
                    end
         | 
| 125 | 
            +
                    return result
         | 
| 126 | 
            +
                  end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                  def sovereignty
         | 
| 129 | 
            +
                    sovereignty = {}
         | 
| 130 | 
            +
                    doc = @transport.call('map/Sovereignty.xml.aspx')
         | 
| 131 | 
            +
                    doc.each_element('//rowset[@name="solarSystems"]/row') do |row|
         | 
| 132 | 
            +
                      solarsystem = {
         | 
| 133 | 
            +
                        :id => row.attributes['solarSystemID'].to_i,
         | 
| 134 | 
            +
                        :name => row.attributes['solarSystemName'],
         | 
| 135 | 
            +
                        :alliance_id => row.attributes['allianceID'].to_i,
         | 
| 136 | 
            +
                        :faction_id => row.attributes['factionID'].to_i,
         | 
| 137 | 
            +
                        :constellation_sovereignty => (row.attributes['constellationSovereignty'] != '0'),
         | 
| 138 | 
            +
                        :sovereignty_level => row.attributes['sovereigntyLevel'].to_i
         | 
| 139 | 
            +
                      }
         | 
| 140 | 
            +
                      sovereignty[solarsystem[:id]] = solarsystem
         | 
| 141 | 
            +
                    end
         | 
| 142 | 
            +
                    return sovereignty
         | 
| 143 | 
            +
                  end
         | 
| 144 | 
            +
                  
         | 
| 145 | 
            +
                  def account_balances(character_id, type)
         | 
| 146 | 
            +
                    accounts = []
         | 
| 147 | 
            +
                    doc = @transport.call("#{type.to_s}/AccountBalance.xml.aspx", :characterID => character_id)
         | 
| 148 | 
            +
                    doc.each_element('//rowset[@name="accounts"]/row') do |row|
         | 
| 149 | 
            +
                      account = {
         | 
| 150 | 
            +
                        :id => row.attributes['accountID'].to_i,
         | 
| 151 | 
            +
                        :key => row.attributes['accountKey'].to_i,
         | 
| 152 | 
            +
                        :balance => row.attributes['balance'].to_f
         | 
| 153 | 
            +
                      }
         | 
| 154 | 
            +
                      accounts << account
         | 
| 155 | 
            +
                    end
         | 
| 156 | 
            +
                    return accounts
         | 
| 157 | 
            +
                  end
         | 
| 158 | 
            +
                  
         | 
| 159 | 
            +
                  def account_journal(character_id, type, account_key)
         | 
| 160 | 
            +
                    journal = []
         | 
| 161 | 
            +
                    doc = @transport.call("#{type.to_s}/WalletJournal.xml.aspx", :characterID => character_id, :accountKey => account_key)
         | 
| 162 | 
            +
                    doc.each_element('//rowset[@name="entries"]/row') do |row|
         | 
| 163 | 
            +
                      entry = {
         | 
| 164 | 
            +
                        :id => row.attributes['refID'].to_i,
         | 
| 165 | 
            +
                        :reftype_id => row.attributes['refTypeID'].to_i,
         | 
| 166 | 
            +
                        :owner1 => {
         | 
| 167 | 
            +
                          :id => row.attributes['ownerID1'].to_i,
         | 
| 168 | 
            +
                          :name => row.attributes['ownerName1'].to_i
         | 
| 169 | 
            +
                        },
         | 
| 170 | 
            +
                        :owner2 => {
         | 
| 171 | 
            +
                          :id => row.attributes['ownerID2'].to_i,
         | 
| 172 | 
            +
                          :name => row.attributes['ownerName2'].to_i
         | 
| 173 | 
            +
                        },
         | 
| 174 | 
            +
                        :arg => {
         | 
| 175 | 
            +
                          :id => row.attributes['argID1'].to_i,
         | 
| 176 | 
            +
                          :name => row.attributes['argName1'].to_i              
         | 
| 177 | 
            +
                        },
         | 
| 178 | 
            +
                        :amount => row.attributes['amount'].to_f,
         | 
| 179 | 
            +
                        :balance => row.attributes['balance'].to_f,
         | 
| 180 | 
            +
                        :date => DateTime.parse(row.attributes['date']),
         | 
| 181 | 
            +
                        :reason => row.attributes['reason']
         | 
| 182 | 
            +
                      }
         | 
| 183 | 
            +
                      journal << entry
         | 
| 184 | 
            +
                    end
         | 
| 185 | 
            +
                    return journal
         | 
| 186 | 
            +
                  end
         | 
| 187 | 
            +
                  
         | 
| 188 | 
            +
                  def account_transactions(character_id, type, account_key)
         | 
| 189 | 
            +
                    transactions = []
         | 
| 190 | 
            +
                    doc = @transport.call("#{type.to_s}/WalletTransactions.xml.aspx", :characterID => character_id, :accountKey => account_key)
         | 
| 191 | 
            +
                    doc.each_element('//rowset[@name="transactions"]/row') do |row|
         | 
| 192 | 
            +
                      transaction = {
         | 
| 193 | 
            +
                        :id => row.attributes['transactionID'].to_i,
         | 
| 194 | 
            +
                        :type => row.attributes['transactionType'],
         | 
| 195 | 
            +
                        :date => DateTime.parse(row.attributes['transactionDateTime']),
         | 
| 196 | 
            +
                        :quantity => row.attributes['quantity'].to_i,
         | 
| 197 | 
            +
                        :item => {
         | 
| 198 | 
            +
                          :id => row.attributes['typeID'].to_i,
         | 
| 199 | 
            +
                          :name => row.attributes['typeName']
         | 
| 200 | 
            +
                        },
         | 
| 201 | 
            +
                        :price => row.attributes['price'].to_f,
         | 
| 202 | 
            +
                        :client => {
         | 
| 203 | 
            +
                          :id => row.attributes['clientID'].to_i,
         | 
| 204 | 
            +
                          :name => row.attributes['clientName']
         | 
| 205 | 
            +
                        },
         | 
| 206 | 
            +
                        :seller => {
         | 
| 207 | 
            +
                          :id => row.attributes['characterID'].to_i,
         | 
| 208 | 
            +
                          :name => row.attributes['characterName']
         | 
| 209 | 
            +
                        },
         | 
| 210 | 
            +
                        :station => {
         | 
| 211 | 
            +
                          :id => row.attributes['stationID'].to_i,
         | 
| 212 | 
            +
                          :name => row.attributes['stationName']
         | 
| 213 | 
            +
                        }
         | 
| 214 | 
            +
                      }
         | 
| 215 | 
            +
                      transactions << transaction
         | 
| 216 | 
            +
                    end
         | 
| 217 | 
            +
                    return transactions
         | 
| 218 | 
            +
                  end
         | 
| 219 | 
            +
                  
         | 
| 220 | 
            +
                  def member_tracking(character_id)
         | 
| 221 | 
            +
                    members = {}
         | 
| 222 | 
            +
                    doc = @transport.call('corp/MemberTracking.xml.aspx', :characterID => character_id)
         | 
| 223 | 
            +
                    doc.each_element('//rowset[@name="members"]/row') do |row|
         | 
| 224 | 
            +
                      member = {
         | 
| 225 | 
            +
                        :id => row.attributes['characterID'].to_i,
         | 
| 226 | 
            +
                        :name => row.attributes['name'],
         | 
| 227 | 
            +
                        :title => row.attributes['title'],
         | 
| 228 | 
            +
                        :base => {
         | 
| 229 | 
            +
                          :id => row.attributes['baseID'].to_i,
         | 
| 230 | 
            +
                          :name => row.attributes['base']
         | 
| 231 | 
            +
                        },
         | 
| 232 | 
            +
                        :ship => {
         | 
| 233 | 
            +
                          :id => row.attributes['shipTypeID'].to_i,
         | 
| 234 | 
            +
                          :name => row.attributes['shipType']
         | 
| 235 | 
            +
                        },
         | 
| 236 | 
            +
                        :last => {
         | 
| 237 | 
            +
                          :logon => DateTime.parse(row.attributes['logonDateTime']),
         | 
| 238 | 
            +
                          :logoff => DateTime.parse(row.attributes['logoffDateTime'])
         | 
| 239 | 
            +
                        },
         | 
| 240 | 
            +
                        :location => {
         | 
| 241 | 
            +
                          :id => row.attributes['locationID'].to_i,
         | 
| 242 | 
            +
                          :name => row.attributes['location']
         | 
| 243 | 
            +
                        },
         | 
| 244 | 
            +
                        :roles => row.attributes['roles'].to_i,
         | 
| 245 | 
            +
                        :grantable_roles => row.attributes['grantableRoles'].to_i
         | 
| 246 | 
            +
                      }
         | 
| 247 | 
            +
                      members[member[:id]] = member
         | 
| 248 | 
            +
                    end
         | 
| 249 | 
            +
                    return members
         | 
| 250 | 
            +
                  end
         | 
| 251 | 
            +
                end
         | 
| 252 | 
            +
                
         | 
| 253 | 
            +
                class HTTP
         | 
| 254 | 
            +
                  
         | 
| 255 | 
            +
                  include Common
         | 
| 256 | 
            +
                
         | 
| 257 | 
            +
                  EVE_API_URI_BASE = "http://api.eve-online.com/"
         | 
| 258 | 
            +
                
         | 
| 259 | 
            +
                  def initialize(*args)
         | 
| 260 | 
            +
                    options = extract_options_from_args!(args)
         | 
| 261 | 
            +
                    @base_params = {}
         | 
| 262 | 
            +
                    @base_params[:userID] = options[:id] or raise Exceptions::OptionsException, "id is missing"
         | 
| 263 | 
            +
                    @base_params[:apiKey] = options[:api_key] or raise Exceptions::OptionsException, "api_key is missing"
         | 
| 264 | 
            +
                    @base_params[:betaAccess] = options[:beta_key] if options[:beta_key]
         | 
| 265 | 
            +
                  end
         | 
| 266 | 
            +
                
         | 
| 267 | 
            +
                  def call(uri, *args)
         | 
| 268 | 
            +
                    params = extract_options_from_args!(args).merge(@base_params)
         | 
| 269 | 
            +
                    #pp params
         | 
| 270 | 
            +
                    res = Net::HTTP.post_form(URI.parse("#{EVE_API_URI_BASE}#{uri}"), params)
         | 
| 271 | 
            +
                    xml = '<?xml version="1.0"?>' + res.body
         | 
| 272 | 
            +
                    doc = REXML::Document.new(xml)
         | 
| 273 | 
            +
                    #puts doc
         | 
| 274 | 
            +
                    if error = doc.elements['//error']
         | 
| 275 | 
            +
                      case error.attributes['code'][0,1]
         | 
| 276 | 
            +
                        when '1': raise Exceptions::InputException, error.text
         | 
| 277 | 
            +
                        when '2': raise Exceptions::CredentialsException, error.text
         | 
| 278 | 
            +
                        else raise Exceptions::APIException, error.text
         | 
| 279 | 
            +
                      end
         | 
| 280 | 
            +
                    end
         | 
| 281 | 
            +
                    return doc
         | 
| 282 | 
            +
                  end
         | 
| 283 | 
            +
              
         | 
| 284 | 
            +
                end
         | 
| 285 | 
            +
             | 
| 286 | 
            +
              end
         | 
| 287 | 
            +
              
         | 
| 288 | 
            +
            end
         | 
    
        data/tests/general.rb
    ADDED
    
    | @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            require 'eve-api'
         | 
| 2 | 
            +
            require 'yaml'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            include EveAPI
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # create a file called "config.yml" in the tests dir that looks like:
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            # user_id: <EVE API User ID>
         | 
| 9 | 
            +
            # api_key: <EVE API Key>
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            config = YAML::load_file('../tests/config.yml')
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            raise "config.yml missing attribute user_id" unless config.has_key?('user_id')
         | 
| 14 | 
            +
            raise "config.yml missing attribute api_key" unless config.has_key?('api_key')
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            api = Transport::API.new(:id => config['user_id'], :api_key => config['api_key'])
         | 
| 17 | 
            +
            api.characters.each do |char_id, character|
         | 
| 18 | 
            +
              begin
         | 
| 19 | 
            +
                pp api.member_tracking(char_id)
         | 
| 20 | 
            +
              rescue Exceptions::CredentialsException => ex
         | 
| 21 | 
            +
                puts "CREDENTIALS EXCEPTION: #{ex.message}"
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            api = API.new(:id => config['user_id'], :api_key => config['api_key'])
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            api = API.new
         | 
| 28 | 
            +
            api << User.new(:id => config['user_id'], :api_key => config['api_key'])
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            api.users.each do |user|
         | 
| 31 | 
            +
              user.characters.each do |character|
         | 
| 32 | 
            +
                puts "CHARACTER: #{character.name}"
         | 
| 33 | 
            +
                puts "  SELF ACCOUNTS:"
         | 
| 34 | 
            +
                character.accounts.each do |account|
         | 
| 35 | 
            +
                  begin
         | 
| 36 | 
            +
                    puts "    ACCOUNT: #{account.key} [balance=#{account.balance}]"
         | 
| 37 | 
            +
                    puts "      TRANSACTIONS: "
         | 
| 38 | 
            +
                    account.transactions.each do |transaction|
         | 
| 39 | 
            +
                      puts "        TRANSACTION: #{transaction.id} [date=#{transaction.date.strftime("%Y-%m-%d %H:%m")}]"
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
                    puts "      JOURNAL: "
         | 
| 42 | 
            +
                    account.journal.each do |entry|
         | 
| 43 | 
            +
                      puts "        ENTRY: #{entry.id} [balance=#{entry.balance}]"
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
                  rescue Exceptions::InputException => ex
         | 
| 46 | 
            +
                    puts "        INPUT ERROR: #{ex.message}"
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
                begin
         | 
| 50 | 
            +
                  puts "  CORP MEMBERS:"
         | 
| 51 | 
            +
                  character.corporation.members.each do |member|
         | 
| 52 | 
            +
                    puts "    MEMBER: #{member.id} [name=#{member.name}]"
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                rescue Exceptions::CredentialsException => ex
         | 
| 55 | 
            +
                  print "    CREDENTIALS EXCEPTION: #{ex.message}"
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
                puts "  CORP ACCOUNTS:"
         | 
| 58 | 
            +
                begin
         | 
| 59 | 
            +
                  character.corporation.accounts.each do |account|
         | 
| 60 | 
            +
                    begin
         | 
| 61 | 
            +
                      puts "    ACCOUNT: #{account.key} [balance=#{account.balance}]"
         | 
| 62 | 
            +
                      puts "      TRANSACTIONS: "
         | 
| 63 | 
            +
                      account.transactions.each do |transaction|
         | 
| 64 | 
            +
                        puts "        TRANSACTION: #{transaction.id} [date=#{transaction.date.strftime("%Y-%m-%d %H:%m")}]"
         | 
| 65 | 
            +
                      end
         | 
| 66 | 
            +
                      puts "      JOURNAL: "
         | 
| 67 | 
            +
                      account.journal.each do |entry|
         | 
| 68 | 
            +
                        puts "        ENTRY: #{entry.id} [balance=#{entry.balance}]"
         | 
| 69 | 
            +
                      end
         | 
| 70 | 
            +
                    rescue Exceptions::InputException => ex
         | 
| 71 | 
            +
                      puts "        INPUT ERROR: #{ex.message}"
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                rescue Exceptions::CredentialsException => ex
         | 
| 75 | 
            +
                  puts "    CREDENTIALS ERROR: #{ex.message}"
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
            end
         | 
| 79 | 
            +
                            
         | 
| 80 | 
            +
             | 
| 81 | 
            +
             | 
| 82 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            rubygems_version: 0.9.2
         | 
| 3 | 
            +
            specification_version: 1
         | 
| 4 | 
            +
            name: eve-api
         | 
| 5 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            +
              version: 0.0.1
         | 
| 7 | 
            +
            date: 2007-06-21 00:00:00 -04:00
         | 
| 8 | 
            +
            summary: Ruby support for EVE Online's API
         | 
| 9 | 
            +
            require_paths: 
         | 
| 10 | 
            +
            - lib
         | 
| 11 | 
            +
            email: ddollar@gmail.com
         | 
| 12 | 
            +
            homepage: ""
         | 
| 13 | 
            +
            rubyforge_project: 
         | 
| 14 | 
            +
            description: 
         | 
| 15 | 
            +
            autorequire: eve-api
         | 
| 16 | 
            +
            default_executable: 
         | 
| 17 | 
            +
            bindir: bin
         | 
| 18 | 
            +
            has_rdoc: true
         | 
| 19 | 
            +
            required_ruby_version: !ruby/object:Gem::Version::Requirement 
         | 
| 20 | 
            +
              requirements: 
         | 
| 21 | 
            +
              - - ">"
         | 
| 22 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 23 | 
            +
                  version: 0.0.0
         | 
| 24 | 
            +
              version: 
         | 
| 25 | 
            +
            platform: ruby
         | 
| 26 | 
            +
            signing_key: 
         | 
| 27 | 
            +
            cert_chain: 
         | 
| 28 | 
            +
            post_install_message: 
         | 
| 29 | 
            +
            authors: 
         | 
| 30 | 
            +
            - David Dollar
         | 
| 31 | 
            +
            files: 
         | 
| 32 | 
            +
            - lib/eve-api
         | 
| 33 | 
            +
            - lib/eve-api.rb
         | 
| 34 | 
            +
            - lib/eve-api/common.rb
         | 
| 35 | 
            +
            - lib/eve-api/eve-api.rb
         | 
| 36 | 
            +
            - lib/eve-api/exceptions.rb
         | 
| 37 | 
            +
            - lib/eve-api/transport.rb
         | 
| 38 | 
            +
            - README
         | 
| 39 | 
            +
            test_files: 
         | 
| 40 | 
            +
            - tests/general.rb
         | 
| 41 | 
            +
            rdoc_options: []
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            extra_rdoc_files: 
         | 
| 44 | 
            +
            - README
         | 
| 45 | 
            +
            executables: []
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            extensions: []
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            requirements: []
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            dependencies: []
         | 
| 52 | 
            +
             |