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
@@ -0,0 +1,51 @@
1
+ {
2
+ "bump": 1453660379,
3
+ "intent": 1,
4
+ "currencies": {
5
+ "keys": 58
6
+ },
7
+ "buyout": 1,
8
+ "details": false,
9
+ "item": {
10
+ "id": 4224171036,
11
+ "original_id": 4114938468,
12
+ "defindex": 937,
13
+ "level": 85,
14
+ "quality": 5,
15
+ "inventory": 3221225475,
16
+ "quantity": 1,
17
+ "origin": 8,
18
+ "attributes": [
19
+ {
20
+ "defindex": 134,
21
+ "value": 1088421888,
22
+ "float_value": 7
23
+ },
24
+ {
25
+ "defindex": 746,
26
+ "value": 1065353216,
27
+ "float_value": 1
28
+ },
29
+ {
30
+ "defindex": 292,
31
+ "value": 1115684864,
32
+ "float_value": 64
33
+ },
34
+ {
35
+ "defindex": 388,
36
+ "value": 1115684864,
37
+ "float_value": 64
38
+ }
39
+ ]
40
+ },
41
+ "flags": {
42
+ "class": "pyro",
43
+ "slot": "misc",
44
+ "particle": 7,
45
+ "craft_material_type": "hat",
46
+ "priceindex": 7,
47
+ "sku": "440_Unusual_Wraith Wrap_1_1_7"
48
+ },
49
+ "created": 1445205322,
50
+ "id": "5624154aba8d884610a41c51"
51
+ }
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,20 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'backpack_tf'
2
5
  require 'webmock/rspec'
3
6
 
4
7
  def generate_fake_api_key
5
8
  hex_nums = %w(0 1 2 3 4 5 6 7 8 9 a b c d e f)
6
9
  key = ''
7
- 24.times{ |k| key << hex_nums.sample }
10
+ 24.times { key << hex_nums.sample }
8
11
  key
9
12
  end
10
13
 
11
14
  # taken from httparty's spec dir
12
15
  # https://github.com/jnunemaker/httparty/blob/master/spec/spec_helper.rb
13
16
  def file_fixture(filename)
14
- filename = File.join( File.dirname(__FILE__), "fixtures", "#{filename}")
17
+ filename = File.join(File.dirname(__FILE__), 'fixtures', filename.to_s)
15
18
  File.open(filename).read
16
19
  end
17
20
 
@@ -23,55 +26,12 @@ def stub_http_response_with(filename)
23
26
  response = Net::HTTPOK.new('1.1', 200, 'Content for you')
24
27
  allow(response).to receive(:body).and_return(data)
25
28
 
26
- http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', format: format)
27
- allow(http_request).to receive_message_chain(:http, :request).and_return(response)
28
-
29
- expect(HTTParty::Request).to receive(:new).and_return(http_request)
30
- end
31
-
32
- def make_fetch_sym
33
- opt = described_class.to_s
34
- ind_after_scope_operator = opt.index('::') + 2
35
- opt = opt[ind_after_scope_operator..-1]
36
- opt.downcase.to_sym
37
- end
38
-
39
- def mock_alias
40
-
41
- case described_class.to_s
42
-
43
- when BackpackTF::Price.to_s
44
- described_class.class_eval do
45
- class << self; attr_class_alias(:data_storage, :items); end
46
- end
47
- when BackpackTF::Currency.to_s
48
- described_class.class_eval do
49
- class << self; attr_class_alias :data_storage, :currencies; end
50
- end
51
- when BackpackTF::SpecialItem.to_s
52
- described_class.class_eval do
53
- class << self; attr_class_alias :data_storage, :items; end
54
- end
55
- when BackpackTF::User.to_s
56
- described_class.class_eval do
57
- class << self; attr_class_alias :data_storage, :players; end
58
- end
59
- when BackpackTF::UserListing.to_s
60
- described_class.class_eval do
61
- class << self; attr_class_alias :data_storage, :listings; end
62
- end
63
- else
64
- raise RuntimeError, "#{described_class} != described_class"
65
- end
66
-
67
- end
29
+ request = HTTParty::Request.new(Net::HTTP::Get,
30
+ 'http://localhost',
31
+ format: format)
32
+ allow(request).
33
+ to receive_message_chain(:http, :request).
34
+ and_return(response)
68
35
 
