backpack_tf 0.8.4 → 1.0.0.rc1
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 +1 -3
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +5 -3
- data/Gemfile.lock +49 -0
- data/README.md +144 -0
- data/Rakefile +7 -0
- data/backpack_tf.gemspec +2 -2
- data/lib/backpack_tf/assets/{attribute_controlled_attached_particles.json → particle_effects.json} +0 -0
- data/lib/backpack_tf/client.rb +72 -95
- data/lib/backpack_tf/currency/interface.rb +9 -0
- data/lib/backpack_tf/currency/response.rb +24 -0
- data/lib/backpack_tf/currency.rb +24 -47
- data/lib/backpack_tf/helpers.rb +29 -0
- data/lib/backpack_tf/interface.rb +29 -0
- data/lib/backpack_tf/market_price/interface.rb +9 -0
- data/lib/backpack_tf/market_price/response.rb +15 -0
- data/lib/backpack_tf/market_price.rb +25 -0
- data/lib/backpack_tf/price/interface.rb +19 -0
- data/lib/backpack_tf/price/item.rb +85 -0
- data/lib/backpack_tf/price/item_price.rb +113 -0
- data/lib/backpack_tf/price/particle_effect.rb +27 -0
- data/lib/backpack_tf/price/response.rb +38 -0
- data/lib/backpack_tf/price.rb +9 -81
- data/lib/backpack_tf/price_history/interface.rb +22 -0
- data/lib/backpack_tf/price_history/response.rb +15 -0
- data/lib/backpack_tf/price_history.rb +25 -0
- data/lib/backpack_tf/response.rb +9 -56
- data/lib/backpack_tf/special_item/interface.rb +9 -0
- data/lib/backpack_tf/special_item/response.rb +16 -0
- data/lib/backpack_tf/special_item.rb +11 -21
- data/lib/backpack_tf/user/interface.rb +18 -0
- data/lib/backpack_tf/user/response.rb +16 -0
- data/lib/backpack_tf/user.rb +10 -19
- data/lib/backpack_tf/user_listing/interface.rb +18 -0
- data/lib/backpack_tf/user_listing/response.rb +15 -0
- data/lib/backpack_tf/user_listing.rb +31 -43
- data/lib/backpack_tf/version.rb +1 -1
- data/lib/backpack_tf.rb +8 -8
- data/spec/backpack_tf/client_spec.rb +151 -101
- data/spec/backpack_tf/currency/interface_spec.rb +8 -0
- data/spec/backpack_tf/currency/response_spec.rb +41 -0
- data/spec/backpack_tf/currency_spec.rb +34 -118
- data/spec/backpack_tf/helpers_spec.rb +85 -0
- data/spec/backpack_tf/interface_spec.rb +56 -0
- data/spec/backpack_tf/market_price/interface_spec.rb +8 -0
- data/spec/backpack_tf/market_price/response_spec.rb +22 -0
- data/spec/backpack_tf/market_price_spec.rb +22 -0
- data/spec/backpack_tf/price/interface_spec.rb +27 -0
- data/spec/backpack_tf/price/item_price_spec.rb +101 -0
- data/spec/backpack_tf/price/item_spec.rb +291 -0
- data/spec/backpack_tf/price/particle_effect_spec.rb +23 -0
- data/spec/backpack_tf/price/response_spec.rb +87 -0
- data/spec/backpack_tf/price_history/interface_spec.rb +38 -0
- data/spec/backpack_tf/price_history/response_spec.rb +22 -0
- data/spec/backpack_tf/price_history_spec.rb +24 -0
- data/spec/backpack_tf/response_spec.rb +22 -108
- data/spec/backpack_tf/special_item/interface_spec.rb +8 -0
- data/spec/backpack_tf/special_item/response_spec.rb +26 -0
- data/spec/backpack_tf/special_item_spec.rb +23 -100
- data/spec/backpack_tf/user/interface_spec.rb +20 -0
- data/spec/backpack_tf/user/response_spec.rb +27 -0
- data/spec/backpack_tf/user_listing/interface_spec.rb +20 -0
- data/spec/backpack_tf/user_listing/response_spec.rb +21 -0
- data/spec/backpack_tf/user_listing_spec.rb +53 -81
- data/spec/backpack_tf/user_spec.rb +16 -83
- data/spec/fixtures/item_price_typical.json +6 -0
- data/spec/fixtures/item_price_unusual.json +7 -0
- data/spec/fixtures/item_typical.json +1 -1
- data/spec/fixtures/item_unusual.json +311 -1
- data/spec/fixtures/item_with_dual_craftability_tradability.json +59 -0
- data/spec/fixtures/market_prices.json +1 -0
- data/spec/fixtures/price_history.json +1 -0
- data/spec/fixtures/prices.json +80 -1
- data/spec/fixtures/user_listing.json +1 -1
- data/spec/fixtures/user_listing_individual.json +51 -0
- data/spec/spec_helper.rb +12 -52
- metadata +61 -16
- data/TODO.md +0 -15
- data/lib/backpack_tf/item.rb +0 -84
- data/lib/backpack_tf/item_price.rb +0 -172
- data/readme.md +0 -96
- data/spec/backpack_tf/inherited_class_methods_spec.rb +0 -100
- data/spec/backpack_tf/item_price_spec.rb +0 -119
- data/spec/backpack_tf/item_spec.rb +0 -126
- data/spec/backpack_tf/price_spec.rb +0 -184
- data/spec/fixtures/item_without_defindex.json +0 -1
data/lib/backpack_tf/user.rb
CHANGED
@@ -1,21 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
INTERFACE = :IGetUsers
|
4
|
-
@interface = INTERFACE
|
5
|
-
@response = nil
|
6
|
-
@@players = {}
|
7
|
-
|
8
|
-
def self.response
|
9
|
-
@response = superclass.responses[to_sym]
|
10
|
-
end
|
1
|
+
require 'backpack_tf/user/interface'
|
2
|
+
require 'backpack_tf/user/response'
|
11
3
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
players
|
17
|
-
end
|
18
|
-
end
|
4
|
+
module BackpackTF
|
5
|
+
# Ruby representations of a JSON response to IGetUsers
|
6
|
+
class User
|
7
|
+
include Helpers
|
19
8
|
|
20
9
|
attr_reader :steamid
|
21
10
|
attr_reader :success
|
@@ -32,8 +21,10 @@ module BackpackTF
|
|
32
21
|
attr_reader :ban_vac
|
33
22
|
attr_reader :notifications
|
34
23
|
|
35
|
-
|
36
|
-
|
24
|
+
# @param attr [Hash] Attributes.
|
25
|
+
# @return [User] A new User object.
|
26
|
+
def initialize(attr)
|
27
|
+
attr = hash_keys_to_sym(attr)
|
37
28
|
|
38
29
|
@steamid = attr[:steamid]
|
39
30
|
@success = attr[:success]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BackpackTF
|
2
|
+
class UserListing
|
3
|
+
# Access the IGetUserListings interface
|
4
|
+
class Interface < BackpackTF::Interface
|
5
|
+
class << self
|
6
|
+
attr_reader :steamid
|
7
|
+
end
|
8
|
+
|
9
|
+
@name = :IGetUserListings
|
10
|
+
@version = 2
|
11
|
+
|
12
|
+
def self.defaults(options)
|
13
|
+
@steamid = options[:steamid] || nil
|
14
|
+
super(options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BackpackTF
|
2
|
+
class UserListing
|
3
|
+
# Process reponses from IGetUserListings
|
4
|
+
class Response < BackpackTF::Response
|
5
|
+
@response = nil
|
6
|
+
@listings = []
|
7
|
+
|
8
|
+
def self.listings
|
9
|
+
@listings = response['listings'].map do |attr|
|
10
|
+
BackpackTF::UserListing.new(attr)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,60 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
INTERFACE = :IGetUserListings
|
5
|
-
|
6
|
-
@interface = INTERFACE
|
7
|
-
@response = nil
|
8
|
-
@@listings = []
|
1
|
+
require 'backpack_tf/user_listing/interface'
|
2
|
+
require 'backpack_tf/user_listing/response'
|
9
3
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.listings
|
17
|
-
return @response if response.nil?
|
18
|
-
@@listings = response[:listings].inject([]) do |listings, attr|
|
19
|
-
listings << new(attr)
|
20
|
-
listings
|
21
|
-
end
|
22
|
-
end
|
4
|
+
module BackpackTF
|
5
|
+
# Ruby representations of a JSON response to IGetUserListings
|
6
|
+
class UserListing
|
7
|
+
include Helpers
|
23
8
|
|
24
|
-
attr_reader :id
|
25
9
|
attr_reader :bump
|
26
|
-
attr_reader :
|
10
|
+
attr_reader :intent
|
27
11
|
attr_reader :currencies
|
28
|
-
attr_reader :item
|
29
|
-
attr_reader :details
|
30
|
-
attr_reader :meta
|
31
12
|
attr_reader :buyout
|
13
|
+
attr_reader :details
|
14
|
+
attr_reader :item
|
15
|
+
attr_reader :flags
|
16
|
+
attr_reader :created
|
17
|
+
attr_reader :id
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
19
|
+
# @param attr [Hash] Attributes.
|
20
|
+
# @return [UserListing] A new UserListing object.
|
21
|
+
def initialize(attr)
|
22
|
+
attr = hash_keys_to_sym(attr)
|
23
|
+
|
24
|
+
@bump = attr[:bump]
|
25
|
+
@intent = attr[:intent]
|
26
|
+
@currencies = hash_keys_to_sym(attr[:currencies])
|
27
|
+
@buyout = attr[:buyout]
|
28
|
+
@details = attr[:details]
|
29
|
+
@item = set_keys_of_key_to_symbols(attr[:item], 'attributes')
|
30
|
+
@flags = hash_keys_to_sym(attr[:flags])
|
31
|
+
@created = attr[:created]
|
32
|
+
@id = attr[:id]
|
44
33
|
end
|
45
34
|
|
46
35
|
private
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return nil unless attr.has_key? key
|
36
|
+
|
37
|
+
def set_keys_of_key_to_symbols(attr, key)
|
38
|
+
return nil unless attr.key?(key)
|
51
39
|
|
52
40
|
item_attributes = attr[key].map do |set_of_attr|
|
53
|
-
|
41
|
+
hash_keys_to_sym(set_of_attr)
|
54
42
|
end
|
55
43
|
attr[key] = item_attributes
|
56
44
|
|
57
|
-
|
45
|
+
hash_keys_to_sym(attr)
|
58
46
|
end
|
59
47
|
end
|
60
48
|
end
|
data/lib/backpack_tf/version.rb
CHANGED
data/lib/backpack_tf.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
|
-
# namespace for classes & modules inside of the wrapper for the BackpackTF API
|
4
|
-
module BackpackTF
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
# IMPORTANT! require the Response module before any other class or module
|
9
3
|
require 'backpack_tf/version'
|
10
4
|
require 'backpack_tf/response'
|
5
|
+
require 'backpack_tf/interface'
|
11
6
|
require 'backpack_tf/client'
|
7
|
+
require 'backpack_tf/helpers'
|
12
8
|
require 'backpack_tf/currency'
|
13
|
-
require 'backpack_tf/item'
|
14
|
-
require 'backpack_tf/item_price'
|
15
9
|
require 'backpack_tf/price'
|
16
10
|
require 'backpack_tf/special_item'
|
17
11
|
require 'backpack_tf/user'
|
18
12
|
require 'backpack_tf/user_listing'
|
13
|
+
require 'backpack_tf/price_history'
|
14
|
+
require 'backpack_tf/market_price'
|
15
|
+
|
16
|
+
# backpack.tf API library
|
17
|
+
module BackpackTF
|
18
|
+
end
|
@@ -1,133 +1,183 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe BackpackTF::Client do
|
4
|
+
let(:key) { 'deadbeef01234567deadbeef' }
|
5
|
+
let(:bp) { BackpackTF::Client.new(key) }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'calls #check_key' do
|
9
|
+
expect_any_instance_of(described_class).to receive(:check_key)
|
10
|
+
described_class.new(key)
|
11
|
+
end
|
12
|
+
it 'sets a value for @key' do
|
13
|
+
client = described_class.new(key)
|
14
|
+
expect(client.instance_eval { @key }).to eq 'deadbeef01234567deadbeef'
|
15
|
+
end
|
16
|
+
it 'calls #httparty_settings' do
|
17
|
+
expect_any_instance_of(described_class).to receive(:httparty_settings)
|
18
|
+
described_class.new(key)
|
19
|
+
end
|
20
|
+
end
|
6
21
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
expect(
|
22
|
+
describe '#fetch' do
|
23
|
+
it 'calls #get_data' do
|
24
|
+
mock_response = { 'response' => nil }
|
25
|
+
expect(bp).to receive(:get_data).and_return(mock_response)
|
26
|
+
bp.fetch(:foo)
|
11
27
|
end
|
28
|
+
it 'fetches JSON from an interface and returns a response' do
|
29
|
+
stub_http_response_with('currencies.json')
|
30
|
+
response = bp.fetch(:currencies, compress: 1, appid: 440)
|
31
|
+
response.keys.all? do |key|
|
32
|
+
expect(response[key]).not_to be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
12
36
|
|
13
|
-
|
37
|
+
describe '#get_data' do
|
38
|
+
it 'calls #handle_timeout' do
|
39
|
+
allow(described_class).to receive(:get).and_return('get')
|
40
|
+
allow(bp).to receive(:build_url_via).and_return('url')
|
41
|
+
expect(bp).to receive(:handle_timeouts)
|
42
|
+
bp.send(:get_data, :foo)
|
43
|
+
end
|
44
|
+
it 'calls #build_url_via' do
|
45
|
+
allow(described_class).to receive(:get).and_return('get')
|
46
|
+
expect(bp).to receive(:build_url_via).and_return('url')
|
47
|
+
bp.send(:get_data, :foo)
|
48
|
+
end
|
49
|
+
it 'calls HTTParty.get' do
|
50
|
+
allow(bp).to receive(:build_url_via).and_return('url')
|
51
|
+
expect(described_class).to receive(:get)
|
52
|
+
bp.send(:get_data, :foo)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'handle_timeouts' do
|
57
|
+
specify do
|
58
|
+
expect { |mtd| bp.send(:handle_timeouts, &mtd) }.to yield_control
|
59
|
+
end
|
60
|
+
it 'rescues on Net::OpenTimeout or Net::ReadTimeout exceptions' do
|
61
|
+
bp.send(:handle_timeouts) { raise Net::OpenTimeout }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe('#httparty_settings') do
|
66
|
+
before(:each) do
|
67
|
+
bp.instance_eval { @key = 'foo' }
|
68
|
+
end
|
69
|
+
after(:each) do
|
70
|
+
bp.instance_eval { @key = nil }
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'sets some default_options for HTTParty' do
|
74
|
+
bp.send(:httparty_settings)
|
75
|
+
|
76
|
+
actual = described_class.default_options
|
77
|
+
expect(actual[:base_uri]).not_to be_nil
|
78
|
+
expect(actual[:timeout]).not_to be_nil
|
79
|
+
expect(actual[:default_params][:key]).not_to be_nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#check_key' do
|
84
|
+
context('without a key') do
|
85
|
+
it 'gently reminds user to set an API key' do
|
86
|
+
expect(bp).to receive(:warn)
|
87
|
+
bp.send(:check_key)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context('checking a key') do
|
14
91
|
it 'Raises ArgumentError, if key is not a hexadecimal string' do
|
15
92
|
fake_key = 'abcdefghijklmnopqrstuvwx'
|
16
|
-
expect{
|
93
|
+
expect { bp.send(:check_key, fake_key) }.to raise_error ArgumentError
|
17
94
|
end
|
18
95
|
it 'Raises ArgumentError, if key is not 24 digits long' do
|
19
96
|
fake_key = 'abcdef0987654321'
|
20
|
-
expect{
|
97
|
+
expect { bp.send(:check_key, fake_key) }.to raise_error ArgumentError
|
21
98
|
end
|
22
|
-
it 'lets an otherwise theoretically-valid key
|
99
|
+
it 'lets an otherwise theoretically-valid key pass through' do
|
23
100
|
key = generate_fake_api_key
|
24
|
-
expect(
|
101
|
+
expect(bp.send(:check_key, key)).to eq key
|
25
102
|
end
|
26
103
|
end
|
104
|
+
end
|
27
105
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
ans = "key=#{Client.api_key}&appid=440&format=json&compress=1&raw=2"
|
32
|
-
expect(Client.extract_query_string(opts)).to eq ans
|
33
|
-
end
|
106
|
+
describe '#build_url_via' do
|
107
|
+
before(:each) do
|
108
|
+
allow(bp).to receive(:warn).and_return true
|
34
109
|
end
|
35
110
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
it 'raises an error when asking for any unexpected interface' do
|
42
|
-
expect{Client.build_url_via(:foo)}.to raise_error ArgumentError
|
43
|
-
end
|
44
|
-
end
|
111
|
+
it 'returns correct destination url when asking for pricing data' do
|
112
|
+
query_opts = {
|
113
|
+
key: key,
|
114
|
+
compress: 1
|
115
|
+
}
|
45
116
|
|
46
|
-
|
117
|
+
actual = bp.send(:build_url_via, :prices, query_opts)
|
118
|
+
expected = "http://backpack.tf/api/IGetPrices/v4/?key=#{key}&compress=1"
|
47
119
|
|
48
|
-
|
49
|
-
|
50
|
-
|
120
|
+
expect(actual).to eq expected
|
121
|
+
end
|
122
|
+
end
|
51
123
|
|
52
|
-
|
53
|
-
|
124
|
+
describe '#extract_query_string' do
|
125
|
+
it 'produces a query parameter string' do
|
126
|
+
opts = {
|
127
|
+
key: key,
|
128
|
+
appid: 440,
|
129
|
+
format: 'json',
|
130
|
+
compress: 1,
|
131
|
+
raw: 2
|
54
132
|
}
|
55
133
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
134
|
+
expected = "key=#{key}&appid=440&format=json&compress=1&raw=2"
|
135
|
+
expect(bp.send(:extract_query_string, opts)).to eq expected
|
136
|
+
end
|
137
|
+
it 'separates array values by comma' do
|
138
|
+
opts = {
|
139
|
+
steamids: %w(1 2 3)
|
140
|
+
}
|
63
141
|
|
142
|
+
expected = 'steamids=1,2,3'
|
143
|
+
expect(bp.send(:extract_query_string, opts)).to eq expected
|
64
144
|
end
|
145
|
+
end
|
65
146
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# allow(MockResponse).to receive(:responses) {
|
73
|
-
# { MockCurrency => fetched_currencies }
|
74
|
-
# }
|
75
|
-
# expect(MockResponse.responses.keys).to eq [MockCurrency]
|
76
|
-
|
77
|
-
# allow(MockCurrency).to receive(:response) {
|
78
|
-
# Response.hash_keys_to_sym(MockResponse.responses[MockCurrency])
|
79
|
-
# }
|
80
|
-
# expect(MockCurrency.response.keys).to eq [:success, :currencies, :name, :url, :current_time]
|
81
|
-
|
82
|
-
# allow(MockCurrency).to receive(:currencies)
|
83
|
-
# #expect(MockCurrency.response).to be_nil
|
84
|
-
# end
|
85
|
-
|
86
|
-
# it 'the client passes its fetched data to Response.response class method' do
|
87
|
-
# end
|
88
|
-
# it 'the client can pass fetched data to another class so the class can update one of its own class variables' do
|
89
|
-
# MockResponse.responses(MockCurrency => fetched_currencies)
|
90
|
-
# MockCurrency.response
|
91
|
-
# expect(MockCurrency.currencies).not_to be_nil
|
92
|
-
# end
|
93
|
-
#end
|
94
|
-
|
95
|
-
before :each do
|
96
|
-
stub_http_response_with('currencies.json')
|
97
|
-
Response.responses(:reset => :confirm)
|
98
|
-
expect(Response.responses).to be_empty
|
99
|
-
expect(Currency.response).to be_nil
|
100
|
-
expect(Currency.currencies).to be_nil
|
147
|
+
describe '#select_interface_url_fragment' do
|
148
|
+
context 'verifying API base urls' do
|
149
|
+
it 'gets it right for IGetCurrencies' do
|
150
|
+
actual = bp.send(:select_interface_url_fragment, :currencies)
|
151
|
+
expect(actual).to eq '/IGetCurrencies/v1/?'
|
101
152
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
expect(Response.responses).to be_empty
|
106
|
-
expect(Currency.response).to be_nil
|
107
|
-
expect(Currency.currencies).to be_nil
|
153
|
+
it 'gets it right for IGetMarketPrices' do
|
154
|
+
actual = bp.send(:select_interface_url_fragment, :market_prices)
|
155
|
+
expect(actual).to eq '/IGetMarketPrices/v1/?'
|
108
156
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
113
|
-
|
114
|
-
context 'results on the Currency.response method' do
|
115
|
-
it 'returns this Hash object' do
|
116
|
-
bp.update(Currency, fetched_currencies)
|
117
|
-
processed_json = Response.hash_keys_to_sym(fetched_currencies)
|
118
|
-
expect(Currency.response).to eq processed_json
|
119
|
-
end
|
157
|
+
it 'gets it right for IGetPrices' do
|
158
|
+
actual = bp.send(:select_interface_url_fragment, :prices)
|
159
|
+
expect(actual).to eq '/IGetPrices/v4/?'
|
120
160
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
161
|
+
it 'gets it right for IGetPriceHistory' do
|
162
|
+
actual = bp.send(:select_interface_url_fragment, :price_history)
|
163
|
+
expect(actual).to eq '/IGetPriceHistory/v1/?'
|
164
|
+
end
|
165
|
+
it 'gets it right for IGetSpecialItems' do
|
166
|
+
actual = bp.send(:select_interface_url_fragment, :special_items)
|
167
|
+
expect(actual).to eq '/IGetSpecialItems/v1/?'
|
168
|
+
end
|
169
|
+
it 'gets it right for IGetUsers' do
|
170
|
+
actual = bp.send(:select_interface_url_fragment, :users)
|
171
|
+
expect(actual).to eq '/IGetUsers/v3/?'
|
172
|
+
end
|
173
|
+
it 'gets it right for IGetUserListings' do
|
174
|
+
actual = bp.send(:select_interface_url_fragment, :user_listings)
|
175
|
+
expect(actual).to eq '/IGetUserListings/v2/?'
|
128
176
|
end
|
129
|
-
|
130
177
|
end
|
131
|
-
|
178
|
+
it 'returns nil when it cannot match to an action' do
|
179
|
+
actual = bp.send(:select_interface_url_fragment, :foobar)
|
180
|
+
expect(actual).to be_nil
|
181
|
+
end
|
132
182
|
end
|
133
183
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BackpackTF::Currency::Response do
|
4
|
+
let(:json_response) do
|
5
|
+
fixture = file_fixture('currencies_updated.json')
|
6
|
+
JSON.parse(fixture)['response']
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'reader methods' do
|
10
|
+
before(:each) do
|
11
|
+
described_class.response = json_response
|
12
|
+
end
|
13
|
+
after(:each) do
|
14
|
+
described_class.response = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '::currencies' do
|
18
|
+
it 'should have these keys' do
|
19
|
+
currencies = described_class.currencies
|
20
|
+
expected_keys = %w(metal keys earbuds hat)
|
21
|
+
expect(currencies.keys).to match_array expected_keys
|
22
|
+
end
|
23
|
+
it 'each key points to an instance of BackpackTF::Currency' do
|
24
|
+
currencies = described_class.currencies
|
25
|
+
expect(currencies.values).to all be_a BackpackTF::Currency
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '::name' do
|
30
|
+
it 'returns the value' do
|
31
|
+
expect(described_class.name).to eq 'Team Fortress 2'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '::url' do
|
36
|
+
it 'returns the value' do
|
37
|
+
expect(described_class.url).to eq 'http://backpack.tf'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|