A corporation manager and dashboard for EVE Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1008 B

  1. require 'eaal'
  2. module Calefaction::EVE
  3. extend self
  4. class APIUser
  5. def initialize(key_id=nil, vcode=nil)
  6. @api = EAAL::API.new(key_id, vcode)
  7. end
  8. def characters
  9. query('account') { @api.Characters.characters }
  10. end
  11. def character_sheet(char_id)
  12. query('char') { @api.CharacterSheet(characterID: char_id) }
  13. end
  14. def corporation_sheet(corp_id)
  15. query('corp') { @api.CorporationSheet(corporationID: corp_id) }
  16. end
  17. private
  18. def query(scope)
  19. @api.scope = scope
  20. begin
  21. yield
  22. rescue EAAL::Exception::EAALError
  23. nil
  24. end
  25. end
  26. end
  27. def corp_ticker(corp_id)
  28. cache_key = "calefaction/eve/corp_ticker/#{corp_id}"
  29. existing = Rails.cache.read(cache_key)
  30. return existing unless existing.nil?
  31. sheet = basic_api.corporation_sheet(corp_id)
  32. return '?' if sheet.nil?
  33. Rails.cache.write(cache_key, sheet.ticker)
  34. sheet.ticker
  35. end
  36. private
  37. def basic_api
  38. @@api ||= APIUser.new
  39. end
  40. end