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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +5 -3
  6. data/Gemfile.lock +49 -0
  7. data/README.md +144 -0
  8. data/Rakefile +7 -0
  9. data/backpack_tf.gemspec +2 -2
  10. data/lib/backpack_tf/assets/{attribute_controlled_attached_particles.json → particle_effects.json} +0 -0
  11. data/lib/backpack_tf/client.rb +72 -95
  12. data/lib/backpack_tf/currency/interface.rb +9 -0
  13. data/lib/backpack_tf/currency/response.rb +24 -0
  14. data/lib/backpack_tf/currency.rb +24 -47
  15. data/lib/backpack_tf/helpers.rb +29 -0
  16. data/lib/backpack_tf/interface.rb +29 -0
  17. data/lib/backpack_tf/market_price/interface.rb +9 -0
  18. data/lib/backpack_tf/market_price/response.rb +15 -0
  19. data/lib/backpack_tf/market_price.rb +25 -0
  20. data/lib/backpack_tf/price/interface.rb +19 -0
  21. data/lib/backpack_tf/price/item.rb +85 -0
  22. data/lib/backpack_tf/price/item_price.rb +113 -0
  23. data/lib/backpack_tf/price/particle_effect.rb +27 -0
  24. data/lib/backpack_tf/price/response.rb +38 -0
  25. data/lib/backpack_tf/price.rb +9 -81
  26. data/lib/backpack_tf/price_history/interface.rb +22 -0
  27. data/lib/backpack_tf/price_history/response.rb +15 -0
  28. data/lib/backpack_tf/price_history.rb +25 -0
  29. data/lib/backpack_tf/response.rb +9 -56
  30. data/lib/backpack_tf/special_item/interface.rb +9 -0
  31. data/lib/backpack_tf/special_item/response.rb +16 -0
  32. data/lib/backpack_tf/special_item.rb +11 -21
  33. data/lib/backpack_tf/user/interface.rb +18 -0
  34. data/lib/backpack_tf/user/response.rb +16 -0
  35. data/lib/backpack_tf/user.rb +10 -19
  36. data/lib/backpack_tf/user_listing/interface.rb +18 -0
  37. data/lib/backpack_tf/user_listing/response.rb +15 -0
  38. data/lib/backpack_tf/user_listing.rb +31 -43
  39. data/lib/backpack_tf/version.rb +1 -1
  40. data/lib/backpack_tf.rb +8 -8
  41. data/spec/backpack_tf/client_spec.rb +151 -101
  42. data/spec/backpack_tf/currency/interface_spec.rb +8 -0
  43. data/spec/backpack_tf/currency/response_spec.rb +41 -0
  44. data/spec/backpack_tf/currency_spec.rb +34 -118
  45. data/spec/backpack_tf/helpers_spec.rb +85 -0
  46. data/spec/backpack_tf/interface_spec.rb +56 -0
  47. data/spec/backpack_tf/market_price/interface_spec.rb +8 -0
  48. data/spec/backpack_tf/market_price/response_spec.rb +22 -0
  49. data/spec/backpack_tf/market_price_spec.rb +22 -0
  50. data/spec/backpack_tf/price/interface_spec.rb +27 -0
  51. data/spec/backpack_tf/price/item_price_spec.rb +101 -0
  52. data/spec/backpack_tf/price/item_spec.rb +291 -0
  53. data/spec/backpack_tf/price/particle_effect_spec.rb +23 -0
  54. data/spec/backpack_tf/price/response_spec.rb +87 -0
  55. data/spec/backpack_tf/price_history/interface_spec.rb +38 -0
  56. data/spec/backpack_tf/price_history/response_spec.rb +22 -0
  57. data/spec/backpack_tf/price_history_spec.rb +24 -0
  58. data/spec/backpack_tf/response_spec.rb +22 -108
  59. data/spec/backpack_tf/special_item/interface_spec.rb +8 -0
  60. data/spec/backpack_tf/special_item/response_spec.rb +26 -0
  61. data/spec/backpack_tf/special_item_spec.rb +23 -100
  62. data/spec/backpack_tf/user/interface_spec.rb +20 -0
  63. data/spec/backpack_tf/user/response_spec.rb +27 -0
  64. data/spec/backpack_tf/user_listing/interface_spec.rb +20 -0
  65. data/spec/backpack_tf/user_listing/response_spec.rb +21 -0
  66. data/spec/backpack_tf/user_listing_spec.rb +53 -81
  67. data/spec/backpack_tf/user_spec.rb +16 -83
  68. data/spec/fixtures/item_price_typical.json +6 -0
  69. data/spec/fixtures/item_price_unusual.json +7 -0
  70. data/spec/fixtures/item_typical.json +1 -1
  71. data/spec/fixtures/item_unusual.json +311 -1
  72. data/spec/fixtures/item_with_dual_craftability_tradability.json +59 -0
  73. data/spec/fixtures/market_prices.json +1 -0
  74. data/spec/fixtures/price_history.json +1 -0
  75. data/spec/fixtures/prices.json +80 -1
  76. data/spec/fixtures/user_listing.json +1 -1
  77. data/spec/fixtures/user_listing_individual.json +51 -0
  78. data/spec/spec_helper.rb +12 -52
  79. metadata +61 -16
  80. data/TODO.md +0 -15
  81. data/lib/backpack_tf/item.rb +0 -84
  82. data/lib/backpack_tf/item_price.rb +0 -172
  83. data/readme.md +0 -96
  84. data/spec/backpack_tf/inherited_class_methods_spec.rb +0 -100
  85. data/spec/backpack_tf/item_price_spec.rb +0 -119
  86. data/spec/backpack_tf/item_spec.rb +0 -126
  87. data/spec/backpack_tf/price_spec.rb +0 -184
  88. data/spec/fixtures/item_without_defindex.json +0 -1
