tcg-player-sdk 0.1.4 → 0.1.7
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 +31 -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: 184656f7abbc6a380c6aff7f017f560dc4f4030cb8bc50ef0c73fd3c5c5b7bd7
|
4
|
+
data.tar.gz: 0e7c70024f3beaffc399f63dceabdf208584c7c805a1922d357eac290e4927f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '04946a188758e630db7a2a422ed4df275ce1da16c31f8b5ebe97cf01537abf01e13b487206da081b117ed26fa3c220a78c47c6ee005951c5f8c60e1b97c012c3'
|
7
|
+
data.tar.gz: 392276fa0e12c2c7f4096f6ca53eaba5d0c59a9337cb01fe43ddcb3754dab28cf699f3de2cee518a3d3f863539787fc7a8b50ca71d8b0303d6b76295c599b6c9
|
@@ -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,28 @@ 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
|
+
# Corner case for emptiness
|
193
|
+
if(ids.empty?)
|
194
|
+
resp = yield(ids)
|
195
|
+
else
|
196
|
+
ids.each_slice(slice_size) do |slice|
|
197
|
+
response = yield(slice)
|
198
|
+
if(resp.nil?)
|
199
|
+
resp = response
|
200
|
+
else
|
201
|
+
resp.results += response.results if(response.results && resp.results)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
return resp
|
207
|
+
end
|
208
|
+
|
182
209
|
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.7
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|