5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . IO ;
8
+ using System . Threading ;
8
9
using System . Threading . Tasks ;
9
10
using Item = FikaAmazonAPI . AmazonSpApiSDK . Models . CatalogItems . Item ;
10
11
@@ -76,7 +77,7 @@ public async Task<Item> GetCatalogItemAsync(string asin)
76
77
public IList < Categories > ListCatalogCategories ( string ASIN , string SellerSKU = null , string MarketPlaceID = null ) =>
77
78
Task . Run ( ( ) => ListCatalogCategoriesAsync ( ASIN , SellerSKU , MarketPlaceID ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
78
79
79
- public async Task < IList < Categories > > ListCatalogCategoriesAsync ( string ASIN , string SellerSKU = null , string MarketPlaceID = null )
80
+ public async Task < IList < Categories > > ListCatalogCategoriesAsync ( string ASIN , string SellerSKU = null , string MarketPlaceID = null , CancellationToken cancellationToken = default )
80
81
{
81
82
if ( string . IsNullOrEmpty ( ASIN ) )
82
83
throw new InvalidDataException ( "ASIN is a required property and cannot be null or empty" ) ;
@@ -88,8 +89,8 @@ public async Task<IList<Categories>> ListCatalogCategoriesAsync(string ASIN, str
88
89
if ( ! string . IsNullOrEmpty ( SellerSKU ) )
89
90
param . Add ( new KeyValuePair < string , string > ( "SellerSKU" , SellerSKU ) ) ;
90
91
91
- await CreateAuthorizedRequestAsync ( CategoryApiUrls . ListCatalogCategories , RestSharp . Method . Get , param ) ;
92
- var response = await ExecuteRequestAsync < ListCatalogCategoriesResponse > ( RateLimitType . CatalogItems_ListCatalogCategories ) ;
92
+ await CreateAuthorizedRequestAsync ( CategoryApiUrls . ListCatalogCategories , RestSharp . Method . Get , param , cancellationToken : cancellationToken ) ;
93
+ var response = await ExecuteRequestAsync < ListCatalogCategoriesResponse > ( RateLimitType . CatalogItems_ListCatalogCategories , cancellationToken ) ;
93
94
94
95
if ( response != null && response . Payload != null )
95
96
return response . Payload ;
@@ -106,7 +107,7 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
106
107
/// <summary>
107
108
/// Retrieves details for an item in the Amazon catalog.
108
109
/// </summary>
109
- public async Task < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > GetCatalogItem202204Async ( ParameterGetCatalogItem parameterGetCatalogItem )
110
+ public async Task < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > GetCatalogItem202204Async ( ParameterGetCatalogItem parameterGetCatalogItem , CancellationToken cancellationToken = default )
110
111
{
111
112
if ( string . IsNullOrEmpty ( parameterGetCatalogItem . ASIN ) )
112
113
throw new InvalidDataException ( "asin is a required property and cannot be null" ) ;
@@ -118,8 +119,8 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
118
119
119
120
var param = parameterGetCatalogItem . getParameters ( ) ;
120
121
121
- await CreateAuthorizedRequestAsync ( CategoryApiUrls . GetCatalogItem202204 ( parameterGetCatalogItem . ASIN ) , RestSharp . Method . Get , param ) ;
122
- var response = await ExecuteRequestAsync < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > ( RateLimitType . CatalogItems20220401_GetCatalogItem ) ;
122
+ await CreateAuthorizedRequestAsync ( CategoryApiUrls . GetCatalogItem202204 ( parameterGetCatalogItem . ASIN ) , RestSharp . Method . Get , param , cancellationToken : cancellationToken ) ;
123
+ var response = await ExecuteRequestAsync < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > ( RateLimitType . CatalogItems20220401_GetCatalogItem , cancellationToken ) ;
123
124
124
125
return response ;
125
126
}
@@ -128,7 +129,7 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
128
129
public IList < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > SearchCatalogItems202204 ( ParameterSearchCatalogItems202204 parameterSearchCatalogItems ) =>
129
130
Task . Run ( ( ) => SearchCatalogItems202204Async ( parameterSearchCatalogItems ) ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
130
131
131
- public async Task < IList < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > > SearchCatalogItems202204Async ( ParameterSearchCatalogItems202204 parameter )
132
+ public async Task < IList < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > > SearchCatalogItems202204Async ( ParameterSearchCatalogItems202204 parameter , CancellationToken cancellationToken = default )
132
133
{
133
134
if ( parameter . identifiers != null && parameter . identifiers . Count > 20 )
134
135
throw new InvalidDataException ( "identifiers max count 20" ) ;
@@ -145,17 +146,17 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
145
146
146
147
var param = parameter . getParameters ( ) ;
147
148
148
- await CreateAuthorizedRequestAsync ( CategoryApiUrls . SearchCatalogItems202204 , RestSharp . Method . Get , param ) ;
149
- var response = await ExecuteRequestAsync < ItemSearchResults > ( RateLimitType . CatalogItems20220401_SearchCatalogItems ) ;
149
+ await CreateAuthorizedRequestAsync ( CategoryApiUrls . SearchCatalogItems202204 , RestSharp . Method . Get , param , cancellationToken : cancellationToken ) ;
150
+ var response = await ExecuteRequestAsync < ItemSearchResults > ( RateLimitType . CatalogItems20220401_SearchCatalogItems , cancellationToken ) ;
150
151
list . AddRange ( response . Items ) ;
151
152
var totalPages = 1 ;
152
153
if ( response . Pagination != null && ! string . IsNullOrEmpty ( response . Pagination . NextToken ) )
153
154
{
154
155
var nextToken = response . Pagination . NextToken ;
155
156
while ( ! string . IsNullOrEmpty ( nextToken ) && ( ! parameter . maxPages . HasValue || totalPages < parameter . maxPages . Value ) )
156
157
{
157
- parameter . pageToken = nextToken ;
158
- var getItemNextPage = await SearchCatalogItemsByNextToken202204Async ( parameter ) ;
158
+ parameter . pageToken = nextToken ;
159
+ var getItemNextPage = await SearchCatalogItemsByNextToken202204Async ( parameter , cancellationToken ) ;
159
160
list . AddRange ( getItemNextPage . Items ) ;
160
161
nextToken = getItemNextPage . Pagination ? . NextToken ;
161
162
totalPages ++ ;
@@ -164,15 +165,15 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
164
165
return list ;
165
166
}
166
167
167
- private async Task < ItemSearchResults > SearchCatalogItemsByNextToken202204Async ( ParameterSearchCatalogItems202204 parameter )
168
+ private async Task < ItemSearchResults > SearchCatalogItemsByNextToken202204Async ( ParameterSearchCatalogItems202204 parameter , CancellationToken cancellationToken = default )
168
169
{
169
170
170
171
List < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > list = new List < AmazonSpApiSDK . Models . CatalogItems . V20220401 . Item > ( ) ;
171
172
172
173
var param = parameter . getParameters ( ) ;
173
174
174
- await CreateAuthorizedRequestAsync ( CategoryApiUrls . SearchCatalogItems202204 , RestSharp . Method . Get , param ) ;
175
- return await ExecuteRequestAsync < ItemSearchResults > ( RateLimitType . CatalogItems20220401_SearchCatalogItems ) ;
175
+ await CreateAuthorizedRequestAsync ( CategoryApiUrls . SearchCatalogItems202204 , RestSharp . Method . Get , param , cancellationToken : cancellationToken ) ;
176
+ return await ExecuteRequestAsync < ItemSearchResults > ( RateLimitType . CatalogItems20220401_SearchCatalogItems , cancellationToken ) ;
176
177
}
177
178
#endregion
178
179
}
0 commit comments