| @@ -4,23 +4,27 @@ module Calefaction::EVE | |||||
| extend self | extend self | ||||
| class APIUser | class APIUser | ||||
| def initialize(key_id, vcode) | |||||
| def initialize(key_id=nil, vcode=nil) | |||||
| @api = EAAL::API.new(key_id, vcode) | @api = EAAL::API.new(key_id, vcode) | ||||
| end | end | ||||
| def characters | |||||
| query('account') { @api.Characters.characters } | |||||
| end | |||||
| def character_sheet(char_id) | 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 | 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 | begin | ||||
| @api.Characters.characters | |||||
| yield | |||||
| rescue EAAL::Exception::EAALError | rescue EAAL::Exception::EAALError | ||||
| nil | nil | ||||
| end | end | ||||
| @@ -31,23 +35,14 @@ module Calefaction::EVE | |||||
| 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? | ||||
| sheet = corporation_sheet(corp_id) | |||||
| sheet = basic_api.corporation_sheet(corp_id) | |||||
| return '?' if sheet.nil? | return '?' if sheet.nil? | ||||
| Rails.cache.write(cache_key, sheet.ticker) | Rails.cache.write(cache_key, sheet.ticker) | ||||
| sheet.ticker | sheet.ticker | ||||
| end | end | ||||
| private | 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 | def basic_api | ||||
| @@api ||= EAAL::API.new(nil, nil) | |||||
| @@api ||= APIUser.new | |||||
| end | end | ||||
| end | end | ||||