tcg-player-sdk 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tcg-player-sdk/product_price_list.rb +23 -16
- data/lib/tcg-player-sdk/tcg_player_sdk.rb +26 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f6eeb012e245a03c621cfbb4eb55882bed72fd12fd6f19e5aeaff128bf4b158
|
4
|
+
data.tar.gz: 5584cb03b502ad8450de6afe6e4517313acde7dc2259b8d0eac51c1df6bff061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76338f3a710643a18677707569fbc84992e022d82f6bed3b0e9ebbb57b1e0543eda8a6866f0ca682396029e56dc7cdf65c15df8bf3f180fbe29bd594a681cd8e
|
7
|
+
data.tar.gz: 572e74efdc7619649ec6ce3201e3405be8c87f7c72f57ab7e088615dd11456cdde860fc62af9570075de274b0aaf5f80e6dbe1f438d6416450e5f2082f95fe82
|
@@ -1,18 +1,7 @@
|
|
1
1
|
class TCGPlayerSDK::ProductPriceList < TCGPlayerSDK::ResponseStruct
|
2
2
|
|
3
|
-
##
|
4
|
-
# Group prices by product ID. This will set
|
5
|
-
# prices to an empty hash if there was an error. Check response.errors for details about any errors.
|
6
|
-
#
|
7
|
-
# @param _response[TCGPlayerSDK::ResponseStruct] the result of calling TCGPlayerAPI#product_pricing
|
8
3
|
def initialize(hash = {})
|
9
4
|
super
|
10
|
-
|
11
|
-
if(self.success && self.results)
|
12
|
-
@prices = self.results.map{|r| TCGPlayerSDK::ProductPrice.new(r)}.group_by{|r| r.productId}
|
13
|
-
else
|
14
|
-
@prices = {}
|
15
|
-
end
|
16
5
|
end
|
17
6
|
|
18
7
|
##
|
@@ -42,6 +31,12 @@ class TCGPlayerSDK::ProductPriceList < TCGPlayerSDK::ResponseStruct
|
|
42
31
|
#
|
43
32
|
# @return [Hash<Integer, Array<TCGPlayerSDK::ProductPrice>>]
|
44
33
|
def prices
|
34
|
+
if(self.success && self.results)
|
35
|
+
@prices ||= self.results.map{|r| TCGPlayerSDK::ProductPrice.new(r)}.group_by{|r| r.productId}
|
36
|
+
else
|
37
|
+
@prices = {}
|
38
|
+
end
|
39
|
+
|
45
40
|
@prices
|
46
41
|
end
|
47
42
|
|
@@ -50,13 +45,15 @@ class TCGPlayerSDK::ProductPriceList < TCGPlayerSDK::ResponseStruct
|
|
50
45
|
#
|
51
46
|
# @return [Hash<Integer, Array<TCGPlayerSDK::ProductPrice>>]
|
52
47
|
def valid_prices
|
53
|
-
valid_prices
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
if(@valid_prices.nil?)
|
49
|
+
@valid_prices = {}
|
50
|
+
@prices.each do |id, prl|
|
51
|
+
@valid_prices[id] ||= []
|
52
|
+
@valid_prices[id] = prl.select{|pr| pr.has_valid_prices?}
|
53
|
+
end
|
57
54
|
end
|
58
55
|
|
59
|
-
return valid_prices
|
56
|
+
return @valid_prices
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
@@ -80,4 +77,14 @@ class TCGPlayerSDK::ProductPrice < TCGPlayerSDK::ResponseStruct
|
|
80
77
|
def has_valid_prices?
|
81
78
|
return !(lowPrice.nil? && midPrice.nil? && highPrice.nil? && directLowPrice.nil? && marketPrice.nil?)
|
82
79
|
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Returns "price points" described by this price object. i.e. "midPrice" and "highPrice". These are also accessors,
|
83
|
+
# so access away
|
84
|
+
# price.points.each{|pp| puts price.send(pp)}
|
85
|
+
#
|
86
|
+
# @return Array<Symbol>
|
87
|
+
def points
|
88
|
+
self.keys.select{|k| k.to_s =~ /Price/i}
|
89
|
+
end
|
83
90
|
end
|
@@ -155,18 +155,21 @@ class TCGPlayerSDK
|
|
155
155
|
# https://docs.tcgplayer.com/reference/catalog_getproduct-1
|
156
156
|
#
|
157
157
|
def product_details(_ids, params = {})
|
158
|
-
|
159
|
-
|
158
|
+
slice_ids(_ids) do |slice|
|
159
|
+
query("#{CATALOG_URL}/products/#{id_list(slice)}", params)
|
160
|
+
end
|
160
161
|
end
|
161
162
|
|
162
163
|
##
|
163
164
|
# Accessor to https://docs.tcgplayer.com/reference/pricing_getproductprices-1
|
165
|
+
# Automatically handles arbitrarily large number of _ids and provides one merged response
|
164
166
|
#
|
165
167
|
# @param _ids An array of product IDs to query
|
166
168
|
# @return [TCGPlayerSDK::ProductPriceList]
|
167
169
|
def product_pricing(_ids)
|
168
|
-
|
169
|
-
|
170
|
+
slice_ids(_ids) do |slice|
|
171
|
+
TCGPlayerSDK::ProductPriceList.new(query("#{PRICING_URL}/product/#{id_list(slice)}"))
|
172
|
+
end
|
170
173
|
end
|
171
174
|
|
172
175
|
private
|
@@ -179,4 +182,23 @@ class TCGPlayerSDK
|
|
179
182
|
def id_list(value)
|
180
183
|
value.is_a?(Array) ? value.join(',') : value
|
181
184
|
end
|
185
|
+
|
186
|
+
##
|
187
|
+
# Slice the input ids into smaller pieces, and execute the given block with each slice. Merge the results
|
188
|
+
def slice_ids(_ids, slice_size=200)
|
189
|
+
ids = _ids.is_a?(Array) ? _ids : [_ids]
|
190
|
+
resp = nil
|
191
|
+
|
192
|
+
ids.each_slice(slice_size) do |slice|
|
193
|
+
response = yield(slice)
|
194
|
+
if(resp.nil?)
|
195
|
+
resp = response
|
196
|
+
else
|
197
|
+
resp.results += response.results if(response.results && resp.results)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
return resp
|
202
|
+
end
|
203
|
+
|
182
204
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcg-player-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Svensson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|