69
- # credit: http://stackoverflow.com/a/913453/2908123
70
- class Module
71
- def attr_class_alias(new_attr, original_attr)
72
- alias_method(new_attr, original_attr) if method_defined? original_attr
73
- new_writer = "#{new_attr}="
74
- original_writer = "#{original_attr}="
75
- alias_method(new_writer, original_writer) if method_defined? original_writer
76
- end
36
+ expect(HTTParty::Request).to receive(:new).and_return(request)
77
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backpack_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Espinoza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-09 00:00:00.000000000 Z
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -59,42 +59,86 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - ".gitignore"
62
+ - ".rspec"
63
+ - ".travis.yml"
62
64
  - Gemfile
63
- - TODO.md
65
+ - Gemfile.lock
66
+ - README.md
67
+ - Rakefile
64
68
  - backpack_tf.gemspec
65
69
  - lib/backpack_tf.rb
66
- - lib/backpack_tf/assets/attribute_controlled_attached_particles.json
70
+ - lib/backpack_tf/assets/particle_effects.json
67
71
  - lib/backpack_tf/client.rb
68
72
  - lib/backpack_tf/currency.rb
69
- - lib/backpack_tf/item.rb
70
- - lib/backpack_tf/item_price.rb
73
+ - lib/backpack_tf/currency/interface.rb
74
+ - lib/backpack_tf/currency/response.rb
75
+ - lib/backpack_tf/helpers.rb
76
+ - lib/backpack_tf/interface.rb
77
+ - lib/backpack_tf/market_price.rb
78
+ - lib/backpack_tf/market_price/interface.rb
79
+ - lib/backpack_tf/market_price/response.rb
71
80
  - lib/backpack_tf/price.rb
81
+ - lib/backpack_tf/price/interface.rb
82
+ - lib/backpack_tf/price/item.rb
83
+ - lib/backpack_tf/price/item_price.rb
84
+ - lib/backpack_tf/price/particle_effect.rb
85
+ - lib/backpack_tf/price/response.rb
86
+ - lib/backpack_tf/price_history.rb
87
+ - lib/backpack_tf/price_history/interface.rb
88
+ - lib/backpack_tf/price_history/response.rb
72
89
  - lib/backpack_tf/response.rb
73
90
  - lib/backpack_tf/special_item.rb
91
+ - lib/backpack_tf/special_item/interface.rb
92
+ - lib/backpack_tf/special_item/response.rb
74
93
  - lib/backpack_tf/user.rb
94
+ - lib/backpack_tf/user/interface.rb
95
+ - lib/backpack_tf/user/response.rb
75
96
  - lib/backpack_tf/user_listing.rb
97
+ - lib/backpack_tf/user_listing/interface.rb
98
+ - lib/backpack_tf/user_listing/response.rb
76
99
  - lib/backpack_tf/version.rb
77
- - readme.md
78
100
  - spec/backpack_tf/client_spec.rb
101
+ - spec/backpack_tf/currency/interface_spec.rb
102
+ - spec/backpack_tf/currency/response_spec.rb
79
103
  - spec/backpack_tf/currency_spec.rb
80
- - spec/backpack_tf/inherited_class_methods_spec.rb
81
- - spec/backpack_tf/item_price_spec.rb
82
- - spec/backpack_tf/item_spec.rb
83
- - spec/backpack_tf/price_spec.rb
104
+ - spec/backpack_tf/helpers_spec.rb
105
+ - spec/backpack_tf/interface_spec.rb
106
+ - spec/backpack_tf/market_price/interface_spec.rb
107
+ - spec/backpack_tf/market_price/response_spec.rb
108
+ - spec/backpack_tf/market_price_spec.rb
109
+ - spec/backpack_tf/price/interface_spec.rb
110
+ - spec/backpack_tf/price/item_price_spec.rb
111
+ - spec/backpack_tf/price/item_spec.rb
112
+ - spec/backpack_tf/price/particle_effect_spec.rb
113
+ - spec/backpack_tf/price/response_spec.rb
114
+ - spec/backpack_tf/price_history/interface_spec.rb
115
+ - spec/backpack_tf/price_history/response_spec.rb
116
+ - spec/backpack_tf/price_history_spec.rb
84
117
  - spec/backpack_tf/response_spec.rb
