backpack_tf 0.5.0 → 0.8.0
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/lib/backpack_tf/client.rb +9 -12
- data/lib/backpack_tf/{currencies.rb → currency.rb} +1 -1
- data/lib/backpack_tf/item.rb +1 -27
- data/lib/backpack_tf/item_price.rb +35 -29
- data/lib/backpack_tf/price.rb +97 -0
- data/lib/backpack_tf/response.rb +2 -2
- data/lib/backpack_tf/special_item.rb +58 -0
- data/lib/backpack_tf/user.rb +54 -0
- data/lib/backpack_tf/user_listing.rb +60 -0
- data/lib/backpack_tf/version.rb +1 -1
- data/lib/backpack_tf.rb +5 -3
- data/readme.md +53 -13
- data/spec/backpack_tf/client_spec.rb +19 -19
- data/spec/backpack_tf/{currencies_spec.rb → currency_spec.rb} +23 -23
- data/spec/backpack_tf/price_spec.rb +182 -0
- data/spec/backpack_tf/special_item_spec.rb +101 -0
- data/spec/backpack_tf/user_listing_spec.rb +92 -0
- data/spec/backpack_tf/user_spec.rb +94 -0
- data/spec/fixtures/special_items.json +1 -0
- data/spec/fixtures/user_listing.json +1 -0
- data/spec/fixtures/users.json +1 -0
- metadata +14 -7
- data/lib/backpack_tf/finder.rb +0 -87
- data/lib/backpack_tf/prices.rb +0 -49
- data/spec/backpack_tf/finder_spec.rb +0 -30
- data/spec/backpack_tf/prices_spec.rb +0 -130
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcb589dbd6d876a5691b061847e9a3a349a034c3
|
4
|
+
data.tar.gz: 6418bd7b7a7c3b6f4fc55577c1ef414208ce3ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d18da71c8c9504088b6a3a53956272430b512b72761143ad39669e7000054282f0c698eb455861ff3534e9a3b5c7c1563e27a7d81fe859ace62635025ba014
|
7
|
+
data.tar.gz: a0bdd6b0b0394126d92cf5f55cab2b7f70f19f88afe6d3de41101e7990ddd2c4c2d4fc42ff81c52d4d044e536e5d749dcb9e8ef350ea23d6c43771eb4b305614
|
data/lib/backpack_tf/client.rb
CHANGED
@@ -36,22 +36,19 @@ module BackpackTF
|
|
36
36
|
case action
|
37
37
|
when :get_prices, :prices
|
38
38
|
version = 4
|
39
|
-
interface_url = "/#{
|
39
|
+
interface_url = "/#{Price.interface}/v#{version}/?"
|
40
40
|
when :get_currencies, :currencies
|
41
41
|
version = 1
|
42
|
-
interface_url = "/#{
|
42
|
+
interface_url = "/#{Currency.interface}/v#{version}/?"
|
43
43
|
when :get_special_items, :special_items
|
44
|
-
|
45
|
-
|
46
|
-
#interface_url = "/IGetSpecialItems/v#{version}/?"
|
44
|
+
version = 1
|
45
|
+
interface_url = "/#{SpecialItem.interface}/v#{version}/?"
|
47
46
|
when :get_users, :users
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#version = 1
|
54
|
-
#interface_url = "/IGetUserListings/v#{version}/?"
|
47
|
+
version = 3
|
48
|
+
interface_url = "/#{User.interface}/v#{version}/?"
|
49
|
+
when :get_user_listings, :user_listing, :user_listings
|
50
|
+
version = 1
|
51
|
+
interface_url = "/#{UserListing.interface}/v#{version}/?"
|
55
52
|
else
|
56
53
|
raise ArgumentError, 'pass in valid action as a Symbol object'
|
57
54
|
end
|
data/lib/backpack_tf/item.rb
CHANGED
@@ -1,39 +1,13 @@
|
|
1
1
|
module BackpackTF
|
2
2
|
|
3
3
|
class Item
|
4
|
-
|
5
|
-
include BackpackTF::Finder
|
6
|
-
|
7
|
-
###########################
|
8
|
-
# Class Methods
|
9
|
-
###########################
|
10
|
-
|
11
|
-
#def self.generate_price_keys item_hash
|
12
|
-
# raise TypeError unless item_hash.class == Hash
|
13
|
-
# prices = item_hash['prices']
|
14
|
-
|
15
|
-
# prices.each_pair.inject([]) do |gen_keys, (key, val)|
|
16
|
-
# quality = BackpackTF::ItemPrice.qualities[key.to_i]
|
17
|
-
# new_key = [quality.to_s]
|
18
|
-
|
19
|
-
# tradability = val.keys.first
|
20
|
-
# new_key << tradability
|
21
|
-
|
22
|
-
# craftability = prices[key][tradability].keys.first
|
23
|
-
# new_key << craftability
|
24
|
-
|
25
|
-
# gen_keys << new_key.join('_')
|
26
|
-
# end
|
27
|
-
|
28
|
-
#end
|
29
|
-
|
30
4
|
###########################
|
31
5
|
# Instance Methods
|
32
6
|
###########################
|
33
7
|
|
34
8
|
# @return [String] the name of item
|
35
9
|
attr_reader :item_name
|
36
|
-
# @return [Fixnum] the index
|
10
|
+
# @return [Fixnum] the index to which you can link this item to Team Fortress 2's Item Schema
|
37
11
|
attr_reader :defindex
|
38
12
|
# @return [Hash<Fixnum, ItemPrice>] a hash object
|
39
13
|
attr_reader :prices
|
@@ -2,7 +2,41 @@ module BackpackTF
|
|
2
2
|
|
3
3
|
class ItemPrice
|
4
4
|
|
5
|
-
|
5
|
+
###########################
|
6
|
+
# Class Methods
|
7
|
+
###########################
|
8
|
+
|
9
|
+
@@required_keys = ['currency', 'value', 'last_update', 'difference']
|
10
|
+
def self.required_keys; @@required_keys; end
|
11
|
+
|
12
|
+
# mapping official API quality integers to quality names
|
13
|
+
# https://wiki.teamfortress.com/wiki/WebAPI/GetSchema#Result_Data
|
14
|
+
@@qualities = [
|
15
|
+
:Normal,
|
16
|
+
:Genuine,
|
17
|
+
nil,
|
18
|
+
:Vintage,
|
19
|
+
nil,
|
20
|
+
:Unusual,
|
21
|
+
:Unique,
|
22
|
+
:Community,
|
23
|
+
:Valve,
|
24
|
+
:"Self-Made",
|
25
|
+
nil,
|
26
|
+
:Strange,
|
27
|
+
nil,
|
28
|
+
:Haunted,
|
29
|
+
:"Collector's"
|
30
|
+
]
|
31
|
+
|
32
|
+
def self.qualities; @@qualities; end
|
33
|
+
|
34
|
+
@@tradabilities = [:Tradable, :'Non-Tradable']
|
35
|
+
@@craftabilities = [:Craftable, :'Non-Craftable']
|
36
|
+
|
37
|
+
###########################
|
38
|
+
# Instance Methods
|
39
|
+
###########################
|
6
40
|
|
7
41
|
# @return [String] the quality of the item being priced, converted to String
|
8
42
|
attr_reader :quality
|
@@ -49,34 +83,6 @@ module BackpackTF
|
|
49
83
|
@difference = attr['difference']
|
50
84
|
end
|
51
85
|
|
52
|
-
@@required_keys = %w(currency value last_update difference)
|
53
|
-
def self.required_keys; @@required_keys; end
|
54
|
-
|
55
|
-
# mapping official API quality integers to quality names
|
56
|
-
# https://wiki.teamfortress.com/wiki/WebAPI/GetSchema#Result_Data
|
57
|
-
@@qualities = [
|
58
|
-
:Normal,
|
59
|
-
:Genuine,
|
60
|
-
nil,
|
61
|
-
:Vintage,
|
62
|
-
nil,
|
63
|
-
:Unusual,
|
64
|
-
:Unique,
|
65
|
-
:Community,
|
66
|
-
:Valve,
|
67
|
-
:"Self-Made",
|
68
|
-
nil,
|
69
|
-
:Strange,
|
70
|
-
nil,
|
71
|
-
:Haunted,
|
72
|
-
:"Collector's"
|
73
|
-
]
|
74
|
-
|
75
|
-
def self.qualities; @@qualities; end
|
76
|
-
|
77
|
-
@@tradabilities = [:Tradable, :'Non-Tradable']
|
78
|
-
@@craftabilities = [:Craftable, :'Non-Craftable']
|
79
|
-
|
80
86
|
end
|
81
87
|
|
82
88
|
end
|
@@ -0,0 +1,97 @@
|
|
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
|
21
|
+
if @items.nil?
|
22
|
+
generate_items
|
23
|
+
else
|
24
|
+
@items
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.generate_items
|
29
|
+
@items = @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
|
+
if @items[item_name].nil?
|
43
|
+
raise KeyError, "item with the name #{item_name} was not found"
|
44
|
+
else
|
45
|
+
if opt.nil?
|
46
|
+
@items[item_name]
|
47
|
+
elsif @items[item_name].respond_to? opt
|
48
|
+
@items[item_name].public_send(opt)
|
49
|
+
else
|
50
|
+
raise KeyError, "the item, #{item_name} does not have that attribute"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.random_item opt = nil
|
56
|
+
case opt
|
57
|
+
when :prices, :price
|
58
|
+
@items[@items.keys.sample].prices
|
59
|
+
else
|
60
|
+
@items.keys.sample
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.generate_price_keys item_hash
|
65
|
+
raise TypeError unless item_hash.class == Hash
|
66
|
+
prices = item_hash['prices']
|
67
|
+
|
68
|
+
prices.each_pair.inject([]) do |gen_keys, (key, val)|
|
69
|
+
quality = BackpackTF::ItemPrice.qualities[key.to_i]
|
70
|
+
new_key = [quality.to_s]
|
71
|
+
|
72
|
+
tradability = val.keys.first
|
73
|
+
new_key << tradability
|
74
|
+
|
75
|
+
craftability = prices[key][tradability].keys.first
|
76
|
+
new_key << craftability
|
77
|
+
|
78
|
+
gen_keys << new_key.join('_')
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
############################
|
84
|
+
# INSTANCE METHODS
|
85
|
+
############################
|
86
|
+
|
87
|
+
def initialize
|
88
|
+
msg = "This class is meant to receive the JSON response from the #{self.class.interface} interface."
|
89
|
+
msg << "It holds a Hash array of prices of items, but not is meant to be instantiated."
|
90
|
+
msg << "See the Item class if you are interested in an item."
|
91
|
+
msg << "However, information on items should be stored in the @items property of #{self.class}."
|
92
|
+
raise RuntimeError, msg
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/lib/backpack_tf/response.rb
CHANGED
@@ -5,14 +5,14 @@ module BackpackTF
|
|
5
5
|
# CLASS METHODS
|
6
6
|
############################
|
7
7
|
|
8
|
+
@responses = {}
|
9
|
+
|
8
10
|
def self.interface; @interface; end
|
9
11
|
|
10
12
|
def self.to_sym
|
11
13
|
self.name.to_sym
|
12
14
|
end
|
13
15
|
|
14
|
-
@responses = {}
|
15
|
-
|
16
16
|
def self.responses key_val = nil
|
17
17
|
unless key_val.nil?
|
18
18
|
key_val = { key_val => nil } unless key_val.class == Hash
|
@@ -0,0 +1,58 @@
|
|
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
|
11
|
+
|
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
|
21
|
+
|
22
|
+
attr_reader :name
|
23
|
+
attr_reader :item_name
|
24
|
+
attr_reader :defindex
|
25
|
+
attr_reader :item_class
|
26
|
+
attr_reader :item_type_name
|
27
|
+
attr_reader :item_description
|
28
|
+
attr_reader :proper_name
|
29
|
+
attr_reader :item_quality
|
30
|
+
attr_reader :min_ilevel
|
31
|
+
attr_reader :max_ilevel
|
32
|
+
attr_reader :image_url
|
33
|
+
attr_reader :image_url_large
|
34
|
+
attr_reader :image_url_orig
|
35
|
+
attr_reader :image_url_large_orig
|
36
|
+
attr_reader :appid
|
37
|
+
|
38
|
+
def initialize name, attr
|
39
|
+
attr = check_attr_keys(attr)
|
40
|
+
|
41
|
+
@name = name
|
42
|
+
@item_name = attr[:item_name]
|
43
|
+
@defindex = attr[:defindex]
|
44
|
+
@item_class = attr[:item_class]
|
45
|
+
@item_type_name = attr[:item_type_name]
|
46
|
+
@item_description = attr[:item_description]
|
47
|
+
@proper_name = attr[:proper_name]
|
48
|
+
@item_quality = attr[:item_quality]
|
49
|
+
@min_ilevel = attr[:min_ilevel]
|
50
|
+
@max_ilevel = attr[:max_ilevel]
|
51
|
+
@image_url = attr[:image_url]
|
52
|
+
@image_url_large = attr[:image_url_large]
|
53
|
+
@image_url_orig = attr[:image_url_orig]
|
54
|
+
@image_url_large_orig = attr[:image_url_large_orig]
|
55
|
+
@appid = attr[:appid]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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
|
11
|
+
|
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
|
19
|
+
|
20
|
+
attr_reader :steamid
|
21
|
+
attr_reader :success
|
22
|
+
attr_reader :backpack_value
|
23
|
+
attr_reader :backpack_update
|
24
|
+
attr_reader :name
|
25
|
+
attr_reader :backpack_tf_reputation
|
26
|
+
attr_reader :backpack_tf_group
|
27
|
+
attr_reader :backpack_tf_banned
|
28
|
+
attr_reader :backpack_tf_trust
|
29
|
+
attr_reader :steamrep_scammer
|
30
|
+
attr_reader :ban_economy
|
31
|
+
attr_reader :ban_community
|
32
|
+
attr_reader :ban_vac
|
33
|
+
attr_reader :notifications
|
34
|
+
|
35
|
+
def initialize attr
|
36
|
+
attr = check_attr_keys(attr)
|
37
|
+
|
38
|
+
@steamid = attr[:steamid]
|
39
|
+
@success = attr[:success]
|
40
|
+
@backpack_value = attr[:backpack_value]
|
41
|
+
@backpack_update = attr[:backpack_update]
|
42
|
+
@name = attr[:name]
|
43
|
+
@backpack_tf_reputation = attr[:backpack_tf_reputation]
|
44
|
+
@backpack_tf_group = attr[:backpack_tf_group]
|
45
|
+
@backpack_tf_banned = attr[:backpack_tf_banned]
|
46
|
+
@backpack_tf_trust = attr[:backpack_tf_trust]
|
47
|
+
@steamrep_scammer = attr[:steamrep_scammer]
|
48
|
+
@ban_economy = attr[:ban_economy]
|
49
|
+
@ban_community = attr[:ban_community]
|
50
|
+
@ban_vac = attr[:ban_vac]
|
51
|
+
@notifications = attr[:notifications]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module BackpackTF
|
2
|
+
class UserListing < Response
|
3
|
+
|
4
|
+
INTERFACE = :IGetUserListings
|
5
|
+
|
6
|
+
@interface = INTERFACE
|
7
|
+
@response = nil
|
8
|
+
@@listings = []
|
9
|
+
|
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
|
23
|
+
|
24
|
+
attr_reader :id
|
25
|
+
attr_reader :bump
|
26
|
+
attr_reader :created
|
27
|
+
attr_reader :currencies
|
28
|
+
attr_reader :item
|
29
|
+
attr_reader :details
|
30
|
+
attr_reader :meta
|
31
|
+
attr_reader :buyout
|
32
|
+
|
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]
|
44
|
+
end
|
45
|
+
|
46
|
+
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
|
51
|
+
|
52
|
+
item_attributes = attr[key].map do |set_of_attr|
|
53
|
+
self.class.hash_keys_to_sym(set_of_attr)
|
54
|
+
end
|
55
|
+
attr[key] = item_attributes
|
56
|
+
|
57
|
+
self.class.hash_keys_to_sym(attr)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|