@@ -1,21 +1,10 @@
1
- module BackpackTF
2
- class User < Response
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
- def self.players
13
- return @response if response.nil?
14
- @@players = response[:players].inject({}) do |players, (steamid, attr)|
15
- players[steamid] = new(attr)
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
- def initialize attr
36
- attr = check_attr_keys(attr)
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
- module BackpackTF
2
- class UserListing < Response
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
- def self.interface; @interface; end
11
-
12
- def self.response
13
- @response = superclass.responses[to_sym]
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 :created
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
- def initialize attr
34
- attr = check_attr_keys(attr)
35
-
36
- @id = attr[:id].to_sym
37
- @bump = attr[:bump]
38
- @created = attr[:created]
39
- @currencies = attr[:currencies]
40
- @item = set_keys_of_key_to_symbols(attr[:item], 'attributes')
41
- @details = attr[:details]
42
- @meta = self.class.hash_keys_to_sym(attr[:meta])
43
- @buyout = attr[:buyout]
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
- # Similar to Response.hash_key_to_sym, except you are returning
48
- # an Array of Hash objects instead of a Hash.
49
- def set_keys_of_key_to_symbols attr, key
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
- self.class.hash_keys_to_sym(set_of_attr)
41
+ hash_keys_to_sym(set_of_attr)
54
42
  end
55
43
  attr[key] = item_attributes
56
44
 
57
- self.class.hash_keys_to_sym(attr)
45
+ hash_keys_to_sym(attr)
58
46
  end
59
47
  end
60
48
  end
@@ -1,3 +1,3 @@
1
1
  module BackpackTF
2
- VERSION = "0.8.4"
2
+ VERSION = '1.0.0.rc1'.freeze
3
3
  end
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
- module BackpackTF
4
- describe 'Client' do
5
- let(:bp) { Client.new }
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
- it 'has these default options' do
8
- ans = { base_uri: 'http://backpack.tf/api', timeout: 5 }
9
- ans[:default_params] = { key: ENV[Client.env_var] }
10
- expect(Client.default_options).to eq ans
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
- describe '::api_key' do
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{Client.api_key(fake_key)}.to raise_error ArgumentError
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{Client.api_key(fake_key)}.to raise_error ArgumentError
97
+ expect { bp.send(:check_key, fake_key) }.to raise_error ArgumentError
21
98
  end
22
- it 'lets an otherwise theoretically-valid key, pass through' do
99
+ it 'lets an otherwise theoretically-valid key pass through' do
23
100
  key = generate_fake_api_key
24
- expect(Client.api_key(key)).to eq key
101
+ expect(bp.send(:check_key, key)).to eq key
25
102
  end
26
103
  end
104
+ end
27
105
 
28
- describe '::extract_query_string' do
29
- it 'produces a query parameter string' do
30
- opts = {:key => Client.api_key, :appid => 440, :format => 'json', :compress => 1, :raw => 2}
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
- describe '::build_url_via' do
37
- it 'returns correct destination url when asking for pricing data' do
38
- opts = {:key => Client.api_key, :compress => 1}
39
- expect(Client.build_url_via(:get_prices, opts)).to eq "http://backpack.tf/api/IGetPrices/v4/?key=#{Client.api_key}&compress=1"
40
- end
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
- describe '#fetch' do
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
- before :each do
49
- stub_http_response_with('currencies.json')
50
- end
120
+ expect(actual).to eq expected
121
+ end
122
+ end
51
123
 
52
- let(:fetched_currencies) {
53
- bp.fetch(:currencies, {:compress => 1, :appid => 440})
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
- it 'fetches JSON from an interface and returns as a Hash object' do
57
- expect(fetched_currencies).to be_instance_of Hash
58
- end
59
- it 'fetched response has these keys' do
60
- expected_keys = %w(currencies current_time name success url)
61
- expect(fetched_currencies.keys).to match_array expected_keys
62
- end
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
- describe '#update' do
67
- #context "USING rspec/mock, updating another another class' class variable" do
68
- # before :each do
69
- # MockResponse = class_double(Response)
70
- # MockCurrency = class_double(Currency)
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
- after :each do
104
- Response.responses(:reset => :confirm)
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
- let(:fetched_currencies) {
111
- bp.fetch(:currencies, {:compress => 1, :appid => 440})
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
- context 'results on the Currency.currencies method' do
123
- it 'returns this Hash object' do
124
- bp.update(Currency, fetched_currencies)
125
- processed_json = Response.hash_keys_to_sym(fetched_currencies['currencies'])
126
- expect(Currency.currencies).to eq processed_json
127
- end
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,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::Currency::Interface do
4
+ it 'has these attributes' do
5
+ expect(described_class.name).to eq :IGetCurrencies
6
+ expect(described_class.version).to eq 1
7
+ end
8
+ 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