118
+ - spec/backpack_tf/special_item/interface_spec.rb
119
+ - spec/backpack_tf/special_item/response_spec.rb
85
120
  - spec/backpack_tf/special_item_spec.rb
121
+ - spec/backpack_tf/user/interface_spec.rb
122
+ - spec/backpack_tf/user/response_spec.rb
123
+ - spec/backpack_tf/user_listing/interface_spec.rb
124
+ - spec/backpack_tf/user_listing/response_spec.rb
86
125
  - spec/backpack_tf/user_listing_spec.rb
87
126
  - spec/backpack_tf/user_spec.rb
88
127
  - spec/fixtures/currencies.json
89
128
  - spec/fixtures/currencies_updated.json
90
129
  - spec/fixtures/item_crate.json
130
+ - spec/fixtures/item_price_typical.json
131
+ - spec/fixtures/item_price_unusual.json
91
132
  - spec/fixtures/item_typical.json
92
133
  - spec/fixtures/item_unusual.json
134
+ - spec/fixtures/item_with_dual_craftability_tradability.json
93
135
  - spec/fixtures/item_with_unconventional_structure.json
94
- - spec/fixtures/item_without_defindex.json
136
+ - spec/fixtures/market_prices.json
137
+ - spec/fixtures/price_history.json
95
138
  - spec/fixtures/prices.json
96
139
  - spec/fixtures/special_items.json
97
140
  - spec/fixtures/user_listing.json
141
+ - spec/fixtures/user_listing_individual.json
98
142
  - spec/fixtures/users.json
99
143
  - spec/spec_helper.rb
100
144
  homepage: https://github.com/NerdDiffer/backpack_tf
@@ -109,16 +153,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
153
  requirements:
110
154
  - - ">="
111
155
  - !ruby/object:Gem::Version
112
- version: 1.9.3
156
+ version: 2.0.0
113
157
  required_rubygems_version: !ruby/object:Gem::Requirement
114
158
  requirements:
115
- - - ">="
159
+ - - ">"
116
160
  - !ruby/object:Gem::Version
117
- version: '0'
161
+ version: 1.3.1
118
162
  requirements: []
119
163
  rubyforge_project:
120
- rubygems_version: 2.4.5
164
+ rubygems_version: 2.4.5.1
121
165
  signing_key:
122
166
  specification_version: 4
123
167
  summary: a wrapper for the backpack.tf API
124
168
  test_files: []
