backpack_tf 0.2.0 → 0.2.1
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 +4 -4
- data/.gitignore +10 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +41 -0
- data/TODO.md +15 -0
- data/backpack_tf.gemspec +19 -0
- data/lib/backpack_tf/client.rb +102 -0
- data/lib/backpack_tf/currencies.rb +62 -0
- data/lib/backpack_tf/item.rb +19 -0
- data/lib/backpack_tf/item_price.rb +63 -0
- data/lib/backpack_tf/prices.rb +70 -0
- data/lib/backpack_tf/response.rb +59 -0
- data/lib/backpack_tf.rb +15 -0
- data/readme.md +56 -0
- data/spec/backpack_tf/client_spec.rb +75 -0
- data/spec/backpack_tf/currencies_spec.rb +68 -0
- data/spec/backpack_tf/item_spec.rb +27 -0
- data/spec/backpack_tf/prices_spec.rb +59 -0
- data/spec/backpack_tf/response_spec.rb +36 -0
- data/spec/fixtures/currencies.json +1 -0
- data/spec/fixtures/item.json +1 -0
- data/spec/fixtures/prices.json +1 -0
- data/spec/spec_helper.rb +29 -0
- metadata +24 -2
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BackpackTF
|
4
|
+
describe 'Currencies' do
|
5
|
+
let(:bp) { Client.new }
|
6
|
+
|
7
|
+
describe 'the class' do
|
8
|
+
|
9
|
+
it 'has these default attributes' do
|
10
|
+
expect(Currencies.interface).to eq :IGetCurrencies
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'accessing the IGetCurrencies interface' do
|
14
|
+
it 'returns the fixture and sets to @@currencies variable' do
|
15
|
+
stub_http_response_with('currencies.json')
|
16
|
+
opts = { :app_id => 440, :compress => 1 }
|
17
|
+
Currencies.fetch(bp.get_data(:get_currencies, opts)['response'])
|
18
|
+
expect(Currencies.currencies).not_to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'the response attribute should have these keys' do
|
22
|
+
expect(Currencies.response.keys).to match_array [:success, :current_time, :currencies, :name, :url]
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'the keys of the response attribute should have these values' do
|
26
|
+
expect(Currencies.response[:success]).to eq 1
|
27
|
+
expect(Currencies.response[:message]).to eq nil
|
28
|
+
expect(Currencies.response[:current_time]).to eq 1430784460
|
29
|
+
expect(Currencies.response[:name]).to eq 'Team Fortress 2'
|
30
|
+
expect(Currencies.response[:url]).to eq 'http://backpack.tf'
|
31
|
+
end
|
32
|
+
|
33
|
+
it '@@currencies attribute should be a Hash object' do
|
34
|
+
expect(Currencies.currencies).to be_instance_of Hash
|
35
|
+
end
|
36
|
+
|
37
|
+
it '@@currencies should have these keys' do
|
38
|
+
expected_keys = [:metal, :keys, :earbuds, :hat]
|
39
|
+
expect(Currencies.currencies.keys).to match_array expected_keys
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'instance of Currencies' do
|
46
|
+
|
47
|
+
let (:metal) { Currencies.new(:metal, Currencies.currencies[:metal]) }
|
48
|
+
|
49
|
+
it 'should respond to these methods' do
|
50
|
+
expect(metal).to respond_to :quality, :priceindex, :single, :plural, :round, :craftable, :tradable, :defindex, :blanket
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should have these values' do
|
54
|
+
expect(metal.quality).to eq 6
|
55
|
+
expect(metal.priceindex).to eq 0
|
56
|
+
expect(metal.single).to eq 'ref'
|
57
|
+
expect(metal.plural).to eq 'ref'
|
58
|
+
expect(metal.round).to eq 2
|
59
|
+
expect(metal.craftable).to eq :Craftable
|
60
|
+
expect(metal.tradable).to eq :Tradable
|
61
|
+
expect(metal.defindex).to eq 5002
|
62
|
+
expect(metal.blanket).to eq 0
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BackpackTF
|
4
|
+
describe 'Item' do
|
5
|
+
it 'The Prices class returns the fixture and sets to its @@items variable' do
|
6
|
+
stub_http_response_with('prices.json')
|
7
|
+
opts = { :app_id => 440, :compress => 1 }
|
8
|
+
Prices.fetch(Client.new.get_data(:get_prices, opts)['response'])
|
9
|
+
expect(Prices.items).not_to be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'instance of Item' do
|
13
|
+
|
14
|
+
let (:item) { Item.new('Kritzkrieg', Prices.items['Kritzkrieg']) }
|
15
|
+
|
16
|
+
it 'should respond to these methods' do
|
17
|
+
expect(item).to respond_to :item_name, :defindex, :prices
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have these values' do
|
21
|
+
expect(item.item_name).to eq 'Kritzkrieg'
|
22
|
+
expect(item.defindex).to eq 35
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BackpackTF
|
4
|
+
describe 'Prices' do
|
5
|
+
describe 'Prices class' do
|
6
|
+
|
7
|
+
it 'has these default attributes' do
|
8
|
+
expect(Prices.interface).to eq :IGetPrices
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'accessing the IGetPrices interface' do
|
12
|
+
|
13
|
+
context 'a successful response' do
|
14
|
+
it 'returns the fixture and sets to @@items variable' do
|
15
|
+
stub_http_response_with('prices.json')
|
16
|
+
opts = { :app_id => 440, :compress => 1 }
|
17
|
+
Prices.fetch(Client.new.get_data(:get_prices, opts)['response'])
|
18
|
+
expect(Prices.items).not_to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'the response attribute should have these keys' do
|
22
|
+
expect(Prices.response.keys).to match_array [:success, :current_time, :raw_usd_value, :usd_currency, :usd_currency_index, :items]
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'the keys of the response attribute should have these values' do
|
26
|
+
expect(Prices.response[:success]).to eq 1
|
27
|
+
expect(Prices.response[:message]).to eq nil
|
28
|
+
expect(Prices.response[:current_time]).to eq 1430785805
|
29
|
+
expect(Prices.response[:raw_usd_value]).to eq 0.115
|
30
|
+
expect(Prices.response[:usd_currency]).to eq 'metal'
|
31
|
+
expect(Prices.response[:usd_currency_index]).to eq 5002
|
32
|
+
end
|
33
|
+
|
34
|
+
it '@@items attribute should be a Hash object' do
|
35
|
+
expect(Prices.items).to be_instance_of Hash
|
36
|
+
end
|
37
|
+
|
38
|
+
it '@@items should have this many keys' do
|
39
|
+
expect(Prices.items.keys.length).to be 1661
|
40
|
+
end
|
41
|
+
|
42
|
+
it '@@items should have these keys' do
|
43
|
+
expect(Prices.items).to have_key('Kritzkrieg')
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'instances of Prices' do
|
53
|
+
it 'for now, there are not meant to be instances of this class' do
|
54
|
+
expect{Prices.new}.to raise_error RuntimeError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BackpackTF
|
4
|
+
|
5
|
+
class Dummy
|
6
|
+
include BackpackTF::Response
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples 'Response' do
|
10
|
+
let(:dummy) { Dummy.new }
|
11
|
+
|
12
|
+
context 'the class' do
|
13
|
+
it 'responds to these inherited class methods' do
|
14
|
+
expect(Dummy).to respond_to(:interface, :fetch, :response, :hash_keys_to_sym)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '::hash_keys_to_sym' do
|
18
|
+
it 'changes the type of each key from String to Symbol' do
|
19
|
+
metal = {'quality'=>6, 'priceindex'=>0, 'single'=>'ref', 'plural'=>'ref', 'round'=>2, 'blanket'=>0, 'craftable'=>'Craftable', 'tradable'=>'Tradable', 'defindex'=>5002}
|
20
|
+
hashed_metal = {:quality=>6, :priceindex=>0, :single=>'ref', :plural=>'ref', :round=>2, :blanket=>0, :craftable=>'Craftable', :tradable=>'Tradable', :defindex=>5002}
|
21
|
+
expect(Dummy.hash_keys_to_sym(metal)).to eq hashed_metal
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Prices do
|
29
|
+
it_behaves_like 'Response'
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Currencies do
|
33
|
+
it_behaves_like 'Response'
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"response":{"success":1,"currencies":{"metal":{"quality":6,"priceindex":0,"single":"ref","plural":"ref","round":2,"blanket":0,"craftable":"Craftable","tradable":"Tradable","defindex":5002},"hat":{"quality":6,"priceindex":0,"single":"hat","plural":"hats","round":1,"blanket":1,"blanket_name":"Random Craft Hat","craftable":"Craftable","tradable":"Tradable","defindex":-2},"keys":{"quality":6,"priceindex":0,"single":"key","plural":"keys","round":2,"blanket":0,"craftable":"Craftable","tradable":"Tradable","defindex":5021},"earbuds":{"quality":6,"priceindex":0,"single":"bud","plural":"buds","round":2,"blanket":0,"craftable":"Craftable","tradable":"Tradable","defindex":143}},"name":"Team Fortress 2","url":"http:\/\/backpack.tf","current_time":1430784460}}
|
@@ -0,0 +1 @@
|
|
1
|
+
"Kritzkrieg":{"defindex":[35],"prices":{"11":{"Tradable":{"Craftable":[{"currency":"keys","value":18,"last_update":1430665867,"difference":-18.495}]}},"14":{"Tradable":{"Craftable":[{"currency":"keys","value":9,"last_update":1416841372,"difference":11.385}]}},"3":{"Tradable":{"Craftable":[{"currency":"metal","value":0.66,"last_update":1426439779,"difference":0.33}]}},"6":{"Tradable":{"Craftable":[{"currency":"metal","value":0.05,"last_update":1336410088,"difference":0}],"Non-Craftable":[{"currency":"metal","value":0.05,"last_update":1362791812,"difference":0.03}]}}}}
|