class Itch::GameMap
Map game names to itch ids
Could be handled via API, but would require user API keys or oauth
Public Class Methods
new(agent)
click to toggle source
# File lib/itch/game_map.rb, line 16 def initialize(agent) @agent = agent end
Public Instance Methods
find(id)
click to toggle source
# File lib/itch/game_map.rb, line 48 def find(id) id = id.to_s map.values.find do |value| value[:id] == id end end
find!(id)
click to toggle source
# File lib/itch/game_map.rb, line 41 def find!(id) result = find(id) raise Error, "Cannot find game with id #{id}" unless result result end
find_by_name(name)
click to toggle source
# File lib/itch/game_map.rb, line 30 def find_by_name(name) map[name] end
find_by_name!(name)
click to toggle source
# File lib/itch/game_map.rb, line 34 def find_by_name!(name) result = find_by_name(name) raise Error, "Cannot find game with name #{name}" unless result result end
map()
click to toggle source
# File lib/itch/game_map.rb, line 20 def map @map ||= begin page = with_login do @agent.get(Itch::URL::DASHBOARD) end parse_dashboard page end end
Protected Instance Methods
parse_dashboard(page)
click to toggle source
# File lib/itch/game_map.rb, line 57 def parse_dashboard(page) page.css(".game_row").map do |row| title = row.at_css(".game_title .game_link") name = title.text url = title["href"] edit_url = row.at_xpath('.//a[text()="Edit"]/@href').value id = edit_url.match(%r{/game/edit/(\d+)})[1] [name, { id: id, url: url, name: name }] if id && name end.compact.to_h end