Browse Source

Add corp tickers to header.

old-ruby
Ben Kurtovic 9 years ago
parent
commit
d6c8589785
4 changed files with 37 additions and 4 deletions
  1. +1
    -0
      app/helpers/application_helper.rb
  2. +7
    -3
      app/models/user.rb
  3. +1
    -1
      app/views/shared/_header.html.erb
  4. +28
    -0
      lib/calefaction/eve.rb

+ 1
- 0
app/helpers/application_helper.rb View File

@@ -1,3 +1,4 @@
require 'calefaction/eve'
require 'calefaction/version'

module ApplicationHelper


+ 7
- 3
app/models/user.rb View File

@@ -17,13 +17,17 @@ class User < ActiveRecord::Base
member_of? AdminSetting.get(:corp_id).to_i
end

def member_of?(corp_id)
def member_of?(corp)
corp_id == corp
end

def corp_id
ensure_api_user
@api.scope = 'char'
begin
@api.CharacterSheet(names: name).corporationID.to_i == corp_id
@api.CharacterSheet(names: name).corporationID.to_i
rescue EAAL::EAALError
false
0
end
end



+ 1
- 1
app/views/shared/_header.html.erb View File

@@ -8,7 +8,7 @@
<nav>
<ul>
<% if @user %>
<li><%= @user.name %></li>
<li><%= @user.name %> [<%= Calefaction::EVE.corp_ticker @user.corp_id %>]</li>
<% if @user.admin? %>
<li><%= link_to 'Admin', controller: 'admin', action: 'index' %></li>
<% end %>


+ 28
- 0
lib/calefaction/eve.rb View File

@@ -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

Loading…
Cancel
Save