lol_static 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lol_static.rb +1 -19
- data/lib/lol_static/client.rb +26 -0
- data/lib/lol_static/endpoint.rb +15 -11
- data/lib/lol_static/realm.rb +7 -1
- data/lib/lol_static/version.rb +1 -1
- data/spec/integration/client_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/unit/champion_spec.rb +13 -0
- data/spec/unit/endpoint_spec.rb +31 -0
- data/spec/unit/item_spec.rb +13 -0
- data/spec/unit/realm_spec.rb +20 -0
- data/spec/unit/spell_spec.rb +12 -0
- metadata +15 -11
- data/lib/lol_static/config.rb +0 -21
- data/spec/lol_static/champion_spec.rb +0 -24
- data/spec/lol_static/item_spec.rb +0 -24
- data/spec/lol_static/realm_spec.rb +0 -23
- data/spec/lol_static/spell_spec.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2590a57c64958ce913e12f182f8800f6d822ceb
|
4
|
+
data.tar.gz: 4e730334954c16b91bbd401f4da4eab77bb3ddad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ba1d608a978d4bf2608e4641b3703b1ef064315960960747ee6d6b4dd9b254ca344ec1591c2a9052094e6250882c0f3e34be23a3db35c28f2d6ce19f3f4fed
|
7
|
+
data.tar.gz: 6102a639057a0a3fb0cc6d5e17ea1088dcd57795f4172246812a1a610095e423c02f1cc57c20ff7444830b8362a6a3489406369cc626a4ed78bb810e294b2df5
|
data/lib/lol_static.rb
CHANGED
@@ -1,24 +1,6 @@
|
|
1
1
|
require 'lol_static/version'
|
2
|
-
require 'lol_static/
|
3
|
-
require 'lol_static/spell'
|
4
|
-
require 'lol_static/realm'
|
5
|
-
require 'lol_static/champion'
|
6
|
-
|
2
|
+
require 'lol_static/client'
|
7
3
|
|
8
4
|
module LolStatic
|
9
|
-
class << self
|
10
|
-
|
11
|
-
def item(id)
|
12
|
-
Item.new(id)
|
13
|
-
end
|
14
|
-
|
15
|
-
def spell(id)
|
16
|
-
Spell.new(id)
|
17
|
-
end
|
18
|
-
|
19
|
-
def champion(id)
|
20
|
-
Champion.new(id)
|
21
|
-
end
|
22
5
|
|
23
|
-
end
|
24
6
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'lol_static/realm'
|
2
|
+
require 'lol_static/item'
|
3
|
+
require 'lol_static/spell'
|
4
|
+
require 'lol_static/champion'
|
5
|
+
|
6
|
+
module LolStatic
|
7
|
+
class Client
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@realm = Realm.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def item(id)
|
14
|
+
Item.new(id, @realm)
|
15
|
+
end
|
16
|
+
|
17
|
+
def spell(id)
|
18
|
+
Spell.new(id, @realm)
|
19
|
+
end
|
20
|
+
|
21
|
+
def champion(id)
|
22
|
+
Champion.new(id, @realm)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/lol_static/endpoint.rb
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
require 'open-uri'
|
2
|
-
require 'lol_static/config'
|
3
2
|
|
4
3
|
module LolStatic
|
5
4
|
class Endpoint
|
6
5
|
|
7
|
-
def
|
8
|
-
LolStatic::Config.api_version(key)
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(id)
|
6
|
+
def initialize(id, realm)
|
12
7
|
@id = id
|
8
|
+
@realm = realm
|
13
9
|
end
|
14
10
|
|
15
11
|
def image_url
|
16
|
-
"#{
|
12
|
+
"#{@realm.base_uri}/#{api_version}/img/#{self.class.key}/#{@id}.png"
|
17
13
|
end
|
18
14
|
|
19
15
|
def download(path)
|
20
|
-
open(
|
21
|
-
|
22
|
-
f.write(image.read)
|
23
|
-
end
|
16
|
+
File.open(path, 'wb') do |f|
|
17
|
+
f.write(read)
|
24
18
|
end
|
25
19
|
rescue OpenURI::HTTPError
|
26
20
|
false
|
@@ -28,5 +22,15 @@ module LolStatic
|
|
28
22
|
true
|
29
23
|
end
|
30
24
|
|
25
|
+
def read
|
26
|
+
open(image_url) do |image|
|
27
|
+
image.read
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def api_version
|
32
|
+
@realm.api_version(self.class.key)
|
33
|
+
end
|
34
|
+
|
31
35
|
end
|
32
36
|
end
|
data/lib/lol_static/realm.rb
CHANGED
@@ -3,6 +3,10 @@ require 'httparty'
|
|
3
3
|
module LolStatic
|
4
4
|
class Realm
|
5
5
|
|
6
|
+
def initialize
|
7
|
+
@mutex = Mutex.new
|
8
|
+
end
|
9
|
+
|
6
10
|
def base_uri
|
7
11
|
realm_data['cdn']
|
8
12
|
end
|
@@ -14,7 +18,9 @@ module LolStatic
|
|
14
18
|
private
|
15
19
|
|
16
20
|
def realm_data
|
17
|
-
@
|
21
|
+
@mutex.synchronize do
|
22
|
+
@realm_data ||= HTTParty.get('http://ddragon.leagueoflegends.com/realms/euw.json').parsed_response
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
end
|
data/lib/lol_static/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'lol_static/client'
|
4
|
+
|
5
|
+
describe LolStatic::Client, vcr: { cassette_name: 'realm' } do
|
6
|
+
|
7
|
+
let(:client) { LolStatic::Client.new }
|
8
|
+
|
9
|
+
describe '#item' do
|
10
|
+
it 'does not raise error' do
|
11
|
+
expect { client.item(1) }.to_not raise_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,8 @@ 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
|
-
|
9
5
|
VCR.configure do |c|
|
10
6
|
c.cassette_library_dir = File.join(ROOT_DIR, 'spec', 'fixtures')
|
11
7
|
c.hook_into :webmock # or :fakeweb
|
8
|
+
c.configure_rspec_metadata!
|
12
9
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'lol_static/endpoint'
|
4
|
+
|
5
|
+
class ConcreteEndpoint < LolStatic::Endpoint
|
6
|
+
|
7
|
+
def self.key
|
8
|
+
'key'
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe LolStatic::Endpoint do
|
14
|
+
|
15
|
+
let(:id) { 1 }
|
16
|
+
let(:realm) { double('realm', api_version: '4.4.3', base_uri: 'http://ddragon.leagueoflegends.com/cdn') }
|
17
|
+
|
18
|
+
let(:endpoint) { ConcreteEndpoint.new(id, realm) }
|
19
|
+
|
20
|
+
describe '#api_version' do
|
21
|
+
it 'returns api version' do
|
22
|
+
expect(endpoint.api_version).to eq('4.4.3')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#image_url' do
|
27
|
+
it 'returns image url' do
|
28
|
+
expect(endpoint.image_url).to eq("http://ddragon.leagueoflegends.com/cdn/4.4.3/img/key/#{id}.png")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'lol_static/realm'
|
4
|
+
|
5
|
+
describe LolStatic::Realm, vcr: { cassette_name: 'realm' } do
|
6
|
+
|
7
|
+
describe '#base_uri' do
|
8
|
+
it 'returns correct uri' do
|
9
|
+
realm = LolStatic::Realm.new
|
10
|
+
expect(realm.base_uri).to eq('http://ddragon.leagueoflegends.com/cdn')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#api_version' do
|
15
|
+
it 'returns correct version for item' do
|
16
|
+
realm = LolStatic::Realm.new
|
17
|
+
expect(realm.api_version('item')).to eq('4.4.3')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
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.
|
4
|
+
version: 0.0.8
|
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-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- lib/lol_static.rb
|
110
110
|
- lib/lol_static/champion.rb
|
111
|
-
- lib/lol_static/
|
111
|
+
- lib/lol_static/client.rb
|
112
112
|
- lib/lol_static/endpoint.rb
|
113
113
|
- lib/lol_static/item.rb
|
114
114
|
- lib/lol_static/realm.rb
|
@@ -116,11 +116,13 @@ files:
|
|
116
116
|
- lib/lol_static/version.rb
|
117
117
|
- lol_static.gemspec
|
118
118
|
- spec/fixtures/realm.yml
|
119
|
-
- spec/
|
120
|
-
- spec/lol_static/item_spec.rb
|
121
|
-
- spec/lol_static/realm_spec.rb
|
122
|
-
- spec/lol_static/spell_spec.rb
|
119
|
+
- spec/integration/client_spec.rb
|
123
120
|
- spec/spec_helper.rb
|
121
|
+
- spec/unit/champion_spec.rb
|
122
|
+
- spec/unit/endpoint_spec.rb
|
123
|
+
- spec/unit/item_spec.rb
|
124
|
+
- spec/unit/realm_spec.rb
|
125
|
+
- spec/unit/spell_spec.rb
|
124
126
|
homepage: ''
|
125
127
|
licenses:
|
126
128
|
- MIT
|
@@ -147,9 +149,11 @@ specification_version: 4
|
|
147
149
|
summary: Fetches static content from the league of legends CDN
|
148
150
|
test_files:
|
149
151
|
- spec/fixtures/realm.yml
|
150
|
-
- spec/
|
151
|
-
- spec/lol_static/item_spec.rb
|
152
|
-
- spec/lol_static/realm_spec.rb
|
153
|
-
- spec/lol_static/spell_spec.rb
|
152
|
+
- spec/integration/client_spec.rb
|
154
153
|
- spec/spec_helper.rb
|
154
|
+
- spec/unit/champion_spec.rb
|
155
|
+
- spec/unit/endpoint_spec.rb
|
156
|
+
- spec/unit/item_spec.rb
|
157
|
+
- spec/unit/realm_spec.rb
|
158
|
+
- spec/unit/spell_spec.rb
|
155
159
|
has_rdoc:
|
data/lib/lol_static/config.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module LolStatic
|
2
|
-
Config = Object.new.tap do |object|
|
3
|
-
class << object
|
4
|
-
|
5
|
-
def api_version(*args)
|
6
|
-
realm.api_version(*args)
|
7
|
-
end
|
8
|
-
|
9
|
-
def base_uri
|
10
|
-
realm.base_uri
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def realm
|
16
|
-
@realm ||= Realm.new
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'lol_static/champion'
|
4
|
-
|
5
|
-
describe LolStatic::Champion do
|
6
|
-
|
7
|
-
use_vcr_cassette 'realm'
|
8
|
-
|
9
|
-
let(:id) { 'Champion' }
|
10
|
-
|
11
|
-
let(:spell) { LolStatic::Champion.new(id) }
|
12
|
-
|
13
|
-
describe '.api_version' do
|
14
|
-
it 'returns api version' do
|
15
|
-
expect(LolStatic::Champion.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/champion/#{id}.png")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'lol_static/item'
|
4
|
-
|
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
|
-
|
18
|
-
describe '#image_url' do
|
19
|
-
it 'returns image url' do
|
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")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'lol_static/realm'
|
4
|
-
|
5
|
-
describe LolStatic::Realm do
|
6
|
-
describe '#base_uri' do
|
7
|
-
it 'returns correct uri' do
|
8
|
-
VCR.use_cassette('realm') do
|
9
|
-
realm = LolStatic::Realm.new
|
10
|
-
expect(realm.base_uri).to eq('http://ddragon.leagueoflegends.com/cdn')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#api_version' do
|
16
|
-
it 'returns correct version for item' do
|
17
|
-
VCR.use_cassette('realm') do
|
18
|
-
realm = LolStatic::Realm.new
|
19
|
-
expect(realm.api_version('item')).to eq('4.4.3')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,24 +0,0 @@
|
|
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) { 'Spell' }
|
10
|
-
|
11
|
-
let(:spell) { LolStatic::Spell.new(id) }
|
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/#{id}.png")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|