|
|
@@ -4,23 +4,27 @@ module Calefaction::EVE |
|
|
|
extend self |
|
|
|
|
|
|
|
class APIUser |
|
|
|
def initialize(key_id, vcode) |
|
|
|
def initialize(key_id=nil, vcode=nil) |
|
|
|
@api = EAAL::API.new(key_id, vcode) |
|
|
|
end |
|
|
|
|
|
|
|
def characters |
|
|
|
query('account') { @api.Characters.characters } |
|
|
|
end |
|
|
|
|
|
|
|
def character_sheet(char_id) |
|
|
|
@api.scope = 'char' |
|
|
|
begin |
|
|
|
@api.CharacterSheet(characterID: char_id) |
|
|
|
rescue EAAL::Exception::EAALError |
|
|
|
nil |
|
|
|
end |
|
|
|
query('char') { @api.CharacterSheet(characterID: char_id) } |
|
|
|
end |
|
|
|
|
|
|
|
def characters |
|
|
|
@api.scope = 'account' |
|
|
|
def corporation_sheet(corp_id) |
|
|
|
query('corp') { @api.CorporationSheet(corporationID: corp_id) } |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
|
def query(scope) |
|
|
|
@api.scope = scope |
|
|
|
begin |
|
|
|
@api.Characters.characters |
|
|
|
yield |
|
|
|
rescue EAAL::Exception::EAALError |
|
|
|
nil |
|
|
|
end |
|
|
@@ -31,23 +35,14 @@ module Calefaction::EVE |
|
|
|
cache_key = "calefaction/eve/corp_ticker/#{corp_id}" |
|
|
|
existing = Rails.cache.read(cache_key) |
|
|
|
return existing unless existing.nil? |
|
|
|
sheet = corporation_sheet(corp_id) |
|
|
|
sheet = basic_api.corporation_sheet(corp_id) |
|
|
|
return '?' if sheet.nil? |
|
|
|
Rails.cache.write(cache_key, sheet.ticker) |
|
|
|
sheet.ticker |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
|
def corporation_sheet(corp_id) |
|
|
|
basic_api.scope = 'corp' |
|
|
|
begin |
|
|
|
basic_api.CorporationSheet(corporationID: corp_id) |
|
|
|
rescue EAAL::Exception::EAALError |
|
|
|
nil |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def basic_api |
|
|
|
@@api ||= EAAL::API.new(nil, nil) |
|
|
|
@@api ||= APIUser.new |
|
|
|
end |
|
|
|
end |