Class: Eve::SkillQueue

Inherits:
Base
  • Object
show all
Includes:
Blinkenstein::Logging
Defined in:
lib/eve/skill_queue.rb

Constant Summary

Constants inherited from Base

Base::VALID_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Blinkenstein::Logging

#debug, #error, #fatal, #info, #warn

Methods inherited from Base

#configure, #load_config, #parse_date, #query

Constructor Details

#initializeSkillQueue

Returns a new instance of SkillQueue.



8
9
10
# File 'lib/eve/skill_queue.rb', line 8

def initialize
  @expire_time = Time.now - 1
end

Instance Attribute Details

#expire_timeObject (readonly)

Returns the value of attribute expire_time.



6
7
8
# File 'lib/eve/skill_queue.rb', line 6

def expire_time
  @expire_time
end

Instance Method Details

#blocked?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/eve/skill_queue.rb', line 44

def blocked?
  @response.fetch("eveapi", {}).fetch("error", false)
end

#cached_untilObject



62
63
64
# File 'lib/eve/skill_queue.rb', line 62

def cached_until
  parse_date(@response.fetch("eveapi", {}).fetch("cachedUntil", {}))
end

#current_timeObject



58
59
60
# File 'lib/eve/skill_queue.rb', line 58

def current_time 
  parse_date(@response.fetch("eveapi", {}).fetch("currentTime", {}))
end

#empty?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/eve/skill_queue.rb', line 48

def empty?
  return false if blocked?

  last_skill.empty?
end

#end_timeObject



66
67
68
# File 'lib/eve/skill_queue.rb', line 66

def end_time
  parse_date(last_skill.fetch("endTime", ""))
end

#hours_leftObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eve/skill_queue.rb', line 12

def hours_left
  refresh

  return ((end_time - current_time) * 24).to_i if end_time 

  if empty?
    info "Skill Queue is empty..."
    return 0
  end

  if paused?
    info "Skill Queue is paused..."
    return 0
  end


  if blocked?
    info "Couldn't fetch updates: API is blocked."
    return -1 
  end

rescue => e
  error "Couldn't fetch updates: #{e}"
  -1
end

#last_skillObject



54
55
56
# File 'lib/eve/skill_queue.rb', line 54

def last_skill
  @last_skill = Array[@response.fetch("eveapi", {}).fetch("result", {}).fetch("rowset", {}).fetch("row", {})].flatten.last
end

#paused?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/eve/skill_queue.rb', line 38

def paused?
  return false if blocked?

  last_skill.fetch("endTime", false) == "" 
end

#refreshObject



78
79
80
81
82
83
# File 'lib/eve/skill_queue.rb', line 78

def refresh 
  return if @response && Time.now < @expire_time 
  info "Updating Skillqueue from Eve-API"
  @response = self.class.get('/char/SkillQueue.xml.aspx', query: query)
  update_cache
end

#update_cacheObject



70
71
72
73
74
75
76
# File 'lib/eve/skill_queue.rb', line 70

def update_cache
  if current_time && cached_until
    @expire_time = Time.now + ((cached_until - current_time) * 24 * 60 * 60).to_i
  else
    @expire_time = Time.now + 60 
  end
end