backpack_tf 0.8.4 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,25 @@
1
+ require 'backpack_tf/market_price/interface'
2
+ require 'backpack_tf/market_price/response'
3
+
4
+ module BackpackTF
5
+ # Ruby representations of a JSON response to IGetMarketPrices
6
+ class MarketPrice
7
+ include Helpers
8
+
9
+ attr_reader :last_updated
10
+ attr_reader :quantity
11
+ attr_reader :value
12
+
13
+ # @param name [String] The name of the item.
14
+ # @param attr [Hash] Attributes for the item.
15
+ # @return [MarketPrice] A new MarketPrice object.
16
+ def initialize(name, attr)
17
+ attr = hash_keys_to_sym(attr)
18
+
19
+ @name = name.to_s
20
+ @last_updated = attr[:last_updated]
21
+ @quantity = attr[:quantity]
22
+ @value = attr[:value]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module BackpackTF
2
+ module Price
3
+ # Access the IGetPrices interface
4
+ class Interface < BackpackTF::Interface
5
+ class << self
6
+ attr_reader :raw, :since
7
+ end
8
+
9
+ @name = :IGetPrices
10
+ @version = 4
11
+
12
+ def self.defaults(options)
13
+ @raw = options[:raw] || nil
14
+ @since = options[:since] || nil
15
+ super(options)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,85 @@
1
+ module BackpackTF
2
+ module Price
3
+ # This lives inside the `@items` hash of BackpackTF::Price::Response
4
+ class Item
5
+ # @return [String] the name of item
6
+ attr_reader :item_name
7
+ # @return [Fixnum] an index number as per TF2's Item Schema
8
+ attr_reader :defindex
9
+ # @return [Hash<Fixnum, ItemPrice>] pricing information for a given item
10
+ attr_reader :prices
11
+
12
+ def initialize(item_name, attr)
13
+ @item_name = item_name
14
+ @defindex = process_defindex(attr['defindex'])
15
+ @prices = generate_prices_hash(attr)
16
+ end
17
+
18
+ private
19
+
20
+ def process_defindex(arr)
21
+ return nil if arr.length == 0
22
+ return arr[0] if arr.length == 1
23
+ arr
24
+ end
25
+
26
+ def generate_prices_hash(input_hash)
27
+ prices = input_hash['prices']
28
+
29
+ prices.each_with_object({}) do |(quality_idx), prices_acc|
30
+ tradables = prices[quality_idx]
31
+
32
+ tradables.each_key do |tradability|
33
+ craftables = tradables[tradability]
34
+
35
+ craftables.each_key do |craftability|
36
+ price_indices = craftables[craftability]
37
+
38
+ price_indices.each_key do |price_idx|
39
+ item_price_data = price_indices[price_idx]
40
+ key_str = keyname(quality_idx, tradability, craftability, price_idx)
41
+
42
+ if price_idx == '0'
43
+ build_item_price(prices_acc, key_str, item_price_data)
44
+ elsif quality_idx == '5'
45
+ build_unusual_item_price(prices_acc, key_str, item_price_data, price_idx)
46
+ else
47
+ build_crate_price(prices_acc, key_str, item_price_data, price_idx)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def quality_index_to_name(index)
56
+ ItemPrice.qualities[index.to_i]
57
+ end
58
+
59
+ def keyname(quality_idx, tradability, craftability, price_idx = '0')
60
+ quality = quality_index_to_name(quality_idx)
61
+ key_str = "#{quality}_#{tradability}_#{craftability}"
62
+ key_str << "_##{price_idx}" unless price_idx == '0'
63
+ key_str
64
+ end
65
+
66
+ def build_item_price(accumulation, key_str, attr)
67
+ item_price = ItemPrice.new(key_str, attr)
68
+ accumulation[key_str] = item_price
69
+ accumulation
70
+ end
71
+
72
+ def build_unusual_item_price(accumulation, key_str, attr, price_idx)
73
+ item_price = ItemPrice.new(key_str, attr, price_idx)
74
+ accumulation[item_price.effect] = item_price
75
+ accumulation
76
+ end
77
+
78
+ def build_crate_price(accumulation, key_str, attr, price_idx)
79
+ item_price = ItemPrice.new(key_str, attr, price_idx)
80
+ accumulation[key_str] = item_price
81
+ accumulation
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,113 @@
1
+ module BackpackTF
2
+ module Price
3
+ # Price for an individual item.
4
+ # This lives inside the `@prices` hash of a BackpackTF::Item object.
5
+ class ItemPrice
6
+ KEYNAME_DELIMITER = '_'.freeze
7
+
8
+ class << self
9
+ # @return [Array<Symbol>] maps quality integers to quality names
10
+ # see: https://wiki.teamfortress.com/wiki/WebAPI/GetSchema#Result_Data
11
+ attr_reader :qualities
12
+ # @return [Array<Symbol>] possible values for tradable
13
+ attr_reader :tradabilities
14
+ # @return [Array<Symbol>] possible values for craftable
15
+ attr_reader :craftabilities
16
+ end
17
+
18
+ @qualities = [
19
+ :Normal,
20
+ :Genuine,
21
+ nil,
22
+ :Vintage,
23
+ nil,
24
+ :Unusual,
25
+ :Unique,
26
+ :Community,
27
+ :Valve,
28
+ :"Self-Made",
29
+ nil,
30
+ :Strange,
31
+ nil,
32
+ :Haunted,
33
+ :"Collector's"
34
+ ]
35
+ @tradabilities = [:Tradable, :'Non-Tradable']
36
+ @craftabilities = [:Craftable, :'Non-Craftable']
37
+
38
+ def self.quality_name_to_index(quality)
39
+ qualities.index(quality.to_sym) unless quality.nil?
40
+ end
41
+
42
+ # @return [String] item quality
43
+ attr_reader :quality
44
+ # @return [Symbol] either :Tradable or :'Non-Tradable'
45
+ attr_reader :tradability
46
+ # @return [Symbol] either :Craftable or :'Non-Craftable'
47
+ attr_reader :craftability
48
+ # @return [NilClass or Fixnum] May signify crate series or unusual effect
49
+ attr_reader :priceindex
50
+ # @return [Symbol] The currency of the item's price
51
+ attr_reader :currency
52
+ # @return [Float] The value of the item in said currency
53
+ attr_reader :value
54
+ # @return [Float] The item's upper value in said currency.
55
+ # Only set if the item has a price range
56
+ attr_reader :value_high
57
+ # @return [Float] The item's value in the lowest currency w/o rounding.
58
+ # If raw is set to 2, this is the lower value if a high value exists.
59
+ # Otherwise, this is the average between the high and low value.
60
+ # Requires raw to be enabled.
61
+ attr_reader :value_raw
62
+ # @return [Float] The item's value in the lowest currency w/o rounding.
63
+ # Requires for 'raw' to be enabled & set to 2.
64
+ attr_reader :value_high_raw
65
+ # @return [Fixnum] A timestamp of when the price was last updated
66
+ attr_reader :last_update
67
+ # @return [Fixnum] A relative difference between the former price & the
68
+ # current price. If 0, assume new price.
69
+ attr_reader :difference
70
+ # @return [String] Which particle effect, if any
71
+ attr_reader :effect
72
+
73
+ # @param key [Array], describes the quality, tradability & craftability
74
+ # of an item. For example: ['Unique', 'Tradable', 'Craftable']
75
+ # It is directly related to the path you would take to find
76
+ # the price from the `@prices` attribute of that item.
77
+ # @param attr [Hash], collection of attributes for the price
78
+ # @param priceindex [nil, Fixnum, Array], not needed unless the item is
79
+ # Unusual, a Crate, a Strangifier, a Chemistry set or has dual qualities
80
+ def initialize(key, attr, priceindex = nil)
81
+ key = split_key(key)
82
+
83
+ @quality = key[0].to_sym
84
+ @tradability = key[1].to_sym
85
+ @craftability = key[2].to_sym
86
+ @currency = currency_or_nil(attr)
87
+ @value = attr['value']
88
+ @value_high = attr['value_high']
89
+ @value_raw = attr['value_raw']
90
+ @value_high_raw = attr['value_high_raw']
91
+ @last_update = attr['last_update']
92
+ @difference = attr['difference']
93
+ @priceindex = priceindex
94
+ @effect = pick_particle_effect(priceindex)
95
+ end
96
+
97
+ private
98
+
99
+ def split_key(key)
100
+ key.split(KEYNAME_DELIMITER)
101
+ end
102
+
103
+ def currency_or_nil(attr)
104
+ curr = attr.fetch('currency', nil)
105
+ curr.to_sym unless curr.nil?
106
+ end
107
+
108
+ def pick_particle_effect(priceindex)
109
+ ParticleEffect.list[priceindex.to_i]
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,27 @@
1
+ module BackpackTF
2
+ module Price
3
+ # For ItemPrice objects with attached particle effects
4
+ class ParticleEffect
5
+ class << self
6
+ # @return [Hash] possible particle effects for an item
7
+ attr_reader :list
8
+ end
9
+
10
+ @key = 'attribute_controlled_attached_particles'
11
+ @file = './lib/backpack_tf/assets/particle_effects.json'
12
+
13
+ def self.read_stored_effects_info
14
+ file = File.open(@file).read
15
+ effects = JSON.parse(file)[@key]
16
+
17
+ effects.each_with_object({}) do |effect, hash|
18
+ id = effect['id']
19
+ name = effect['name']
20
+ hash[id] = name
21
+ end
22
+ end
23
+
24
+ @list = read_stored_effects_info
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ module BackpackTF
2
+ module Price
3
+ # Process reponses from IGetPrices
4
+ class Response < BackpackTF::Response
5
+ @response = nil
6
+ @items = nil
7
+
8
+ def self.raw_usd_value
9
+ @response['raw_usd_value']
10
+ end
11
+
12
+ def self.usd_currency
13
+ @response['usd_currency']
14
+ end
15
+
16
+ def self.usd_currency_index
17
+ @response['usd_currency_index']
18
+ end
19
+
20
+ def self.items
21
+ @items ||= generate_items
22
+ end
23
+
24
+ def self.generate_items
25
+ @response['items'].each_with_object({}) do |(name), items|
26
+ defindex = @response['items'][name]['defindex'][0]
27
+
28
+ if defindex.nil? || defindex < 0
29
+ # ignore this item
30
+ else
31
+ items[name] = Item.new(name, @response['items'][name])
32
+ end
33
+ items
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,84 +1,12 @@
1
- module BackpackTF
2
-
3
- # ruby representations of a JSON response to
4
- # `IGetPrices`['response']
5
- class Price < Response
6
-
7
- INTERFACE = :IGetPrices
8
- @interface = INTERFACE
9
- @response = nil
10
- @items = nil
11
-
12
- ############################
13
- # CLASS METHODS
14
- ############################
15
-
16
- def self.response
17
- @response = superclass.responses[to_sym]
18
- end
19
-
20
- def self.items opt = nil
21
- if @items.nil?
22
- @items = generate_items
23
- else
24
- @items
25
- end
26
- end
27
-
28
- def self.generate_items
29
- @response[:items].inject({}) do |items, (name)|
30
- defindex = @response[:items][name]['defindex'][0]
31
-
32
- if defindex.nil? || defindex < 0
33
- items
34
- else
35
- items[name] = Item.new(name, @response[:items][name])
36
- items
37
- end
38
- end
39
- end
40
-
41
- def self.find_item_by_name item_name, opt = nil
42
-
43
- items if @items.nil?
44
-
45
- if @items[item_name].nil?
46
- raise KeyError, "item with the name #{item_name} was not found"
47
- else
48
- if opt.nil?
49
- @items[item_name]
50
- elsif @items[item_name].respond_to? opt
51
- @items[item_name].public_send(opt)
52
- else
53
- raise KeyError, "the item, #{item_name} does not have that attribute"
54
- end
55
- end
56
- end
57
-
58
- def self.random_item opt = nil
59
-
60
- items if @items.nil?
61
-
62
- case opt
63
- when :prices, :price
64
- @items[@items.keys.sample].prices
65
- else
66
- @items.keys.sample
67
- end
68
- end
69
-
70
- ############################
71
- # INSTANCE METHODS
72
- ############################
73
-
74
- def initialize
75
- msg = "This class is meant to receive the JSON response from the #{self.class.interface} interface."
76
- msg << "It holds a Hash array of prices of items, but not is meant to be instantiated."
77
- msg << "See the Item class if you are interested in an item."
78
- msg << "However, information on items should be stored in the @items property of #{self.class}."
79
- raise RuntimeError, msg
80
- end
1
+ require 'backpack_tf/price/interface'
2
+ require 'backpack_tf/price/response'
3
+ require 'backpack_tf/price/item'
4
+ require 'backpack_tf/price/item_price'
5
+ require 'backpack_tf/price/particle_effect'
81
6
 
