@@ -1,3 +1,4 @@ | |||||
require 'calefaction/eve' | |||||
require 'calefaction/version' | require 'calefaction/version' | ||||
module ApplicationHelper | module ApplicationHelper | ||||
@@ -17,13 +17,17 @@ class User < ActiveRecord::Base | |||||
member_of? AdminSetting.get(:corp_id).to_i | member_of? AdminSetting.get(:corp_id).to_i | ||||
end | end | ||||
def member_of?(corp_id) | |||||
def member_of?(corp) | |||||
corp_id == corp | |||||
end | |||||
def corp_id | |||||
ensure_api_user | ensure_api_user | ||||
@api.scope = 'char' | @api.scope = 'char' | ||||
begin | begin | ||||
@api.CharacterSheet(names: name).corporationID.to_i == corp_id | |||||
@api.CharacterSheet(names: name).corporationID.to_i | |||||
rescue EAAL::EAALError | rescue EAAL::EAALError | ||||
false | |||||
0 | |||||
end | end | ||||
end | end | ||||
@@ -8,7 +8,7 @@ | |||||
<nav> | <nav> | ||||
<ul> | <ul> | ||||
<% if @user %> | <% if @user %> | ||||
<li><%= @user.name %></li> | |||||
<li><%= @user.name %> [<%= Calefaction::EVE.corp_ticker @user.corp_id %>]</li> | |||||
<% if @user.admin? %> | <% if @user.admin? %> | ||||
<li><%= link_to 'Admin', controller: 'admin', action: 'index' %></li> | <li><%= link_to 'Admin', controller: 'admin', action: 'index' %></li> | ||||
<% end %> | <% end %> | ||||
@@ -0,0 +1,28 @@ | |||||
module Calefaction::EVE | |||||
extend self | |||||
def corp_ticker(corp_id) | |||||
cache_key = "calefaction/eve/corp_ticker/#{corp_id}" | |||||
existing = Rails.cache.read(cache_key) | |||||
return existing unless existing.nil? | |||||
ticker = get_corp_ticker_from_api(corp_id) | |||||
return '?' if ticker.nil? | |||||
Rails.cache.write(cache_key, ticker) | |||||
ticker | |||||
end | |||||
private | |||||
def get_corp_ticker_from_api(corp_id) | |||||
ensure_api | |||||
@@api.scope = 'corp' | |||||
begin | |||||
@@api.CorporationSheet(corporationID: corp_id).ticker | |||||
rescue EAAL::EAALError | |||||
nil | |||||
end | |||||
end | |||||
def ensure_api | |||||
@@api ||= EAAL::API.new(nil, nil) | |||||
end | |||||
end |