Class: Eve::SkillQueue
Constant Summary
Constants inherited
from Base
Base::VALID_KEYS
Instance Attribute Summary collapse
Instance Method Summary
collapse
#debug, #error, #fatal, #info, #warn
Methods inherited from Base
#configure, #load_config, #parse_date, #query
Constructor Details
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_time ⇒ Object
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
44
45
46
|
# File 'lib/eve/skill_queue.rb', line 44
def blocked?
@response.fetch("eveapi", {}).fetch("error", false)
end
|
#cached_until ⇒ Object
62
63
64
|
# File 'lib/eve/skill_queue.rb', line 62
def cached_until
parse_date(@response.fetch("eveapi", {}).fetch("cachedUntil", {}))
end
|
#current_time ⇒ Object
58
59
60
|
# File 'lib/eve/skill_queue.rb', line 58
def current_time
parse_date(@response.fetch("eveapi", {}).fetch("currentTime", {}))
end
|
#empty? ⇒ 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_time ⇒ Object
66
67
68
|
# File 'lib/eve/skill_queue.rb', line 66
def end_time
parse_date(last_skill.fetch("endTime", ""))
end
|
#hours_left ⇒ Object
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_skill ⇒ Object
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
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
|
#refresh ⇒ Object
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_cache ⇒ Object
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
|