Class: Itch::GameMap

Inherits:
Object
  • Object
show all
Includes:
RequireAuth, SimpleInspect
Defined in:
lib/itch/game_map.rb

Overview

Map game names to itch ids

Could be handled via API, but would require user API keys or oauth

Instance Method Summary collapse

Methods included from RequireAuth

#require_auth, #with_login

Methods included from SimpleInspect

#exclude_inspection, #inspect, #pretty_print_instance_variables

Constructor Details

#initialize(agent) ⇒ GameMap

Returns a new instance of GameMap.



16
17
18
# File 'lib/itch/game_map.rb', line 16

def initialize(agent)
  @agent = agent
end

Instance Method Details

#find(id) ⇒ Object



48
49
50
51
52
53
# 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) ⇒ Object

Raises:



41
42
43
44
45
46
# 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) ⇒ Object



30
31
32
# File 'lib/itch/game_map.rb', line 30

def find_by_name(name)
  map[name]
end

#find_by_name!(name) ⇒ Object

Raises:



34
35
36
37
38
39
# 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

#mapObject



20
21
22
23
24
25
26
27
28
# File 'lib/itch/game_map.rb', line 20

def map
  @map ||= begin
    page =  do
      @agent.get(Itch::URL::DASHBOARD)
    end

    parse_dashboard page
  end
end