henrikfroehling / TraktApiSharp

DEPRECATED!!! A .NET library for the Trakt.tv API.
MIT License
31 stars 4 forks source link

TraktApiSharp TwitterTwitter Follow

This repository is deprecated. For newer versions, please follow the new repository Trakt.NET.

This is a .NET wrapper library for the Trakt.tv API.

NuGet Package NuGet Package License PRs Welcome CodeFactor

Features

Supported Platforms

Chat Room

Do you have a question or suggestion?

Gitter

Or do you want to report a bug?

Contributions are welcome

Build Status

Branch Status Description
master Build status branch master This branch tracks all stable releases.
dev Build status branch dev This branch tracks the current and possibly unstable development.
next-version Build status branch next-version This branch tracks the current and possibly unstable development of the next major (1.0.0) version.

Getting Started

Install the latest release by running the following NuGet command

PM> Install-Package TraktApiSharp

or with the NuGet Package Management in Visual Studio and search for "trakt".

Each release will also be published here and here.

Library API Documentation

Basic Usage or more advanced usage guide

Create a new TraktApiSharp Client

// Client ID is sufficient for usage without OAuth
var client = new TraktClient("Your Trakt Client ID");

// Both Client ID and Client Secret are required, if you need to authenticate your application
var client = new TraktClient("Your Trakt Client ID", "Your Trakt Client Secret");

// Both Client ID and Access Token are required, if you want to use requests, that require authorization
var client = new TraktClient("Your Trakt Client ID")
{
    Authorization = TraktAuthorization.CreateWith("Trakt Access Token")
};

Use your existing tokens

var client = new TraktClient("Your Trakt Client ID");

// Only access token
client.Authorization = TraktAuthorization.CreateWith("Your Access Token");

// Access Token and Refresh Token
client.Authorization = TraktAuthorization.CreateWith("Your Access Token", "Your Refresh Token");

Serialize and deserialize authorization information

TraktAuthorization authorization = client.Authorization;

// Get JSON string from current authorization
string json = TraktSerializationService.Serialize(authorization);

// Get TraktAuthorization from JSON string
TraktAuthorization deserializedAuthorization = TraktSerializationService.DeserializeAuthorization(json);

client.Authorization = deserializedAuthorization;

// authorization == deserializedAuthorization

Configure the client

client.ClientId = "Your Trakt Client ID";
client.ClientSecret = "Your Trakt Client Secret";

client.Configuration.ApiVersion = 2; // Set by default

// Set this to true, to use Trakt API staging environment
// This is disabled by default
client.Configuration.UseSandboxEnvironment = true;

// Force authorization for requests, where authorization is optional
// This is disabled by default
client.Configuration.ForceAuthorization = true;

Get the top 10 trending shows including full information

var trendingShowsTop10 = await client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo().SetFull(), null, 10);
// or
var trendingShowsTop10 = await client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo() { Full = true }, 1, 10);

foreach (var trendingShow in trendingShowsTop10)
{
    var show = trendingShow.Show;
    Console.WriteLine($"Show: {show.Title} / Watchers: {trendingShow.Watchers}");
}

Get the top 10 trending movies including full information

var extendedInfo = new TraktExtendedInfo() { Full = true };

var trendingMoviesTop10 = await client.Movies.GetTrendingMoviesAsync(extendedInfo, null, 10);
// or
var trendingMoviesTop10 = await client.Movies.GetTrendingMoviesAsync(extendedInfo, 1, 10);

foreach (var trendingMovie in trendingMoviesTop10)
{
    var movie = trendingMovie.Movie;
    Console.WriteLine($"Movie: {movie.Title} / Watchers: {trendingMovie.Watchers}");
}

Get the show 'Game of Thrones'

var gameOfThrones = await client.Shows.GetShowAsync("game-of-thrones", new TraktExtendedInfo().SetFull());

Console.WriteLine($"Title: {gameOfThrones.Title} / Year: {gameOfThrones.Year}");
Console.WriteLine(gameOfThrones.Overview);

Get the movie 'The Martian'

var theMartian = await client.Movies.GetMovieAsync("the-martian-2015", new TraktExtendedInfo().SetFull());

Console.WriteLine($"Title: {theMartian.Title} / Year: {theMartian.Year}");
Console.WriteLine(theMartian.Overview);

License

The MIT License (MIT)

Copyright © 2016 - 2018 Henrik Fröhling et al.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.