Scrobbling documentation #61

This commit is contained in:
Rikki Tooley 2015-04-05 00:46:02 +01:00
parent 8a04cde0f4
commit 82cfb8574f
3 changed files with 83 additions and 18 deletions

View File

@ -66,25 +66,11 @@ Some documentation is available on the [GitHub wiki](https://github.com/rikkit/l
Any problems, just ask in [Gitter](https://gitter.im/inflatablefriends/lastfm).
## Dependency Injection
## Documentation
The SDK is built to work with IoC libraries like MvvmLight and Ninject. To inject an API as a dependency to a viewmodel, you just need to register ```ILastAuth``` to an instance of ```LastAuth```:
```c#
// mvvmlight
var auth = new LastAuth("apikey", "apisecret");
SimpleIoc.Default.Register<ILastAuth>(() => auth);
// ...
var artistApi = ServiceLocator.Current.GetInstance<ArtistApi>();
var response = await artistApi.GetArtistInfoAsync("The Knife");
var theKnife = artist.Content;
```
## Implemented Features
Check the [progress report](https://github.com/inflatablefriends/lastfm/blob/master/PROGRESS.md) for a list of implemented methods.
- [Api method progress report](PROGRESS.md)
- [Scrobbling](doc/scrobbling.md)
- [Dependency Injection](doc/dependency-injection.md)
## Planned Features

View File

@ -0,0 +1,15 @@
# Dependency Injection
The SDK is built to work with IoC libraries like MvvmLight and Ninject. To inject an API as a dependency to a viewmodel, you just need to register ```ILastAuth``` to an instance of ```LastAuth```:
```c#
// mvvmlight
var auth = new LastAuth("apikey", "apisecret");
SimpleIoc.Default.Register<ILastAuth>(() => auth);
// ...
var artistApi = ServiceLocator.Current.GetInstance<ArtistApi>();
var response = await artistApi.GetArtistInfoAsync("The Knife");
var theKnife = artist.Content;
```

64
doc/scrobbling.md Normal file
View File

@ -0,0 +1,64 @@
# Scrobbling
## Quickstart
Create the scrobbler class:
```c#
var auth = new LastAuth(key, secret);
var scrobbler = new Scrobbler(auth);
```
Or if using a SQLite database:
```c#
var scrobbler = new SQLiteScrobbler(auth, databasePath);
```
then
```c#
var scrobble = new Scrobble("65daysofstatic", "The Fall of Math", "Hole", DateTimeOffset.UtcNow);
var response = await scrobbler.ScrobbleAsync();
if (response.Success)
{
// The scrobble was either successfully sent or has been cached to be sent later.
bool scrobbleCached = response.Status == LastResponseStatus.Cached;
}
else
{
if (response.Status == LastResponseStatus.RequestFailed)
{
// response.Exception contains info on the http request failing
}
else if (response.Status == LastResponseStatus.CacheFailed)
{
// response.Exception contains info on the caching mechanism failing
}
}
```
## Extensibility
```IF.Lastfm.Core.Scrobblers.Scrobbler```, the core implementation of IScrobbler doesn't cache failed requests.
The ```ScrobblerBase``` class provides the mechanism for caching scrobbles. Classes deriving it may implement scrobble caching using an external database - if the scrobble request fails, then it will be saved to a database to be sent later. Currently, any cached scrobbles can either be sent when ```ScrobbleAsync(Scrobble s)``` is next called, or independently by calling ```SendCachedScrobblesAsync()```.
### SQLite
The ```IF.Lastfm.SQLite.SQLiteScrobbler``` class enables scrobble caching using a SQLite database.
This is in the NuGet package:
```
Install-Package Inflatable.Lastfm.SQLite
```
Dependencies:
- Newtonsoft.JSON
- Inflatable.Lastfm
- sqlite-net-pcl