lol_static 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8654dbf815546d5c44aa264353e3d71bb8bebc22
4
- data.tar.gz: 21ef93fbc5bef29daa50adc46d967128330c3b98
3
+ metadata.gz: ec2be92c96b8fd39cee72182d7b57b327bdd3d06
4
+ data.tar.gz: 43dbd7e54398e48c810300c3efd39c13c9cca6a1
5
5
  SHA512:
6
- metadata.gz: ca0f6cc05f68ad2315ca40f48e8723d736eb508bb784d83c36b31eb07ef2aae8db1db8426d5b54b359ac5007876355302dfaf2481057e717b18a5ba007bbac93
7
- data.tar.gz: efbdd9a423409e07a6dd1ac8debc51d0db422dfc1a619e2a7074e2180cf951eb9f0e4ec6a8960e142413a2d1b38278910bd531fff9ae5e45b31f37b205cc8482
6
+ metadata.gz: 6c2775c1ba3876a3797ef0cb5720e219881a2d747d7e00933862f28aa44cd41ce2daca01809368f45c5cb1956192fa85379e78c4c41924e3b6f0407059724ca3
7
+ data.tar.gz: 8251298ca7b4d12fc604bea935d0727f1952fa4aef71b3f7f9768be7d86420d0979e608f42860c20031d46c409c94fdf9b511c86e3b9ab22cd165a56674bea20
@@ -0,0 +1,31 @@
1
+ require 'open-uri'
2
+
3
+ module LolStatic
4
+ class Endpoint
5
+
6
+ def self.api_version
7
+ LolStatic.api_version
8
+ end
9
+
10
+ def initialize(id)
11
+ @id = id
12
+ end
13
+
14
+ def api_version
15
+ self.class.api_version
16
+ end
17
+
18
+ def download(path)
19
+ open(image_url) do |image|
20
+ File.open(path, 'wb') do |f|
21
+ f.write(image.read)
22
+ end
23
+ end
24
+ rescue OpenURI::HTTPError
25
+ false
26
+ else
27
+ true
28
+ end
29
+
30
+ end
31
+ end
@@ -1,22 +1,15 @@
1
1
  require 'lol_static'
2
+ require 'lol_static/endpoint'
2
3
 
3
4
  module LolStatic
4
- class Item
5
+ class Item < Endpoint
5
6
 
6
7
  def self.api_version
7
8
  LolStatic.api_version('item')
8
9
  end
9
10
 
10
- def initialize(item_id)
11
- @item_id = item_id
12
- end
13
-
14
- def api_version
15
- self.class.api_version
16
- end
17
-
18
11
  def image_url
19
- "#{LolStatic.base_uri}/#{api_version}/img/item/#{@item_id}.png"
12
+ "#{LolStatic.base_uri}/#{api_version}/img/item/#{@id}.png"
20
13
  end
21
14
 
22
15
  end
@@ -7,8 +7,8 @@ module LolStatic
7
7
  realm_data['cdn']
8
8
  end
9
9
 
10
- def api_version(name)
11
- realm_data['n'][name.to_s]
10
+ def api_version(name=nil)
11
+ name ? realm_data['n'][name.to_s] : realm_data['v']
12
12
  end
13
13
 
14
14
  private
@@ -0,0 +1,12 @@
1
+ require 'lol_static'
2
+ require 'lol_static/endpoint'
3
+
4
+ module LolStatic
5
+ class Spell < Endpoint
6
+
7
+ def image_url
8
+ "#{LolStatic.base_uri}/#{api_version}/img/spell/#{@id}.png"
9
+ end
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module LolStatic
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/lol_static.rb CHANGED
@@ -4,8 +4,8 @@ require 'lol_static/item'
4
4
 
5
5
  module LolStatic
6
6
  class << self
7
- def api_version(name)
8
- realm.api_version(name)
7
+ def api_version(*args)
8
+ realm.api_version(*args)
9
9
  end
10
10
 
11
11
  def base_uri
@@ -16,6 +16,10 @@ module LolStatic
16
16
  Item.new(id)
17
17
  end
18
18
 
19
+ def spell(id)
20
+ Spell.new(id)
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def realm
@@ -3,12 +3,22 @@ require 'spec_helper'
3
3
  require 'lol_static/item'
4
4
 
5
5
  describe LolStatic::Item do
6
+
7
+ use_vcr_cassette 'realm'
8
+
9
+ let(:id) { 1 }
10
+ let(:item) { LolStatic::Item.new(id) }
11
+
12
+ describe '.api_version' do
13
+ it 'returns api version' do
14
+ expect(LolStatic::Item.api_version).to eq('4.4.3')
15
+ end
16
+ end
17
+
6
18
  describe '#image_url' do
7
19
  it 'returns image url' do
8
- VCR.use_cassette('realm') do
9
- item = LolStatic::Item.new(1)
10
- expect(item.image_url).to eq('http://ddragon.leagueoflegends.com/cdn/4.4.3/img/item/1.png')
11
- end
20
+ item = LolStatic::Item.new(1)
21
+ expect(item.image_url).to eq("http://ddragon.leagueoflegends.com/cdn/4.4.3/img/item/#{id}.png")
12
22
  end
13
23
  end
14
24
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ require 'lol_static/spell'
4
+
5
+ describe LolStatic::Spell do
6
+
7
+ use_vcr_cassette 'realm'
8
+
9
+ let(:id) { }
10
+
11
+ let(:spell) { LolStatic::Spell.new('Spell') }
12
+
13
+ describe '.api_version' do
14
+ it 'returns api version' do
15
+ expect(LolStatic::Spell.api_version).to eq('4.4.3')
16
+ end
17
+ end
18
+
19
+ describe '#image_url' do
20
+ it 'returns image url' do
21
+ expect(spell.image_url).to eq('http://ddragon.leagueoflegends.com/cdn/4.4.3/img/spell/Spell.png')
22
+ end
23
+ end
24
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,10 @@ require 'vcr'
2
2
 
3
3
  ROOT_DIR = File.dirname(File.dirname(__FILE__))
4
4
 
5
+ RSpec.configure do |c|
6
+ c.extend VCR::RSpec::Macros
7
+ end
8
+
5
9
  VCR.configure do |c|
6
10
  c.cassette_library_dir = File.join(ROOT_DIR, 'spec', 'fixtures')
7
11
  c.hook_into :webmock # or :fakeweb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_static
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,13 +107,16 @@ files:
107
107
  - README.md
108
108
  - Rakefile
109
109
  - lib/lol_static.rb
110
+ - lib/lol_static/endpoint.rb
110
111
  - lib/lol_static/item.rb
111
112
  - lib/lol_static/realm.rb
113
+ - lib/lol_static/spell.rb
112
114
  - lib/lol_static/version.rb
113
115
  - lol_static.gemspec
114
116
  - spec/fixtures/realm.yml
115
117
  - spec/lol_static/item_spec.rb
116
118
  - spec/lol_static/realm_spec.rb
119
+ - spec/lol_static/spell_spec.rb
117
120
  - spec/spec_helper.rb
118
121
  homepage: ''
119
122
  licenses:
@@ -143,5 +146,6 @@ test_files:
143
146
  - spec/fixtures/realm.yml
144
147
  - spec/lol_static/item_spec.rb
145
148
  - spec/lol_static/realm_spec.rb
149
+ - spec/lol_static/spell_spec.rb
146
150
  - spec/spec_helper.rb
147
151
  has_rdoc: