backpack_tf 1.0.0.rc1 → 1.0.0.rc2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -1
- data/README.md +2 -0
- data/lib/backpack_tf/price/particle_effect.rb +25 -10
- data/lib/backpack_tf/version.rb +1 -1
- data/spec/backpack_tf/price/particle_effect_spec.rb +108 -12
- data/spec/fixtures/particle_effects.json +16 -0
- data/spec/spec_helper.rb +8 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad837f79d1e8158b7158d193b31dab2036d46ed
|
4
|
+
data.tar.gz: c03a3d108b72d82e15c0dd45ebde3bdf25f8d1bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0046372f234d0756bbc9e5a7a7a3ea67c1ce3c062a6c4def4e1ca822a9efdba97f8cad10e0fb5f7e5ac5f2246cc58b893f36f15a385daefa59f461f6db28b4cc
|
7
|
+
data.tar.gz: a30f2616e7737bdfb24ba56142b97696bd8b8f70e3866001fe5d95e846409dfb208d18b77bddbb268971426b1f1762a3b2d193a40b4fffd1678b45d4123e280a
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,6 +2,8 @@ GEM
|
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
addressable (2.3.8)
|
5
|
+
codeclimate-test-reporter (0.4.8)
|
6
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
5
7
|
crack (0.4.2)
|
6
8
|
safe_yaml (~> 1.0.0)
|
7
9
|
diff-lcs (1.2.5)
|
@@ -39,10 +41,10 @@ PLATFORMS
|
|
39
41
|
ruby
|
40
42
|
|
41
43
|
DEPENDENCIES
|
44
|
+
codeclimate-test-reporter (~> 0.4.8)
|
42
45
|
httparty (~> 0.13.5)
|
43
46
|
rake (~> 10.4.2)
|
44
47
|
rspec (~> 3.3.0)
|
45
|
-
simplecov (~> 0.11.1)
|
46
48
|
webmock (~> 1.21.0)
|
47
49
|
|
48
50
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# backpack_tf
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/NerdDiffer/backpack_tf.svg?branch=master)](https://travis-ci.org/NerdDiffer/backpack_tf)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/NerdDiffer/backpack_tf/badges/gpa.svg)](https://codeclimate.com/github/NerdDiffer/backpack_tf)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/NerdDiffer/backpack_tf/badges/coverage.svg)](https://codeclimate.com/github/NerdDiffer/backpack_tf/coverage)
|
4
6
|
|
5
7
|
Backpack.tf is a website for the in-game economies of Team Fortress 2 and
|
6
8
|
Dota 2. This gem is a wrapper for the backpack.tf [API](http://backpack.tf/api).
|
@@ -2,26 +2,41 @@ module BackpackTF
|
|
2
2
|
module Price
|
3
3
|
# For ItemPrice objects with attached particle effects
|
4
4
|
class ParticleEffect
|
5
|
+
RELATIVE_PATH_TO_ASSETS_FILE = '../assets/particle_effects.json'
|
6
|
+
KEY_TO_PARSE_IN_ASSETS_FILE = 'attribute_controlled_attached_particles'
|
7
|
+
|
5
8
|
class << self
|
6
9
|
# @return [Hash] possible particle effects for an item
|
7
|
-
|
8
|
-
|
10
|
+
def list
|
11
|
+
@list ||= accumulate_assets
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def accumulate_assets
|
17
|
+
effects = parse_assets_file
|
9
18
|
|
10
|
-
|
11
|
-
|
19
|
+
effects.each_with_object({}) do |effect, hash|
|
20
|
+
accumulate!(effect, hash)
|
21
|
+
end
|
22
|
+
end
|
12
23
|
|
13
|
-
|
14
|
-
|
15
|
-
|
24
|
+
def parse_assets_file
|
25
|
+
file = File.open(absolute_path_to_assets_file).read
|
26
|
+
JSON.parse(file)[KEY_TO_PARSE_IN_ASSETS_FILE]
|
27
|
+
end
|
16
28
|
|
17
|
-
|
29
|
+
def absolute_path_to_assets_file
|
30
|
+
current_dirname = File.dirname(__FILE__)
|
31
|
+
File.expand_path(RELATIVE_PATH_TO_ASSETS_FILE, current_dirname)
|
32
|
+
end
|
33
|
+
|
34
|
+
def accumulate!(effect, hash)
|
18
35
|
id = effect['id']
|
19
36
|
name = effect['name']
|
20
37
|
hash[id] = name
|
21
38
|
end
|
22
39
|
end
|
23
|
-
|
24
|
-
@list = read_stored_effects_info
|
25
40
|
end
|
26
41
|
end
|
27
42
|
end
|
data/lib/backpack_tf/version.rb
CHANGED
@@ -1,23 +1,119 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BackpackTF::Price::ParticleEffect do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
let(:parsed_assets) do
|
5
|
+
[
|
6
|
+
{
|
7
|
+
"system" => "foo",
|
8
|
+
"id" => 1,
|
9
|
+
"attach_to_rootbone" => true,
|
10
|
+
"name" => "Foo"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"system" => "bar",
|
14
|
+
"id" => 2,
|
15
|
+
"attach_to_rootbone" => false,
|
16
|
+
"name" => "Bar"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.list' do
|
22
|
+
context 'when @list is NOT nil' do
|
23
|
+
before(:each) do
|
24
|
+
described_class.class_eval { @list = :foo }
|
25
|
+
end
|
26
|
+
after(:each) do
|
27
|
+
described_class.class_eval { @list = nil }
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the value of @list' do
|
31
|
+
actual = described_class.list
|
32
|
+
expect(actual).to eq(:foo)
|
33
|
+
end
|
34
|
+
it 'does not call .accumulate_assets' do
|
35
|
+
expect(described_class).not_to receive(:accumulate_assets)
|
36
|
+
described_class.list
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when @list is nil' do
|
41
|
+
before(:each) do
|
42
|
+
allow(described_class).to receive(:accumulate_assets).and_return(:foo)
|
43
|
+
described_class.class_eval { @list = nil }
|
44
|
+
end
|
45
|
+
after(:each) do
|
46
|
+
described_class.list
|
47
|
+
described_class.class_eval { @list = nil }
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'calls .accumulate_assets' do
|
51
|
+
expect(described_class).to receive(:accumulate_assets)
|
52
|
+
end
|
8
53
|
end
|
9
|
-
|
10
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '.accumulate_assets' do
|
57
|
+
before(:each) do
|
58
|
+
allow(described_class)
|
59
|
+
.to receive(:parse_assets_file)
|
60
|
+
.and_return(parsed_assets)
|
11
61
|
end
|
12
62
|
|
13
|
-
context '
|
14
|
-
it '
|
15
|
-
|
16
|
-
expect(
|
63
|
+
context 'reading a value at a known key' do
|
64
|
+
it 'can read the value at this key' do
|
65
|
+
actual = described_class.send(:accumulate_assets)[1]
|
66
|
+
expect(actual).to eq 'Foo'
|
17
67
|
end
|
18
|
-
it '
|
19
|
-
|
68
|
+
it 'can read the value at this key' do
|
69
|
+
actual = described_class.send(:accumulate_assets)[2]
|
70
|
+
expect(actual).to eq 'Bar'
|
20
71
|
end
|
21
72
|
end
|
73
|
+
context 'when it cannot find the requested key' do
|
74
|
+
it 'returns nil' do
|
75
|
+
actual = described_class.send(:accumulate_assets)[3]
|
76
|
+
expect(actual).to be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '.parse_assets_file' do
|
82
|
+
let(:path_to_dummy_file) do
|
83
|
+
rel_path_to_dummy_file = '../../fixtures/particle_effects.json'
|
84
|
+
current_dirname = File.dirname(__FILE__)
|
85
|
+
File.expand_path(rel_path_to_dummy_file, current_dirname)
|
86
|
+
end
|
87
|
+
|
88
|
+
before(:each) do
|
89
|
+
allow(described_class)
|
90
|
+
.to receive(:absolute_path_to_assets_file)
|
91
|
+
.and_return(path_to_dummy_file)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns these results' do
|
95
|
+
expected = parsed_assets
|
96
|
+
actual = described_class.send(:parse_assets_file)
|
97
|
+
expect(actual).to eq expected
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '.absolute_path_to_assets_file' do
|
102
|
+
it 'returns the absolute path to the assets file' do
|
103
|
+
actual = described_class.send(:absolute_path_to_assets_file)
|
104
|
+
expected = 'lib/backpack_tf/assets/particle_effects.json'
|
105
|
+
expect(actual).to match(/.*\/#{expected}/)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.accumulate!' do
|
110
|
+
let(:effect) { { 'id' => 2, 'name' => 'Rad Effect' } }
|
111
|
+
let(:hash) { { 1 => 'Cool Effect' } }
|
112
|
+
|
113
|
+
it 'mutates the hash, like so:' do
|
114
|
+
described_class.send(:accumulate!, effect, hash)
|
115
|
+
expected = { 1 => 'Cool Effect', 2 => 'Rad Effect' }
|
116
|
+
expect(hash).to eq expected
|
117
|
+
end
|
22
118
|
end
|
23
119
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
2
3
|
SimpleCov.start
|
3
4
|
|
4
5
|
require 'backpack_tf'
|
5
6
|
require 'webmock/rspec'
|
6
7
|
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
10
|
+
end
|
11
|
+
|
7
12
|
def generate_fake_api_key
|
8
13
|
hex_nums = %w(0 1 2 3 4 5 6 7 8 9 a b c d e f)
|
9
14
|
key = ''
|
@@ -11,6 +16,8 @@ def generate_fake_api_key
|
|
11
16
|
key
|
12
17
|
end
|
13
18
|
|
19
|
+
WebMock.disable_net_connect!(allow: 'codeclimate.com')
|
20
|
+
|
14
21
|
# taken from httparty's spec dir
|
15
22
|
# https://github.com/jnunemaker/httparty/blob/master/spec/spec_helper.rb
|
16
23
|
def file_fixture(filename)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backpack_tf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Espinoza
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- spec/fixtures/item_with_dual_craftability_tradability.json
|
135
135
|
- spec/fixtures/item_with_unconventional_structure.json
|
136
136
|
- spec/fixtures/market_prices.json
|
137
|
+
- spec/fixtures/particle_effects.json
|
137
138
|
- spec/fixtures/price_history.json
|
138
139
|
- spec/fixtures/prices.json
|
139
140
|
- spec/fixtures/special_items.json
|
@@ -161,9 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
version: 1.3.1
|
162
163
|
requirements: []
|
163
164
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.5.1
|
165
166
|
signing_key:
|
166
167
|
specification_version: 4
|
167
168
|
summary: a wrapper for the backpack.tf API
|
168
169
|
test_files: []
|
169
|
-
has_rdoc:
|