7
+ module BackpackTF
8
+ # Ruby representations of a JSON response to IGetPrices
9
+ module Price
10
+ include Helpers
82
11
  end
83
-
84
12
  end
@@ -0,0 +1,22 @@
1
+ module BackpackTF
2
+ class PriceHistory
3
+ # Access the IGetPriceHistory interface
4
+ class Interface < BackpackTF::Interface
5
+ class << self
6
+ attr_reader :item, :quality, :tradable, :craftable, :priceindex
7
+ end
8
+
9
+ @name = :IGetPriceHistory
10
+ @version = 1
11
+
12
+ def self.defaults(options)
13
+ @item = options[:item] || nil
14
+ @quality = options[:quality] || nil
15
+ @tradable = options[:tradable] || nil
16
+ @craftable = options[:craftable] || nil
17
+ @priceindex = options[:priceindex] || nil
18
+ super(options)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module BackpackTF
2
+ class PriceHistory
3
+ # Process reponses from IGetPriceHistory
4
+ class Response < BackpackTF::Response
5
+ @response = nil
6
+ @history = []
7
+
8
+ def self.history
9
+ @history = @response['history'].map do |attr|
10
+ BackpackTF::PriceHistory.new(attr)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'backpack_tf/price_history/interface'
2
+ require 'backpack_tf/price_history/response'
3
+
4
+ module BackpackTF
5
+ # Ruby representations of a JSON response to IGetPriceHistory
6
+ class PriceHistory
7
+ include Helpers
8
+
9
+ attr_reader :value
10
+ attr_reader :value_high
11
+ attr_reader :currency
12
+ attr_reader :timestamp
13
+
14
+ # @param attr [Hash] Attributes for the price history object
15
+ # @return [PriceHistory] A new PriceHistory object.
16
+ def initialize(attr)
17
+ attr = hash_keys_to_sym(attr)
18
+
19
+ @value = attr[:value]
20
+ @value_high = attr[:value_high]
21
+ @currency = attr[:currency]
22
+ @timestamp = attr[:timestamp]
23
+ end
24
+ end
25
+ end
@@ -1,67 +1,20 @@
1
1
  module BackpackTF
2
+ # Base class for processing a response from a BackpackTF API
2
3
  class Response
3
-
4
- ############################
5
- # CLASS METHODS
6
- ############################
7
-
8
- @responses = {}
9
-
10
- def self.interface; @interface; end
11
-
12
- def self.to_sym
13
- self.name.to_sym
14
- end
15
-
16
- def self.responses key_val = nil
17
- unless key_val.nil?
18
- key_val = { key_val => nil } unless key_val.class == Hash
19
- key = key_val.keys.first
20
- val = key_val.values.first
21
-
22
- if val.nil?
23
- @responses[key]
24
- elsif key == :reset && val == :confirm
25
- @responses = {}
26
- else
27
- @responses[key] = hash_keys_to_sym(val)
28
- end
29
-
30
- end
31
-
32
- @responses
4
+ class << self
5
+ attr_accessor :response
33
6
  end
34
7
 
35
- def self.response
8
+ def self.success
9
+ @response['success']
36
10
  end
37
11
 
38
- # checks the data type of the keys of a Hash object
39
- # if the key is a String, then changes it to a Symbol
40
- # otherwise, leaves it as is
41
- def self.hash_keys_to_sym hash
42
- hash.each_pair.inject({}) do |new_hash, (key, val)|
43
- unless key.class == String
44
- new_hash[key] = val
45
- else
46
- new_hash[key.to_sym] = val
47
- end
48
- new_hash
49
- end
12
+ def self.message
13
+ @response['message']
50
14
  end
