tcg-player-sdk 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 444973875234b87717e9ece0dd3c0373d707d2a13bac732330f7ab8d6a740f72
4
- data.tar.gz: cc526ef5f4bc6cadb4404096dfdf9b5a414b5a438d99c4ddf58171b2b6beb214
3
+ metadata.gz: 30c00bca03558c4b683d20e3ffec48dc5e843fdd5c7170c3410014ad3e2da619
4
+ data.tar.gz: f5a805adc5ea41c1d09d1d0c9e62c72ad6fa5c8bd147e2cb1a24d2eeca1084f4
5
5
  SHA512:
6
- metadata.gz: cdede9b22fe30a6f4106af572ca2f0523e6989ec426de0d307fdc37252cfee511ed6275bae255d954eb9cd386465042d650ac78a6096e522d2810cbe26d1d6bb
7
- data.tar.gz: e4649464a2dd938a07b9ee991cd1b9635248d36685f4f301feb31a5dcded44c43446f32e6a5172cf688938d2e36725c4277b1ef2e2e4e716f0aef7d75445b91a
6
+ metadata.gz: 6b24bdcb6d5a30ba9e1ec9bb682af8456331b0d74e418d734237699fbce048ffee172b2d15511f85c34b791fde8435b9ff84b37c5a11a2d6dea279f7a57e8ed1
7
+ data.tar.gz: d77e338ace8d2605deb9c3c170e75078afea999cdf04f16c7548963d92ef63316b3060089b2540a33fb37c9875f3a991d51a886b6bcd121295993842cb44efe8
@@ -17,4 +17,14 @@ class TCGPlayerSDK::BearerToken
17
17
  def to_s
18
18
  ap self, indent: -2
19
19
  end
20
+
21
+ def to_json
22
+ h = {
23
+ access_token: token,
24
+ token_type: 'bearer',
25
+ expires_in: expires_in,
26
+ '.issued' => issued.to_s,
27
+ '.expires' => expiration.to_s,
28
+ }.to_json
29
+ end
20
30
  end
@@ -0,0 +1,38 @@
1
+ # Add some shortcuts and helpers to parse the manifest
2
+ class TCGPlayerSDK::Manifest < TCGPlayerSDK::ResponseStruct
3
+
4
+ def initialize(hash = nil)
5
+ super
6
+ end
7
+
8
+ ##
9
+ # Pick out the sorting struct from the response
10
+ #
11
+ # @return [Array<TCGPlayerSDK::ResponseStruct>]
12
+ def sorting
13
+ if(self.results && self.results.is_a?(Array))
14
+ @sorting ||= self.results.first.sorting
15
+ end
16
+
17
+ return @sorting
18
+ end
19
+
20
+ ##
21
+ # @return [Array<String>] The actual values that are legitimate inputs to search query's sort field
22
+ def sort_values
23
+ _sorting = sorting || []
24
+ @sort_values ||= _sorting.map(&:value)
25
+ end
26
+
27
+ ##
28
+ # Pick out the filters struct from the response
29
+ #
30
+ # @return [Array<TCGPlayerSDK::ResponseStruct>]
31
+ def filters
32
+ if(self.results && self.results.is_a?(Array))
33
+ @filters ||= self.results.first.filters
34
+ end
35
+
36
+ return @filters
37
+ end
38
+ end
@@ -25,6 +25,13 @@ class TCGPlayerSDK::Pokemon
25
25
  @set_filter ||= @manifest.results.first.filters.select{|f| f.name == 'SetName'}.first
26
26
  end
27
27
 
28
+ ##
29
+ # @return [Array<TCGPlayerSDK::ResponseStruct>] Response struct with keys :value and :text, which correspond to
30
+ # the available ways to sort search data. Set :sort in your search parameters to one of the returned :value
31
+ def sorting
32
+ @sorting ||= @manifest.results.first.sorting
33
+ end
34
+
28
35
  ##
29
36
  # Returns the TCGPlayerSDK filter item corresponding to the input set
30
37
  #
@@ -1,16 +1,15 @@
1
- class TCGPlayerSDK::ProductPriceList
2
- attr_accessor :response
1
+ class TCGPlayerSDK::ProductPriceList < TCGPlayerSDK::ResponseStruct
3
2
 
4
3
  ##
5
4
  # Group prices by product ID. This will set
6
5
  # prices to an empty hash if there was an error. Check response.errors for details about any errors.
7
6
  #
8
7
  # @param _response[TCGPlayerSDK::ResponseStruct] the result of calling TCGPlayerAPI#product_pricing
9
- def initialize(_response)
10
- @response = _response
8
+ def initialize(hash = {})
9
+ super
11
10
 
