Skip to content

Commit

Permalink
Add level subcategories to speedruns.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jan 18, 2017
1 parent bc56c3b commit 50a493d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
26 changes: 21 additions & 5 deletions app/speedrun_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,33 @@ def self.resolve_id(type, id)
return @@cache[type][id] if @@cache[type][id]
value = $redis.hget("speedrun", "#{type}:#{id}")
if value
@@cache[type][id] = value
return value
@@cache[type][id] = if type == "level-subcategories"
JSON.parse(value)
else
value
end
return @@cache[type][id]
end

value = if type == "game"
if type == "game"
response = SpeedrunParty.get("/games/#{id}")
raise SpeedrunError.new(response) if !response.success?
response.parsed_response["data"]["names"]["international"]
redis_value = value = response.parsed_response["data"]["names"]["international"]
elsif type == "level-subcategories"
response = SpeedrunParty.get("/levels/#{id}/variables")
raise SpeedrunError.new(response) if !response.success?
value = response.parsed_response["data"].select { |var| var["is-subcategory"] }.map do |var|
[
var["id"],
var["values"]["values"].map do |id, val|
[id, val["label"]]
end.to_h
]
end.to_h
redis_value = value.to_json
end

$redis.hset("speedrun", "#{type}:#{id}", value)
$redis.hset("speedrun", "#{type}:#{id}", redis_value)
@@cache[type][id] = value
return value
end
Expand Down
5 changes: 5 additions & 0 deletions views/speedrun_feed.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
category_link = "https://www.speedrun.com/#{@abbr}##{run["category"]["data"]["weblink"].partition("#")[2]}"
category = run["category"]["data"]["name"]
end

if !run["level"]["data"].empty?
level_subcategories = SpeedrunParty.resolve_id("level-subcategories", run["level"]["data"]["id"])
category += level_subcategories.select { |id, values| run["values"][id] }.map { |id, values| " - " + values[run["values"][id]] }.join
end
-%>

<entry>
Expand Down

0 comments on commit 50a493d

Please sign in to comment.