class AlbionApi::UserKillboard
this class can make the calls to the UserKillboard
APIs
Attributes
character_api_id[RW]
raw_kills[RW]
Public Class Methods
new(character_api_id)
click to toggle source
# File lib/albion-api/user_killboard.rb, line 4 def initialize(character_api_id) @character_api_id = character_api_id end
Public Instance Methods
top_kills_in_range(start_time, end_time)
click to toggle source
# File lib/albion-api/user_killboard.rb, line 8 def top_kills_in_range(start_time, end_time) # get the difference between the end and start time # determine how long ago it was from now, likely 1 day max # make the top kills request with teh proper `range` param # filter the raw response down to only those kills within the timestamp range # return a response class @raw_kills = [] page = 0 resp = top_kills until resp.empty? do @raw_kills.concat JSON.parse(resp.body) page += 1 resp = top_kills(page) end Response.new(filter_kills(start_time, end_time)) end
Private Instance Methods
filter_kills(start_time, end_time)
click to toggle source
# File lib/albion-api/user_killboard.rb, line 34 def filter_kills(start_time, end_time) @raw_kills.select do |kill| Time.parse(kill['TimeStamp']).between?(start_time, end_time) && kill['GvGMatch'].nil? end.flatten end
top_kills(page = 0)
click to toggle source
# File lib/albion-api/user_killboard.rb, line 29 def top_kills(page = 0) offset = page * 51 self.class.get("/players/#{@character_api_id}/topkills?range=month&limit=51&offset=#{offset}") end