Skip to content

Commit c200181

Browse files
authored
Merge pull request #356 from abuzuhri/updateToRestsharp108
Update to restsharp108
2 parents fa1d342 + 8ac2249 commit c200181

37 files changed

+196
-195
lines changed

Source/FikaAmazonAPI.SampleCode/FikaAmazonAPI.SampleCode.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
2929
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.0" />
3030
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
31-
<PackageReference Include="RestSharp" Version="106.12.0" />
31+
<PackageReference Include="RestSharp" Version="108.0.1" />
3232
<PackageReference Include="System.Collections" Version="4.3.0" />
3333
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
3434
<PackageReference Include="System.Reflection" Version="4.3.0" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"FikaAmazonAPI.SampleCode": {
4+
"commandName": "Project"
5+
}
6+
}
7+
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AmazonException : Exception
88
{
99
public ExceptionResponse Response { get; set; }
1010

11-
public AmazonException(string msg, IRestResponse response = null) : base(msg)
11+
public AmazonException(string msg, RestResponse response = null) : base(msg)
1212
{
1313
if (response != null)
1414
{
@@ -22,38 +22,38 @@ public AmazonException(string msg, IRestResponse response = null) : base(msg)
2222

2323
public class AmazonNotFoundException : AmazonException
2424
{
25-
public AmazonNotFoundException(string msg, IRestResponse response = null) : base(msg, response)
25+
public AmazonNotFoundException(string msg, RestResponse response = null) : base(msg, response)
2626
{
2727

2828
}
2929
}
3030

3131
public class AmazonUnauthorizedException : AmazonException
3232
{
33-
public AmazonUnauthorizedException(string msg, IRestResponse response = null) : base(msg, response)
33+
public AmazonUnauthorizedException(string msg, RestResponse response = null) : base(msg, response)
3434
{
3535

3636
}
3737
}
3838

3939
public class AmazonInvalidInputException : AmazonException
4040
{
41-
public AmazonInvalidInputException(string msg, IRestResponse response = null) : base(msg, response)
41+
public AmazonInvalidInputException(string msg, RestResponse response = null) : base(msg, response)
4242
{
4343

4444
}
4545
}
4646
public class AmazonQuotaExceededException : AmazonException
4747
{
48-
public AmazonQuotaExceededException(string msg, IRestResponse response = null) : base(msg, response)
48+
public AmazonQuotaExceededException(string msg, RestResponse response = null) : base(msg, response)
4949
{
5050

5151
}
5252
}
5353

5454
public class AmazonInvalidSignatureException : AmazonException
5555
{
56-
public AmazonInvalidSignatureException(string msg, IRestResponse response = null) : base(msg, response)
56+
public AmazonInvalidSignatureException(string msg, RestResponse response = null) : base(msg, response)
5757
{
5858

5959
}
@@ -62,7 +62,7 @@ public AmazonInvalidSignatureException(string msg, IRestResponse response = null
6262
public class AmazonProcessingReportDeserializeException : AmazonException
6363
{
6464
public string ReportContent { get; set; }
65-
public AmazonProcessingReportDeserializeException(string msg, string reportContent, IRestResponse response = null) : base(msg, response)
65+
public AmazonProcessingReportDeserializeException(string msg, string reportContent, RestResponse response = null) : base(msg, response)
6666
{
6767
ReportContent = reportContent;
6868
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Runtime/AWSSigV4Signer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public AWSSigV4Signer(AWSAuthenticationCredentials awsAuthenticationCredentials)
2626
/// <param name="request">RestRequest which needs to be signed</param>
2727
/// <param name="host">Request endpoint</param>
2828
/// <returns>RestRequest with AWS Signature</returns>
29-
public IRestRequest Sign(IRestRequest request, string host)
29+
public RestRequest Sign(RestRequest request, string host)
3030
{
3131
DateTime signingDate = AwsSignerHelper.InitializeHeaders(request, host);
3232
string signedHeaders = AwsSignerHelper.ExtractSignedHeaders(request);
@@ -52,11 +52,11 @@ public IRestRequest Sign(IRestRequest request, string host)
5252
return request;
5353
}
5454

55-
private string CreateCanonicalRequest(IRestRequest restRequest, string signedHeaders)
55+
private string CreateCanonicalRequest(RestRequest restRequest, string signedHeaders)
5656
{
5757
var canonicalizedRequest = new StringBuilder();
5858
//Request Method
59-
canonicalizedRequest.AppendFormat("{0}\n", restRequest.Method);
59+
canonicalizedRequest.AppendFormat("{0}\n", restRequest.Method.ToString().ToUpperInvariant());
6060

6161
//CanonicalURI
6262
canonicalizedRequest.AppendFormat("{0}\n", AwsSignerHelper.ExtractCanonicalURIParameters(restRequest.Resource));

Source/FikaAmazonAPI/AmazonSpApiSDK/Runtime/AWSSignerHelper.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public virtual string ExtractCanonicalURIParameters(string resource)
7373
/// </summary>
7474
/// <param name="request">RestRequest</param>
7575
/// <returns>Query parameters in canonical order with URL encoding</returns>
76-
public virtual string ExtractCanonicalQueryString(IRestRequest request)
76+
public virtual string ExtractCanonicalQueryString(RestRequest request)
7777
{
7878
IDictionary<string, string> queryParameters = request.Parameters
7979
.Where(parameter => ParameterType.QueryString.Equals(parameter.Type))
@@ -101,7 +101,7 @@ public virtual string ExtractCanonicalQueryString(IRestRequest request)
101101
/// </summary>
102102
/// <param name="request">RestRequest</param>
103103
/// <returns>Returns Http headers in canonical order</returns>
104-
public virtual string ExtractCanonicalHeaders(IRestRequest request)
104+
public virtual string ExtractCanonicalHeaders(RestRequest request)
105105
{
106106
IDictionary<string, string> headers = request.Parameters
107107
.Where(parameter => ParameterType.HttpHeader.Equals(parameter.Type))
@@ -126,7 +126,7 @@ public virtual string ExtractCanonicalHeaders(IRestRequest request)
126126
/// </summary>
127127
/// <param name="request">RestRequest</param>
128128
/// <returns>List of Http headers in canonical order</returns>
129-
public virtual string ExtractSignedHeaders(IRestRequest request)
129+
public virtual string ExtractSignedHeaders(RestRequest request)
130130
{
131131
List<string> rawHeaders = request.Parameters.Where(parameter => ParameterType.HttpHeader.Equals(parameter.Type))
132132
.Select(header => header.Name.Trim().ToLowerInvariant())
@@ -141,7 +141,7 @@ public virtual string ExtractSignedHeaders(IRestRequest request)
141141
/// </summary>
142142
/// <param name="request">RestRequest</param>
143143
/// <returns>Hexadecimal hashed value of payload in the body of request</returns>
144-
public virtual string HashRequestBody(IRestRequest request)
144+
public virtual string HashRequestBody(RestRequest request)
145145
{
146146
RestSharp.Parameter body = request.Parameters.FirstOrDefault(parameter => ParameterType.RequestBody.Equals(parameter.Type));
147147
string value = body != null ? body.Value.ToString() : string.Empty;
@@ -175,15 +175,12 @@ public virtual string BuildStringToSign(DateTime signingDate, string hashedCanon
175175
/// <param name="restRequest">RestRequest</param>
176176
/// <param name="host">Request endpoint</param>
177177
/// <returns>Date and time used for x-amz-date, in UTC</returns>
178-
public virtual DateTime InitializeHeaders(IRestRequest restRequest, string host)
178+
public virtual DateTime InitializeHeaders(RestRequest restRequest, string host)
179179
{
180180
lock (restRequest)
181181
{
182-
restRequest.Parameters.RemoveAll(parameter => ParameterType.HttpHeader.Equals(parameter.Type)
183-
&& parameter.Name == XAmzDateHeaderName);
184-
restRequest.Parameters.RemoveAll(parameter => ParameterType.HttpHeader.Equals(parameter.Type)
185-
&& parameter.Name == HostHeaderName);
186-
182+
restRequest.Parameters.RemoveParameter(XAmzDateHeaderName);
183+
restRequest.Parameters.RemoveParameter(HostHeaderName);
187184
DateTime signingDate = DateHelper.GetUtcNow();
188185

189186
restRequest.AddOrUpdateHeader(XAmzDateHeaderName, signingDate.ToString(ISO8601BasicDateTimeFormat, CultureInfo.InvariantCulture));
@@ -226,7 +223,7 @@ public virtual string CalculateSignature(string stringToSign,
226223
/// <param name="signature">The signature to add</param>
227224
/// <param name="region">AWS region for the request</param>
228225
/// <param name="signingDate">Signature date</param>
229-
public virtual void AddSignature(IRestRequest restRequest,
226+
public virtual void AddSignature(RestRequest restRequest,
230227
string accessKeyId,
231228
string signedHeaders,
232229
string signature,

Source/FikaAmazonAPI/AmazonSpApiSDK/Runtime/LWAClient.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Runtime
1010
public class LWAClient
1111
{
1212
public const string AccessTokenKey = "access_token";
13-
public const string JsonMediaType = "application/json; charset=utf-8";
13+
public const string JsonMediaType = "application/json";
1414

15-
public IRestClient RestClient { get; set; }
15+
public RestClient RestClient { get; set; }
1616
public LWAAccessTokenRequestMetaBuilder LWAAccessTokenRequestMetaBuilder { get; set; }
1717
public LWAAuthorizationCredentials LWAAuthorizationCredentials { get; private set; }
1818

@@ -34,11 +34,12 @@ public LWAClient(LWAAuthorizationCredentials lwaAuthorizationCredentials)
3434
public virtual async Task<TokenResponse> GetAccessTokenAsync()
3535
{
3636
LWAAccessTokenRequestMeta lwaAccessTokenRequestMeta = LWAAccessTokenRequestMetaBuilder.Build(LWAAuthorizationCredentials);
37-
var accessTokenRequest = new RestRequest(LWAAuthorizationCredentials.Endpoint.AbsolutePath, RestSharp.Method.POST);
37+
var accessTokenRequest = new RestRequest(LWAAuthorizationCredentials.Endpoint.AbsolutePath, RestSharp.Method.Post);
3838

3939
string jsonRequestBody = JsonConvert.SerializeObject(lwaAccessTokenRequestMeta);
4040

41-
accessTokenRequest.AddParameter(JsonMediaType, jsonRequestBody, ParameterType.RequestBody);
41+
//accessTokenRequest.AddParameter(JsonMediaType, jsonRequestBody, ParameterType.RequestBody);
42+
accessTokenRequest.AddJsonBody(jsonRequestBody);
4243

4344
try
4445
{
@@ -60,7 +61,7 @@ public virtual async Task<TokenResponse> GetAccessTokenAsync()
6061
}
6162
}
6263

63-
private bool IsSuccessful(IRestResponse response)
64+
private bool IsSuccessful(RestResponse response)
6465
{
6566
int statusCode = (int)response.StatusCode;
6667
return statusCode >= 200 && statusCode <= 299 && response.ResponseStatus == ResponseStatus.Completed;

Source/FikaAmazonAPI/FikaAmazonAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<PackageReference Include="AWSSDK.SQS" Version="3.7.2.86" />
4040
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
4141
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
42-
<PackageReference Include="RestSharp" Version="106.12.0" />
42+
<PackageReference Include="RestSharp" Version="108.0.1" />
4343
<PackageReference Include="System.Collections" Version="4.3.0" />
4444
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
4545
<PackageReference Include="System.Reflection" Version="4.3.0" />

Source/FikaAmazonAPI/Services/AuthorizationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public string GetAuthorizationCode(ParameterAuthorizationCode parameterGetOrderM
1717
public async Task<string> GetAuthorizationCodeAsync(ParameterAuthorizationCode parameter)
1818
{
1919
var param = parameter.getParameters();
20-
await CreateAuthorizedRequestAsync(AuthorizationsApiUrls.GetAuthorizationCode, RestSharp.Method.GET, param, tokenDataType: TokenDataType.Grantless);
20+
await CreateAuthorizedRequestAsync(AuthorizationsApiUrls.GetAuthorizationCode, RestSharp.Method.Get, param, tokenDataType: TokenDataType.Grantless);
2121

2222
var response = await ExecuteRequestAsync<GetAuthorizationCodeResponse>(Utils.RateLimitType.Authorization_GetAuthorizationCode);
2323
if (response != null && response.Payload != null)

Source/FikaAmazonAPI/Services/CatalogItemService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task<IList<Item>> ListCatalogItemsAsync(ParameterListCatalogItems p
4141

4242
var parameter = parameterListCatalogItems.getParameters();
4343

44-
await CreateAuthorizedRequestAsync(CategoryApiUrls.ListCatalogItems, RestSharp.Method.GET, parameter);
44+
await CreateAuthorizedRequestAsync(CategoryApiUrls.ListCatalogItems, RestSharp.Method.Get, parameter);
4545
var response = await ExecuteRequestAsync<ListCatalogItemsResponse>(RateLimitType.CatalogItems_ListCatalogItems);
4646

4747
if (response != null && response.Payload != null && response.Payload.Items != null && response.Payload.Items.Count > 0)
@@ -63,7 +63,7 @@ public async Task<Item> GetCatalogItemAsync(string asin)
6363
var param = new List<KeyValuePair<string, string>>();
6464
param.Add(new KeyValuePair<string, string>("MarketplaceId", AmazonCredential.MarketPlace.ID));
6565

66-
await CreateAuthorizedRequestAsync(CategoryApiUrls.GetCatalogItem(asin), RestSharp.Method.GET, param);
66+
await CreateAuthorizedRequestAsync(CategoryApiUrls.GetCatalogItem(asin), RestSharp.Method.Get, param);
6767
var response = await ExecuteRequestAsync<GetCatalogItemResponse>(RateLimitType.CatalogItems_GetCatalogItem);
6868

6969
if (response != null && response.Payload != null)
@@ -88,7 +88,7 @@ public async Task<IList<Categories>> ListCatalogCategoriesAsync(string ASIN, str
8888
if (!string.IsNullOrEmpty(SellerSKU))
8989
param.Add(new KeyValuePair<string, string>("SellerSKU", SellerSKU));
9090

91-
await CreateAuthorizedRequestAsync(CategoryApiUrls.ListCatalogCategories, RestSharp.Method.GET, param);
91+
await CreateAuthorizedRequestAsync(CategoryApiUrls.ListCatalogCategories, RestSharp.Method.Get, param);
9292
var response = await ExecuteRequestAsync<ListCatalogCategoriesResponse>(RateLimitType.CatalogItems_ListCatalogCategories);
9393

9494
if (response != null && response.Payload != null)
@@ -118,7 +118,7 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
118118

119119
var param = parameterGetCatalogItem.getParameters();
120120

121-
await CreateAuthorizedRequestAsync(CategoryApiUrls.GetCatalogItem202204(parameterGetCatalogItem.ASIN), RestSharp.Method.GET, param);
121+
await CreateAuthorizedRequestAsync(CategoryApiUrls.GetCatalogItem202204(parameterGetCatalogItem.ASIN), RestSharp.Method.Get, param);
122122
var response = await ExecuteRequestAsync<AmazonSpApiSDK.Models.CatalogItems.V20220401.Item>(RateLimitType.CatalogItems20220401_GetCatalogItem);
123123

124124
return response;
@@ -145,7 +145,7 @@ public AmazonSpApiSDK.Models.CatalogItems.V20220401.Item GetCatalogItem202204(Pa
145145

146146
var param = parameter.getParameters();
147147

148-
await CreateAuthorizedRequestAsync(CategoryApiUrls.SearchCatalogItems202204, RestSharp.Method.GET, param);
148+
await CreateAuthorizedRequestAsync(CategoryApiUrls.SearchCatalogItems202204, RestSharp.Method.Get, param);
149149
var response = await ExecuteRequestAsync<ItemSearchResults>(RateLimitType.CatalogItems20220401_SearchCatalogItems);
150150
list.AddRange(response.Items);
151151
var totalPages = 1;
@@ -171,7 +171,7 @@ private async Task<ItemSearchResults> SearchCatalogItemsByNextToken202204Async(P
171171

172172
var param = parameter.getParameters();
173173

174-
await CreateAuthorizedRequestAsync(CategoryApiUrls.SearchCatalogItems202204, RestSharp.Method.GET, param);
174+
await CreateAuthorizedRequestAsync(CategoryApiUrls.SearchCatalogItems202204, RestSharp.Method.Get, param);
175175
return await ExecuteRequestAsync<ItemSearchResults>(RateLimitType.CatalogItems20220401_SearchCatalogItems);
176176
}
177177
#endregion

Source/FikaAmazonAPI/Services/EasyShip20220323Service.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task<ListHandoverSlotsResponse> ListHandoverSlotsAsync(ListHandover
2222
if (string.IsNullOrEmpty(listHandoverSlotsRequest.MarketplaceId))
2323
listHandoverSlotsRequest.MarketplaceId = AmazonCredential.MarketPlace.ID;
2424

25-
await CreateAuthorizedRequestAsync(EasyShip20220323.ListHandoverSlots, RestSharp.Method.POST, postJsonObj: listHandoverSlotsRequest);
25+
await CreateAuthorizedRequestAsync(EasyShip20220323.ListHandoverSlots, RestSharp.Method.Post, postJsonObj: listHandoverSlotsRequest);
2626
var response = await ExecuteRequestAsync<ListHandoverSlotsResponse>(RateLimitType.EasyShip_ListHandoverSlots);
2727
return response;
2828
}
@@ -36,7 +36,7 @@ public async Task<Package> GetScheduledPackageAsync(ParameterGetScheduledPackage
3636
parameterGetScheduledPackage.marketplaceId = AmazonCredential.MarketPlace.ID;
3737

3838
var parameter = parameterGetScheduledPackage.getParameters();
39-
await CreateAuthorizedRequestAsync(EasyShip20220323.GetScheduledPackage, RestSharp.Method.GET, parameter);
39+
await CreateAuthorizedRequestAsync(EasyShip20220323.GetScheduledPackage, RestSharp.Method.Get, parameter);
4040
var response = await ExecuteRequestAsync<Package>(RateLimitType.EasyShip_GetScheduledPackage);
4141
return response;
4242
}
@@ -50,7 +50,7 @@ public async Task<Package> CreateScheduledPackageAsync(CreateScheduledPackageReq
5050
if (string.IsNullOrEmpty(createScheduledPackageRequest.MarketplaceId))
5151
createScheduledPackageRequest.MarketplaceId = AmazonCredential.MarketPlace.ID;
5252

53-
await CreateAuthorizedRequestAsync(EasyShip20220323.CreateScheduledPackage, RestSharp.Method.POST, postJsonObj: createScheduledPackageRequest);
53+
await CreateAuthorizedRequestAsync(EasyShip20220323.CreateScheduledPackage, RestSharp.Method.Post, postJsonObj: createScheduledPackageRequest);
5454
var response = await ExecuteRequestAsync<Package>(RateLimitType.EasyShip_CreateScheduledPackage);
5555
return response;
5656
}
@@ -65,7 +65,7 @@ public async Task<Packages> UpdateScheduledPackagesAsync(UpdateScheduledPackages
6565
if (string.IsNullOrEmpty(updateScheduledPackagesRequest.MarketplaceId))
6666
updateScheduledPackagesRequest.MarketplaceId = AmazonCredential.MarketPlace.ID;
6767

68-
await CreateAuthorizedRequestAsync(EasyShip20220323.UpdateScheduledPackages, RestSharp.Method.PATCH, postJsonObj: updateScheduledPackagesRequest);
68+
await CreateAuthorizedRequestAsync(EasyShip20220323.UpdateScheduledPackages, RestSharp.Method.Patch, postJsonObj: updateScheduledPackagesRequest);
6969
var response = await ExecuteRequestAsync<Packages>(RateLimitType.EasyShip_UpdateScheduledPackages);
7070
return response;
7171
}

0 commit comments

Comments
 (0)