I’m currenty trying to extract information from a website’s API JSON output.
Here is what I have, and it almost works perfectly:
def get_player_stats
uri = URI("http://elophant.com/api/v1/euw/getPlayerStats?accountId=#{CGI.escape(@summoner.acctId)}&season=CURRENT&key=KEYID")
resp = Net::HTTP.get_response(uri)
hash = JSON(resp.body)
solo_ranked_elo = hash['playerStatSummaries']['playerStatSummarySet'][2]['maxRating']
puts solo_ranked_elo
end
The problem is that the ['playerStatSummarySet'][1] values will change depending on the player. So for one player their maxRating would be in set [1], but another player’s maxRating will be in set [6].
I need to search for the set where the RankedSolo5x5 value exists then I can go about outputting the maxRating. How would I go about this?
Here are two example files I’m using for comparison:
http://elophant.com/api/v1/euw/getPlayerStats?accountId=22031699&season=CURRENT&key=KEYID
http://elophant.com/api/v1/euw/getPlayerStats?accountId=23529170&season=CURRENT&key=KEYID
I hope that is clear enough!
Here’s a full example
ARGV[0]is a command line argument value for theaccountID. You’d save the above to somemax_ratingfile,chmod +x max_ratingand then run