51
15
 
52
- ############################
53
- # PRIVATE INSTANCE METHODS
54
- ############################
55
- private
56
- def check_attr_keys attr
57
- raise TypeError, 'pass in a Hash object' unless attr.class == Hash
58
-
59
- unless attr.keys.all? { |k| k.class == String }
60
- raise TypeError, 'all keys must be String object'
61
- end
62
-
63
- self.class.hash_keys_to_sym(attr)
16
+ def self.current_time
17
+ @response['current_time']
64
18
  end
65
-
66
19
  end
67
20
  end
@@ -0,0 +1,9 @@
1
+ module BackpackTF
2
+ class SpecialItem
3
+ # Access the IGetSpecialItems interface
4
+ class Interface < BackpackTF::Interface
5
+ @name = :IGetSpecialItems
6
+ @version = 1
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module BackpackTF
2
+ class SpecialItem
3
+ # Process reponses from IGetSpecialItems
4
+ class Response < BackpackTF::Response
5
+ @response = nil
6
+ @items = {}
7
+
8
+ def self.items
9
+ @items = @response['items'].each_with_object({}) do |item, hash|
10
+ name = item['name']
11
+ hash[name] = BackpackTF::SpecialItem.new(name, item)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,23 +1,10 @@
1
- module BackpackTF
2
- class SpecialItem < Response
3
- INTERFACE = :IGetSpecialItems
4
- @interface = INTERFACE
5
- @response = nil
6
- @@items = {}
7
-
8
- def self.response
9
- @response = superclass.responses[to_sym]
10
- end
1
+ require 'backpack_tf/special_item/interface'
2
+ require 'backpack_tf/special_item/response'
11
3
 
