Class: Smogon::API

Inherits:
Object
  • Object
show all
Defined in:
lib/smogon/api.rb

Constant Summary collapse

METAGAME =
'sm'
ENDPOINT =
'http://www.smogon.com/dex/_rpc/dump-'.freeze

Class Method Summary collapse

Class Method Details

.request(what, name, remote = false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/smogon/api.rb', line 26

def request(what, name, remote = false)
  name = aliasize(name)

  if remote
    return JSON.parse(req(
      URI(ENDPOINT + what.to_s),
      { gen: METAGAME, alias: name }
    ))
  end

  unless @_basics
    @_basics = JSON.parse(req(
      URI(ENDPOINT + 'basics'),
      { gen: METAGAME }
    ))
  end

  @_basics[what.to_s].find do |x|
    aliasize(x['name']) == name
  end
end

.using_metagame(metagame, &block) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/smogon/api.rb', line 48

def using_metagame(metagame, &block)
  default_metagame = METAGAME.dup
  METAGAME.replace aliasize(metagame)
  instance_eval(&block).tap do
    METAGAME.replace default_metagame
  end
end