Class: Reccore::Marketstat

Inherits:
Object
  • Object
show all
Defined in:
lib/reccore/marketstat.rb

Overview

Endpoint: api.eve-central.com/api/marketstat Purpose: Retrieve aggregate statistics for the items specified. Allowed methods: GET (parameter list), POST (form data) Return data: XML

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Marketstat

hours : Statistics from the last X specified hours. Defaults to 24. typeid : The type ID of the item you are requesting. I.e., 34 for Tritanium. Can be specified more than once. minQ : The minimum quantity in an order to consider it for the statistics. regionlimit : Restrict statistics to a region. Can be specified more than once. usesystem : Restrict statistics to a system.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/reccore/marketstat.rb', line 15

def initialize(options = {})
  # hours = 24, typeid, minQ = nil, regionlimit = nil, usesystem = '30000142' (Jita)
  @args = ''
  @args += "hours=#{options[:hours]}&" unless options[:hours].nil?
  parse_typeid(options[:typeid])
  @args += "minQ=#{options[:minQ]}&" unless options[:minQ].nil?
  parse_regionlimit(options[:regionlimit]) unless options[:regionlimit].nil?
  @args += 'usesystem=30000142&' if options[:regionlimit].nil?
  @args += "usesystem=#{options[:usesystem]}&" unless options[:usesystem].nil?
  xml = Nokogiri::XML(open(Marketstat.endpoint + @args.chomp('&')))
  update(xml)
  Reccore.cache.cleanup!
end

Class Attribute Details

.endpointObject (readonly)

Returns the value of attribute endpoint.



7
8
9
# File 'lib/reccore/marketstat.rb', line 7

def endpoint
  @endpoint
end

Instance Method Details

#parse_regionlimit(regionlimit) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/reccore/marketstat.rb', line 37

def parse_regionlimit(regionlimit)
  if regionlimit.is_a?(Array)
    regionlimit.each { |region| @args += "regionlimit=#{region}&" }
  else
    @args += "regionlimit=#{regionlimit}&"
  end
end

#parse_typeid(typeid) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/reccore/marketstat.rb', line 29

def parse_typeid(typeid)
  if typeid.is_a?(Array)
    typeid.each { |type| @args += "typeid=#{type}&" }
  else
    @args += "typeid=#{typeid}&"
  end
end

#update(xml) ⇒ Object



45
46
47
48
49
50
# File 'lib/reccore/marketstat.rb', line 45

def update(xml)
  elements = xml.xpath('//type')
  elements.each do |element|
    Reccore.cache[element['id'], 3600] = update_buy(element), update_sell(element)
  end
end

#update_buy(element) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/reccore/marketstat.rb', line 52

def update_buy(element)
  {:buy =>
    {:volume => element.css('buy/volume').text,
     :avg => element.css('buy/avg').text,
     :max => element.css('buy/max').text,
     :min => element.css('buy/min').text,
     :stddev => element.css('buy/stddev').text,
     :median => element.css('buy/median').text,
     :percentile => element.css('buy/percentile').text,
      },
    }
end

#update_sell(element) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/reccore/marketstat.rb', line 65

def update_sell(element)
  {:sell =>
    {:volume => element.css('sell/volume').text,
     :avg => element.css('sell/avg').text,
     :max => element.css('sell/max').text,
     :min => element.css('sell/min').text,
     :stddev => element.css('sell/stddev').text,
     :median => element.css('sell/median').text,
     :percentile => element.css('sell/percentile').text,
      },
    }
end