Ticketmaster.Core
1.0.1
See the version list below for details.
dotnet add package Ticketmaster.Core --version 1.0.1
NuGet\Install-Package Ticketmaster.Core -Version 1.0.1
<PackageReference Include="Ticketmaster.Core" Version="1.0.1" />
paket add Ticketmaster.Core --version 1.0.1
#r "nuget: Ticketmaster.Core, 1.0.1"
// Install Ticketmaster.Core as a Cake Addin #addin nuget:?package=Ticketmaster.Core&version=1.0.1 // Install Ticketmaster.Core as a Cake Tool #tool nuget:?package=Ticketmaster.Core&version=1.0.1
Ticketmaster.Core
This package contains common components for Ticketmaster SDK's
Description
The Ticketmaster.Core solution contains components such ass common client interfaces:
- IClientConfig - interface for client configuration;
- IApiRequest - interface for api requests classes;
- IApiGetRequest - interface inherited from IApiRequest created for api GET requests classes;
- IApiResponse - interface for Api responses;
Base Implementation for Api Clients BaseClient, and for queering BaseQuery, GetRequest.
This common models components to serialize response data:
- NameIdPair
- IdTypePaire
- IdTypePairCollectionData
- CurrencyValuePair
Usage
BaseClient.cs
The public abstract class BaseClient is a parent class for all Clients in the SDK. It contains the only protected virtual methods.
1) ExecuteRequestAsync
This method is adding query parameters to IRestRequest, executing call to api and validate the response using method ValidateResponse.
/// <summary>
/// Executes the request asynchronous.
/// </summary>
/// <typeparam name="T">Type of expected response.</typeparam>
/// <param name="request">The request.</param>
/// <param name="expectedStatusCode">The expected status code.</param>
/// <param name="query">The <see cref="IApiRequest" />.</param>
/// <returns></returns>
protected virtual async Task<T> ExecuteRequestAsync<T>(
IRestRequest request,
HttpStatusCode expectedStatusCode,
IApiRequest query = null)
where T : IApiResponse
{
AddQuiriesToRequest(ref request, query);
var response = await _client.ExecuteTaskAsync<T>(request);
ValidateResponse(response, expectedStatusCode);
return response.Data;
}
2) ValidateResponse
The base implementation of ValidateResponse method is comparing Response Status Code with Expected Code and throws InvalidDataException in case if the doesn't math.
protected virtual void ValidateResponse(IRestResponse response, HttpStatusCode expectedCode)
{
if (response.StatusCode == expectedCode) return;
var exceptionBuilder = new StringBuilder();
exceptionBuilder.AppendLine("Invalid respond from the server.");
exceptionBuilder.AppendLine("Current Status Code:" + response.StatusCode);
if (!string.IsNullOrEmpty(response.ErrorMessage))
exceptionBuilder.AppendLine("Error Message:" + response.ErrorMessage);
if (!string.IsNullOrEmpty(response.Content))
exceptionBuilder.AppendLine("Content:" + response.Content);
throw new InvalidDataException(exceptionBuilder.ToString());
}
For example when you doesn't setup IClientConfig property ConsumerKey Without a valid API Key, you will receive a 401 Status Code from API.
{
"fault": {
"faultstring": "Invalid ApiKey",
"detail": {
"errorcode": "oauth.v2.InvalidApiKey"
}
}
}
So exception for this response will be like this:
Invalid respond from the server.
Current Status Code:Unauthorized
Content: { \"fault\": { \"faultstring\": \"Invalid ApiKey\", \"detail\": { \"errorcode\": \"oauth.v2.InvalidApiKey\" } } }
Dependencies
This packages is depended on RestSharp
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- RestSharp (>= 106.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updates:
- Models re-factored.
- Project structure updated.