12
- def self.items
13
- return @response if @response.nil?
14
- @@items = response[:items].inject({}) do |hash, item|
15
- #item = hash_keys_to_sym(item)
16
- name = item['name']
17
- hash[name] = new(name, item)
18
- hash
19
- end
20
- end
4
+ module BackpackTF
5
+ # Ruby representations of a JSON response to IGetSpecialItems
6
+ class SpecialItem
7
+ include Helpers
21
8
 
22
9
  attr_reader :name
23
10
  attr_reader :item_name
@@ -35,8 +22,11 @@ module BackpackTF
35
22
  attr_reader :image_url_large_orig
36
23
  attr_reader :appid
37
24
 
38
- def initialize name, attr
39
- attr = check_attr_keys(attr)
25
+ # @param name [String] Name of the SpecialItem.
26
+ # @param attr [Hash] Attributes.
27
+ # @return [SpecialItem] A new SpecialItem object.
28
+ def initialize(name, attr)
29
+ attr = hash_keys_to_sym(attr)
40
30
 
41
31
  @name = name
42
32
  @item_name = attr[:item_name]
@@ -0,0 +1,18 @@
1
+ module BackpackTF
2
+ class User
3
+ # Access the IGetUsers interface
4
+ class Interface < BackpackTF::Interface
5
+ class << self
6
+ attr_reader :steamids
7
+ end
8
+
9
+ @name = :IGetUsers
10
+ @version = 3
11
+
12
+ def self.defaults(options = {})
13
+ @steamids = options[:steamids] || nil
14
+ super(options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module BackpackTF
2
+ class User
3
+ # Process reponses from IGetUsers
4
+ class Response < BackpackTF::Response
5
+ @response = nil
6
+ @players = {}
7
+
8
+ def self.players
9
+ hash = response['players'].each_with_object({}) do |(id, attr), h|
10
+ h[id] = BackpackTF::User.new(attr)
11
+ end
12
+ @players = hash
13
+ end
14
+ end
15
+ end
16
+ end