Explorar el Código

Add corp tickers to header.

old-ruby
Ben Kurtovic hace 9 años
padre
commit
d6c8589785
Se han modificado 4 ficheros con 37 adiciones y 4 borrados
  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 Ver fichero

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

module ApplicationHelper


+ 7
- 3
app/models/user.rb Ver fichero

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

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

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

Cargando…
Cancelar
Guardar