12
- if(response.success && response.results)
13
- @prices = response.results.map{|r| TCGPlayerSDK::ProductPrice.new(r)}.group_by{|r| r.productId}
11
+ if(self.success && self.results)
12
+ @prices = self.results.map{|r| TCGPlayerSDK::ProductPrice.new(r)}.group_by{|r| r.productId}
14
13
  else
15
14
  @prices = {}
16
15
  end
@@ -115,28 +115,68 @@ class TCGPlayerSDK
115
115
  #
116
116
  # @return [TCGPlayerSDK::ResponseStruct]
117
117
  def category_search_manifest(id)
118
- query("#{CATEGORIES_URL}/#{id}/search/manifest")
118
+ Manifest.new(query("#{CATEGORIES_URL}/#{id}/search/manifest"))
119
119
  end
120
120
 
121
121
  # https://docs.tcgplayer.com/reference/catalog_searchcategory
122
122
  #
123
+ # @param id[String] The category ID to search through
124
+ # @param params[Hash] Put your additional search terms here:
125
+ # - sort: One of the available sort filters see manifest.results.first.sorting
126
+ # - limit: Cap the number of results to this limit
127
+ # - offset: Used with :limit to return a limited number of results in an arbitrary location. i.e. for pagination
128
+ # - filters[Array<Hash>] An array of filters as described by manifest.results.first.filters. Use the following format for Hash in the filters array
129
+ # - name[String]: Name of one of the filters from the manifest
130
+ # - values[Array<String>]: Specify which values to filter on
131
+ #
132
+ # params = {
133
+ # sort: 'ProductName ASC',
134
+ # limit: 10,
135
+ # offset: 0,
136
+ # filters: [ {
137
+ # name: 'ProductName',
138
+ # values: ['Alakazam']
139
+ # }]
140
+ # }
141
+ #
142
+ # results = tcg.category_search_products(3, params)
143
+ # results.results #=> [42444, 42346, 83496, 106996, 83501, 83499, 83497, 83500, 83498, 180715]
144
+ #
145
+ # # Do something with each product ID... will automatically fetch new results
146
+ # all_ids = results.map{|r| r} #=> [42444, 42346, 83496, 106996, 83501, 83499, 83497, 83500, 83498, 180715, 83503, 83504, 117512, 117889, 117896, 117863, 83502, 226606, 228981, 228980, 228979, 251560, 84559, 84560, 118332, 117515, 117890, 88866]
147
+ #
123
148
  # @return [TCGPlayerSDK::ResponseStruct]
124
149
  def category_search_products(id, params = {})
125
150
  search_params = {post: true}.merge(params)
126
151
  query("#{CATEGORIES_URL}/#{id}/search", search_params)
127
152
  end
128
153
 
129
- #def product_details(pids, params = {})
130
- # query("#{CATEGORIES_URL}/#{id}/search", search_params)
131
- #end
154
+ ##
155
+ # https://docs.tcgplayer.com/reference/catalog_getproduct-1
156
+ #
157
+ def product_details(_ids, params = {})
158
+ ids = id_list(_ids)
159
+ query("#{CATALOG_URL}/products/#{ids}", params)
160
+ end
132
161
 
133
162
  ##
134
163
  # Accessor to https://docs.tcgplayer.com/reference/pricing_getproductprices-1
135
164
  #
136
- # @param ids An array of product IDs to query
165
+ # @param _ids An array of product IDs to query
137
166
  # @return [TCGPlayerSDK::ProductPriceList]
138
167
  def product_pricing(_ids)
139
- ids = _ids.is_a?(Array) ? _ids.join(',') : _ids
168
+ ids = id_list(_ids)
140
169
  TCGPlayerSDK::ProductPriceList.new(query("#{PRICING_URL}/product/#{ids}"))
141
170
  end
171
+
172
+ private
173
+
174
+ ##
175
+ # Sanitize an array or string of ids to be compatible with the comma-separated values that the API expects
176
+ #
177
+ # @param value Accepts either an Array or String to convert to the API-friendly formatting
178
+ # @return [String] ids separated by comma
179
+ def id_list(value)
180
+ value.is_a?(Array) ? value.join(',') : value
181
+ end
142
182
  end
@@ -8,4 +8,5 @@ require 'tcg-player-sdk/bearer_token'
8
8
  require 'tcg-player-sdk/response_struct'
9
9
  require 'tcg-player-sdk/product_price_list'
10
10
  require 'tcg-player-sdk/pokemon'
11
+ require 'tcg-player-sdk/manifest'
11
12
 
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.3
4
+ version: 0.1.4
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-24 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -62,6 +62,7 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - lib/tcg-player-sdk.rb
64
64
  - lib/tcg-player-sdk/bearer_token.rb
65
+ - lib/tcg-player-sdk/manifest.rb
65
66
  - lib/tcg-player-sdk/pokemon.rb
66
67
  - lib/tcg-player-sdk/product_price_list.rb
67
68
  - lib/tcg-player-sdk/response_struct.rb