Class: LolStatic::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/lol_static/endpoint.rb

Direct Known Subclasses

Champion, Item, Spell

Instance Method Summary collapse

Constructor Details

#initialize(id, realm) ⇒ Endpoint

Returns a new instance of Endpoint.



6
7
8
9
# File 'lib/lol_static/endpoint.rb', line 6

def initialize(id, realm)
  @id = id
  @realm = realm
end

Instance Method Details

#api_versionObject



31
32
33
# File 'lib/lol_static/endpoint.rb', line 31

def api_version
  @realm.api_version(self.class.key)
end

#download(path) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/lol_static/endpoint.rb', line 15

def download(path)
  File.open(path, 'wb') do |f|
    f.write(read)
  end
rescue OpenURI::HTTPError
  false
else
  true
end

#image_urlObject



11
12
13
# File 'lib/lol_static/endpoint.rb', line 11

def image_url
  "#{@realm.base_uri}/#{api_version}/img/#{self.class.key}/#{@id}.png"
end

#readObject



25
26
27
28
29
# File 'lib/lol_static/endpoint.rb', line 25

def read
  open(image_url) do |image|
    image.read
  end
end