JimBobBennett.Mellon 0.1.33

dotnet add package JimBobBennett.Mellon --version 0.1.33                
NuGet\Install-Package JimBobBennett.Mellon -Version 0.1.33                
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="JimBobBennett.Mellon" Version="0.1.33" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JimBobBennett.Mellon --version 0.1.33                
#r "nuget: JimBobBennett.Mellon, 0.1.33"                
#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 JimBobBennett.Mellon as a Cake Addin
#addin nuget:?package=JimBobBennett.Mellon&version=0.1.33

// Install JimBobBennett.Mellon as a Cake Tool
#tool nuget:?package=JimBobBennett.Mellon&version=0.1.33                

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.

A meme of Bilbo Baggins running with the caption hobbit fans accessing the lord of the rings API

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

A meme of Boromir with the caption one does not simply access the API without 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>));

A meme of Frodo Baggins with the caption all right then, keep your user secrets

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 movies
  • Quotes - 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");

A meme of Bilbo Baggins looking at the One ring with the caption after all why shouldn't I use system.linq.async

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 4 projects:

  • Mellon - The SDK
  • Mellon.Test - Unit tests for the SDK
  • Mellon.IntegrationTest - Integration tests for the SDK that hit The One API endpoint
  • Mellon.Sample - A sample app where you can select a movie and it shows a random movie quote

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

A meme of Frodo saying I will contribute to this repo

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
0.1.33 176 5/1/2023
0.1.31 136 5/1/2023
0.1.29 163 4/29/2023
0.1.27 173 4/29/2023
0.1.24 161 4/29/2023
0.1.22 171 4/29/2023
0.1.0 158 4/29/2023
0.0.1 175 4/29/2023