Ticketmaster.Core 1.0.1

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ticketmaster.Core" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ticketmaster.Core --version 1.0.1                
#r "nuget: Ticketmaster.Core, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.5 3,771 6/6/2021 2.0.5 is deprecated because it is no longer maintained.
2.0.4 2,881 5/11/2020
2.0.3 669 5/11/2020
2.0.3-alpha 521 9/12/2019
2.0.2 12,536 6/22/2019
2.0.1 929 12/22/2018
2.0.0 1,090 7/16/2018
1.0.1 1,535 1/23/2018
1.0.0 1,453 8/4/2017

Updates:
- Models re-factored.
- Project structure updated.