Class: LolStatic::Endpoint
- Inherits:
-
Object
- Object
- LolStatic::Endpoint
- Defined in:
- lib/lol_static/endpoint.rb
Instance Method Summary collapse
- #api_version ⇒ Object
- #download(path) ⇒ Object
- #image_url ⇒ Object
-
#initialize(id, realm) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #read ⇒ Object
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_version ⇒ Object
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_url ⇒ Object
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 |
#read ⇒ Object
25 26 27 28 29 |
# File 'lib/lol_static/endpoint.rb', line 25 def read open(image_url) do |image| image.read end end |