|
@@ -1,28 +1,54 @@ |
|
|
|
|
|
require 'eaal' |
|
|
|
|
|
|
|
|
module Calefaction::EVE |
|
|
module Calefaction::EVE |
|
|
extend self |
|
|
extend self |
|
|
|
|
|
|
|
|
|
|
|
class APIUser |
|
|
|
|
|
def initialize(key_id, vcode) |
|
|
|
|
|
@api = EAAL::API.new(key_id, vcode) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def character_sheet(char_id) |
|
|
|
|
|
@api.scope = 'char' |
|
|
|
|
|
begin |
|
|
|
|
|
@api.CharacterSheet(characterID: char_id) |
|
|
|
|
|
rescue EAAL::Exception::EAALError |
|
|
|
|
|
nil |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def characters |
|
|
|
|
|
@api.scope = 'account' |
|
|
|
|
|
begin |
|
|
|
|
|
@api.Characters.characters |
|
|
|
|
|
rescue EAAL::Exception::EAALError |
|
|
|
|
|
nil |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def corp_ticker(corp_id) |
|
|
def corp_ticker(corp_id) |
|
|
cache_key = "calefaction/eve/corp_ticker/#{corp_id}" |
|
|
cache_key = "calefaction/eve/corp_ticker/#{corp_id}" |
|
|
existing = Rails.cache.read(cache_key) |
|
|
existing = Rails.cache.read(cache_key) |
|
|
return existing unless existing.nil? |
|
|
return existing unless existing.nil? |
|
|
ticker = get_corp_ticker_from_api(corp_id) |
|
|
|
|
|
return '?' if ticker.nil? |
|
|
|
|
|
Rails.cache.write(cache_key, ticker) |
|
|
|
|
|
ticker |
|
|
|
|
|
|
|
|
sheet = corporation_sheet(corp_id) |
|
|
|
|
|
return '?' if sheet.nil? |
|
|
|
|
|
Rails.cache.write(cache_key, sheet.ticker) |
|
|
|
|
|
sheet.ticker |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
|
def get_corp_ticker_from_api(corp_id) |
|
|
|
|
|
ensure_api |
|
|
|
|
|
|
|
|
def corporation_sheet(corp_id) |
|
|
|
|
|
ensure_basic_api |
|
|
@@api.scope = 'corp' |
|
|
@@api.scope = 'corp' |
|
|
begin |
|
|
begin |
|
|
@@api.CorporationSheet(corporationID: corp_id).ticker |
|
|
|
|
|
|
|
|
@@api.CorporationSheet(corporationID: corp_id) |
|
|
rescue EAAL::Exception::EAALError |
|
|
rescue EAAL::Exception::EAALError |
|
|
nil |
|
|
nil |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def ensure_api |
|
|
|
|
|
|
|
|
def ensure_basic_api |
|
|
@@api ||= EAAL::API.new(nil, nil) |
|
|
@@api ||= EAAL::API.new(nil, nil) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |