JimBobBennett.Mellon
0.1.22
See the version list below for details.
dotnet add package JimBobBennett.Mellon --version 0.1.22
NuGet\Install-Package JimBobBennett.Mellon -Version 0.1.22
<PackageReference Include="JimBobBennett.Mellon" Version="0.1.22" />
paket add JimBobBennett.Mellon --version 0.1.22
#r "nuget: JimBobBennett.Mellon, 0.1.22"
// Install JimBobBennett.Mellon as a Cake Addin #addin nuget:?package=JimBobBennett.Mellon&version=0.1.22 // Install JimBobBennett.Mellon as a Cake Tool #tool nuget:?package=JimBobBennett.Mellon&version=0.1.22
Mellon
Speak, friend, and enter! A C# SDK for The One API, an API that serves your needs regarding data about The Lord of the Rings, the epic books by J. R. R. Tolkien and the official movie adaptions by Peter Jackson.
This SDK only implements movies and quotes so far.
Install the SDK
This SDK can be installed from NuGet:
dotnet add package JimBobBennett.Mellon
Get an API key
Before you can use the SDK, you need an API key for The One API. Sign up at the-one-api.dev/sign-up to get your key.
Use the SDK
The entry point to the SDK is the TheOneAPIClient
class. To create this, you need to pass the API key in via an instance of TheOneAPICredentials
:
var client = new TheOneAPIClient(new TheOneAPICredentials(<apiKey>));
The API key should be set using dotnet user secrets or another mechanism to pass them at run time, and not hard coded.
The client loads data from The One Api in pages, defaulting to 1000 records per page. You can configure the page size if you want by passing it to the constructor:
var client = new TheOneAPIClient(new TheOneAPICredentials(<apiKey>), <page size>);
The client exposes 2 properties:
Movies
- a list of all the Lord of the Rings and Hobbit moviesQuotes
- a list of all the quotes from the Lord of the Rings and Hobbit movies
These are async enumerables, and lazy load from the API as you access them.
await foreach (var movie in client.Movies)
{
Console.WriteLine(movie.Name);
}
await foreach (var quote in client.Quotes)
{
Console.WriteLine(quote.Dialog);
}
The client also has a method to get quotes for a single movie, taking the Id of the movie:
var quotesForMovie = client.QuotesForMovie(movie.Id);
await foreach (var quote in quotesForMovie)
{
Console.WriteLine(quote.Dialog);
}
The async enumerables that are returned from the Movies
, Quotes
and QuotesForMovie
have helper functions to count the number of items and retrieve a single item by Id:
var count = await Movies.CountAsync();
var fellowshipOfTheRings = await Movies.GetAsync("5cd95395de30eff6ebccde5c");
You can also use System.Linq.Async
on the async enumerables:
dotnet add package System.Linq.Async
var first = await movies.FirstAsync();
Building and testing the SDK
This repo contains a devcontainer
configuration, so can be run in either GitHub codespaces, or locally using a remote container in VS Code. To run locally you will need Docker installed.
The dev container is configured with .NET 7.0 as well as all the recommended extensions. If you want to build locally, you will need .NET 7.0 installed. Instructions to do this are in the DotNet documentation.
This repo has 3 projects:
Mellon
- The SDKMellon.Test
- Unit tests for the SDKMellon.IntegrationTest
- Integration tests for the SDK that hit The One API endpoint You can build and run the tests as normal:
dotnet build
dotnet test
The integration tests need an API key to work as they query the API. This needs to be set as a user secret, or set in the configuration.json
file in the Mellon.IntegrationTest
project.
cd Mellon.IntegrationTest
dotnet user-secrets set "TheOneApi:apiKey" "<api key>"
Contributing to this project
Want to add the rest of the APIs? That would be awesome.
- Start by raising an issue so we can track the work.
- Fork the repo and make your change
- Raise a PR. This repo is configured to run all the unit and integration tests before allowing a PR through, so make sure your tests work!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.