169
+ has_rdoc:
data/TODO.md DELETED
@@ -1,15 +0,0 @@
1
- ##TODO list
2
-
3
- #####testing:
4
- * a mock backpack.tf service
5
- * stubs & archived cache data
6
-
7
- #####documentation:
8
- * better documentation on all classes, modules, methods, attributes, etc
9
- * support for YARD or RDOC
10
-
11
- #####caching:
12
- * options to cache data and force a refresh
13
-
14
- #####formats:
15
- * the API outputs 3 formats: JSON (default), JSONP and VDF. Currently, the gem supports JSON input only. Support for JSONP & VDF is needed.
@@ -1,84 +0,0 @@
1
- module BackpackTF
2
-
3
- class Item
4
- ###########################
5
- # Instance Methods
6
- ###########################
7
-
8
- # @return [String] the name of item
9
- attr_reader :item_name
10
- # @return [Fixnum] the index to which you can link this item to Team Fortress 2's Item Schema
11
- attr_reader :defindex
12
- # @return [Hash<Fixnum, ItemPrice>] a hash object
13
- attr_reader :prices
14
-
15
- def initialize item_name, attr
16
- @item_name = item_name
17
-
18
- unless attr.class == Hash
19
- attr = JSON.parse(attr)
20
- end
21
-
22
- @defindex = process_defindex(attr['defindex'])
23
- @prices = generate_prices_hash(attr)
24
- end
25
-
26
- def process_defindex arr
27
- return nil if arr.length == 0
28
- return arr[0] if arr.length == 1
29
- arr
30
- end
31
-
32
- def generate_prices_hash input_hash
33
-
34
- raise TypeError, 'expecting a Hash object' unless input_hash.class == Hash
35
- unless input_hash.has_key? 'prices'
36
- msg = "input_hash must be at the one level above the point where 'prices' is a key in the JSON hash"
37
- raise KeyError, msg
38
- end
39
-
40
- prices = input_hash['prices']
41
-
42
- prices.inject({}) do |hash, (key, val)|
43
-
44
- quality = BackpackTF::ItemPrice.qualities[key.to_i]
45
- new_key = [quality.to_s]
46
-
47
- tradability = val.keys.first
48
- new_key << tradability
49
-
50
- craftability = prices[key][tradability].keys.first
51
- new_key << craftability
52
-
53
- new_key = new_key.join(ItemPrice::KEYNAME_DELIMITER)
54
-
55
- prefix = prices[key][tradability][craftability]
56
-
57
- if (prefix.length <= 1)
58
- item_prices = prefix[0]
59
- # patch for oddly-structured items, ie: Aqua Summer 2013 Cooler
60
- item_prices = prefix.values.first if item_prices.nil?
61
-
62
- item_price_obj = ItemPrice.new(new_key, item_prices)
63
- hash[new_key] = item_price_obj
64
- elsif key == '5' # item with 'Unusual' quality
65
- prefix.keys.each do |prefix_key|
66
- item_prices = prefix[prefix_key]
67
- item_price_obj = ItemPrice.new(new_key, item_prices, prefix_key)
68
- hash[item_price_obj.effect] = item_price_obj
69
- end
70
- else # a Crate
71
- prefix.keys.each do |prefix_key|
72
- temp_key = "#{new_key}_##{prefix_key.to_i}"
73
- item_prices = prefix[prefix_key]
74
- item_price_obj = ItemPrice.new(temp_key, item_prices, prefix_key)
75
- hash[temp_key] = item_price_obj
76
- end
77
- end
78
- hash
79
- end
80
-
81
- end
82
-
83
- end
84
- end
@@ -1,172 +0,0 @@
1
- module BackpackTF
2
-
3
- class ItemPrice
4
-
5
- KEYNAME_DELIMITER = '_'
6
- PARTICLE_EFFECTS_KEY = 'attribute_controlled_attached_particles'
7
- PARTICLE_EFFECTS_FILE = "./lib/backpack_tf/assets/#{PARTICLE_EFFECTS_KEY}.json"
8
-
9
- ###########################
10
- # Class Methods
11
- ###########################
12
-
13
- # mapping official API quality integers to quality names
14
- # https://wiki.teamfortress.com/wiki/WebAPI/GetSchema#Result_Data
15
- @@qualities = [
16
- :Normal,
17
- :Genuine,
18
- nil,
19
- :Vintage,
20
- nil,
21
- :Unusual,
22
- :Unique,
23
- :Community,
24
- :Valve,
25
- :"Self-Made",
26
- nil,
27
- :Strange,
28
- nil,
29
- :Haunted,
30
- :"Collector's"
31
- ]
32
-
33
- @@tradabilities = [:Tradable, :'Non-Tradable']
34
- @@craftabilities = [:Craftable, :'Non-Craftable']
35
- @@required_keys = ['currency', 'value', 'last_update', 'difference']
36
-
37
- def self.qualities; @@qualities; end
38
- def self.required_keys; @@required_keys; end
39
-
40
- def self.quality_name_to_index q
41
- @@qualities.index(q.to_sym) unless q.nil?
42
- end
43
-
44
- def self.hash_particle_effects
45
-
46
- file = File.open(PARTICLE_EFFECTS_FILE).read
47
- effects_arr = JSON.parse(file)[PARTICLE_EFFECTS_KEY]
48
-
49
- effects_arr.inject({}) do |hash, pe|
50
- id = pe['id']
51
- name = pe['name']
52
- hash[id] = name
53
- hash
54
- end
55
-
56
- end
57
-
58
- @@particle_effects = self.hash_particle_effects
59
- def self.particle_effects; @@particle_effects; end
60
-
61
- def self.ins_sp str
62
- str = str.split('')
63
- new_str = ''
64
- str.each_with_index do |c, i|
65
- if i == 0
66
- new_str += c
67
- else
68
- unless c == c.upcase && str[i-1] == str[i-1].upcase
69
- new_str += c
70
- else
71
- new_str += (' ' + c)
72
- end
73
- end
74
- end
75
- new_str
76
- end
77
-
78
- ###########################
79
- # Instance Methods
80
- ###########################
81
-
82
- # @return [String] the quality of the item being priced, converted to String
83
- attr_reader :quality
84
- # @return [Symbol] either :Tradable or :'Non-Tradable'
85
- attr_reader :tradability
86
- # @return [Symbol] either :Craftable or :'Non-Craftable'
87
- attr_reader :craftability
88
- # @return [NilClass or Fixnum] Primarily used to signify crate series or unusual effect. Otherwise, this is 0
89
- attr_reader :priceindex
90
- # @return [Symbol] The currency that the item's price is based on
91
- attr_reader :currency
92
- # @return [Float] The value of the item in said currency
93
- attr_reader :value
94
- # @return [Float] The item's upper value measured in said currency. only set if the item has a price range
95
- attr_reader :value_high
96
- # @return [Float] The item's value in the lowest currency without rounding. If raw is set to 2, this is the lower value if a high value exists. Otherwise, this is the average between the high and low value. Requires raw to be enabled.
97
- attr_reader :value_raw
98
- # @return [Float] The item's value in the lowest currency without rounding. Reques raw to be enabled and set to 2
99
- attr_reader :value_high_raw
100
- # @return [Fixnum] A timestamp of when the price was last updated
101
- attr_reader :last_update
102
- # @return [Fixnum] A relative difference between the former price and the current price. If 0, assume new price.
103
- attr_reader :difference
104
- # @return [String] Result of @@particle_effects[@priceindex]
105
- attr_reader :effect
106
-
107
- def initialize key, attr, priceindex = nil
108
- attr = JSON.parse(attr) unless attr.class == Hash
109
-
110
- key = key.split(KEYNAME_DELIMITER)
111
- key = process_key(key)
112
-
113
- validate_attributes(attr)
114
-
115
- @quality = key[0]
116
- @tradability = key[1]
117
- @craftability = key[2]
118
- @currency = attr['currency'].to_sym
119
- @value = attr['value']
120
- @value_high = attr['value_high']
121
- @value_raw = attr['value_raw']
122
- @value_high_raw = attr['value_high_raw']
123
- @last_update = attr['last_update']
124
- @difference = attr['difference']
125
- @priceindex = priceindex
126
- @effect = self.class.particle_effects[priceindex.to_i]
127
- end
128
-
129
- private
130
- # requires the key to an Array with length of 3 or more
131
- # converts each element to a Symbol object
132
- # The 3 bits of info are subject to a NameError if any one of them is invalid
133
- # @return [Array] an Array of Symbol objects
134
- # @raises NameError, ArgumentError
135
- def process_key key
136
-
137
- unless key.length >= 3
138
- raise ArgumentError, "This key must have a length of 3 or greater"
139
- end
140
-
141
- key.map! { |bit| bit.to_sym }
142
-
143
- unless @@qualities.include? key[0]
144
- raise NameError, 'Must include a valid Quality'
145
- end
146
- unless @@tradabilities.include? key[1]
147
- raise NameError, 'Must include a valid Tradability'
148
- end
149
- unless @@craftabilities.include? key[2]
150
- raise NameError, 'Must include a valid Craftability'
151
- end
152
-
153
- key
154
- end
155
-
156
- def validate_attributes attributes
157
-
158
- raise TypeError unless attributes.class == Hash
159
-
160
- unless @@required_keys.all? { |k| attributes.keys.member? k }
161
- msg = "The passed-in hash is required to have at least these 4 keys: "
162
- msg += "#{self.class.required_keys.join(', ')}"
163
- raise KeyError, msg
164
- end
165
-
166
- attributes
167
-
168
- end
169
-
170
- end
171
-
172
- end
data/readme.md DELETED
@@ -1,96 +0,0 @@
1
- #backpack_tf
2
- Backpack.tf is a website for the in-game economies of Team Fortress 2 and Dota 2. This gem is a wrapper for the backpack.tf [API](http://backpack.tf/api). The goal is to capture the results and turn them into Ruby objects for use in your application.
3
-
4
- It is in the early stages of development. See the [TODO](TODO.md) list if you are interested in contributing.
5
-
6
- ###Installation
7
- #####install any dependencies
8
- `bundle install`
9
-
10
- ######Install it as a gem:
11
- `gem install backpack_tf`
12
-
13
- ######Or add it to your project's Gemfile:
14
- `gem 'backpack_tf'`
15
-
16
- ###Usage
17
- * [Register an API key](http://backpack.tf/api). You'll need to log in with your Steam account if you haven't already done so.
18
- * Assign your key to an environment variable through your terminal:
19
- `export BPTF_API_KEY='SECRET_KEY'`
20
- * Load the gem into your project:
21
- `require 'backpack_tf'`
22
-
23
- ###Examples
24
-
25
- ``` ruby
26
- ##### create a new Client object
27
- bp = BackpackTF::Client.new
28
-
29
- ##### fetch some data
30
- fetched_prices = bp.fetch(:prices, { :compress => 1 })
31
- fetched_currencies = bp.fetch(:currencies, { :compress => 1 })
32
- fetched_special_items = bp.fetch(:special_items, { :compress => 1})
33
- fetched_users = bp.fetch(:users, { :steamids => [64_bit_steam_id_of_one_user, 64_bit_steam_id_of_another_user] })
34
- fetched_listings = bp.fetch(:user_listings, { :steamid => 64_bit_steam_id_of_one_user })
35
-
36
- ##### update a class with the data
37
- # *note*: you should send a message from your Client object to the class before
38
- # using any of those class' methods.
39
- # This does not apply to the `Item` class and the `ItemPrice` class.
40
- # Those are updated through the `Price` class.
41
-
42
- bp.update(BackpackTF::Price, fetched_prices)
43
- bp.update(BackpackTF::Currency, fetched_currencies)
44
- bp.update(BackpackTF::SpecialItem, fetched_special_items)
45
- bp.update(BackpackTF::User, fetched_users)
46
- bp.update(BackpackTF::UserListing, fetched_listings)
47
-
48
- ##### look at prices of a random item
49
- random_key = BackpackTF::Price.items.sample
50
- BackpackTF::Price.items[random_key]
51
-
52
- ```
53
-
54
- ##Interfaces
55
-
56
- ####IGetPrices
57
- * Get pricing data for all priced items
58
- * [official doc](http://backpack.tf/api/prices)
59
-
60
- API responses from this interface are captured in the `Price` class. The `Price` class is not meant to be instantiated. One of the class attributes is `@@items`, a Hash object. Information on any particular item, ie: 'Eviction Notice', is captured in an instance of the `Item` class. Furthermore, there may be several prices for the same item, ie: an Eviction Notice with the Unique quality has a different price than a Eviction Notice with a Strange quality. Each price is an instance of the `ItemPrice` class, and is stored in the `@prices` hash of that item.
61
-
62
- ######a visual
63
- * `Price` class
64
- * `@@items` hash of `Price` class.
65
- * `Item` object (ie: 'Beast From Below')
66
- * `Item` object (ie: 'Taunt: Rock, Paper Scissors')
67
- * `Item` object (ie: 'Eviction Notice')
68
- * `@prices` hash of an `Item` object
69
- * `ItemPrice` object (ie: price for Unique Eviction Notice)
70
- * `ItemPrice` object (ie: price for Collector's Eviction Notice)
71
- * `ItemPrice` object (ie: price for Strange Eviction Notice)
72
-
73
- ####IGetCurrencies
74
- * Get internal currency data for a given game
75
- * [official doc](http://backpack.tf/api/currencies)
76
-
77
- API responses from this interface are captured in the `Currency` class. Similar the `Price` class, it has a set of class methods, and attributes to describe the API response. Unlike, the `Price` class, this one can be instantiated. There are currently 4 currencies available through the API. Each one is an instance of `Currency` and is held in the `@@currencies` hash of the `Currency` class.
78
-
79
- ####IGetSpecialItems
80
- * Get internal backpack.tf item placeholders for a given game.
81
- * [official doc](http://backpack.tf/api/special)
82
-
83
- This is for items that only exist on backpack.tf. They are not real game items, but you will see them returned in a call to `IGetPrices`. The class for this interface is `SpecialItem`.
84
-
85
- ####IGetUsers
86
- * Get profile info for a list of 64-bit Steam IDs.
87
- * Does not require an API key
88
- * [official doc](http://backpack.tf/api/users)
89
-
90
- Get some basic information for a list of backpack.tf users. It's basically the info that you'd see on their profile page. The response for this interface is captured in the `User` class. You can request several users at once by sending them in an array.
91
-
92
- ####IGetUserListings
93
- * Get classified listings for a given user
94
- * [official doc](http://backpack.tf/api/classifieds)
95
-
96
- Request all classified listings for one user. You must pass in the 64-bit `steamid`. The response is captured in the `UserListing` class.