mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 07:13:09 +01:00
Merge branch 'master' into syro
This commit is contained in:
commit
e99ba1fb77
3
.gitignore
vendored
3
.gitignore
vendored
@ -161,3 +161,6 @@ pip-log.txt
|
|||||||
|
|
||||||
# Mac crap
|
# Mac crap
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# ignore html files in the root, all are generated by VS or subl
|
||||||
|
/*.html
|
||||||
|
86
README.md
86
README.md
@ -4,28 +4,82 @@ MIT licensed. Maintained by [@rikkilt](http://twitter.com/rikkilt).
|
|||||||
|
|
||||||
Feature request? Bug? Or just wanna help out? Check out [the issues on GitHub](https://github.com/inflatablefriends/lastfm/issues).
|
Feature request? Bug? Or just wanna help out? Check out [the issues on GitHub](https://github.com/inflatablefriends/lastfm/issues).
|
||||||
|
|
||||||
If you have comments or need some help, just post to our chat room on [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/inflatablefriends/lastfm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
If you have comments or need some help, post to our chat room on [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/inflatablefriends/lastfm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||||
|
|
||||||
## Quickstart
|
|
||||||
|
|
||||||
```c#
|
|
||||||
var auth = new Auth("apikey", "apisecret");
|
|
||||||
var response = await auth.GetSessionTokenAsync("username", "pass");
|
|
||||||
|
|
||||||
if (response.Success && auth.HasAuthenticated) {
|
|
||||||
var albumApi = new AlbumApi(auth);
|
|
||||||
var visions = await albumApi.GetAlbumInfoAsync("Grimes", "Visions");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Some documentation is available on the [GitHub wiki](https://github.com/rikkit/lastfm-wp/wiki), but hopefully the source is good enough to document itself!
|
|
||||||
|
|
||||||
## Project Goals
|
## Project Goals
|
||||||
|
|
||||||
- Provide complete, and completely tested, bindings for the Last.fm REST API for use on modern .NET platforms.
|
- Provide complete, and completely tested, bindings for the Last.fm REST API for use on modern .NET platforms.
|
||||||
- Provide functionality beyond mere API bindings, to spread the joy of Last.fm to developers everywhere.
|
- Provide functionality beyond API bindings, to spread the joy of Last.fm to developers everywhere.
|
||||||
- To be the very best, like no-one ever was.
|
- To be the very best, like no-one ever was.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
### Acquiring the SDK
|
||||||
|
|
||||||
|
You can either:
|
||||||
|
|
||||||
|
- clone this repo and build from source, referencing IF.Lastfm.Core in your project (requires a version of Visual Studio that supports portable class libraries - i.e. any version of VS 2012/2013 *except* 2012 Express)
|
||||||
|
- download and reference the .dlls from the [latest release](https://github.com/inflatablefriends/lastfm/releases)
|
||||||
|
|
||||||
|
A NuGet package is coming soon.
|
||||||
|
|
||||||
|
### Using the SDK
|
||||||
|
|
||||||
|
Once IF.Lastfm.Core is referenced, it's pretty simple to get started. First, sign up for Last.fm API access if you haven't already
|
||||||
|
|
||||||
|
This is how to get album info:
|
||||||
|
|
||||||
|
```c#
|
||||||
|
var auth = new LastAuth("apikey", "apisecret");
|
||||||
|
var albumApi = new AlbumApi(auth); // this is an unauthenticated call to the API
|
||||||
|
var response = await albumApi.GetAlbumInfoAsync("Grimes", "Visions");
|
||||||
|
var visions = response.Content; // visions is a LastAlbum
|
||||||
|
```
|
||||||
|
|
||||||
|
For methods that return several items, you can simply iterate over the response
|
||||||
|
|
||||||
|
```c#
|
||||||
|
var pageResponse = await artistApi.GetTopTracksForArtistAsync("Ben Frost", page: 5, itemsPerPage: 100);
|
||||||
|
|
||||||
|
foreach (var wallOfSound in pageResponse)
|
||||||
|
{
|
||||||
|
// wallOfSound is a LastTrack
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Several API methods require user authentication. Once you have your user's Last.fm username and password:
|
||||||
|
|
||||||
|
```c#
|
||||||
|
var auth = new LastAuth("apikey", "apisecret");
|
||||||
|
|
||||||
|
// wait for authentication
|
||||||
|
var response = await auth.GetSessionTokenAsync("username", "pass");
|
||||||
|
|
||||||
|
if (response.Success && auth.HasAuthenticated) {
|
||||||
|
var trackApi = new TrackApi(auth);
|
||||||
|
var loved = await trackApi.LoveTrackAsync("CIRCLONT6A [141.98][Syrobonkus mix]", "Aphex Twin");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Some documentation is available on the [GitHub wiki](https://github.com/rikkit/lastfm-wp/wiki). You can also check the Windows Phone demo project for some example code.
|
||||||
|
|
||||||
|
Any problems, just ask in [Gitter](https://gitter.im/inflatablefriends/lastfm).
|
||||||
|
|
||||||
|
## 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;
|
||||||
|
```
|
||||||
|
|
||||||
## Implemented Features
|
## Implemented Features
|
||||||
|
|
||||||
Check the [progress report](https://github.com/inflatablefriends/lastfm/blob/master/PROGRESS.md) for a list of implemented methods.
|
Check the [progress report](https://github.com/inflatablefriends/lastfm/blob/master/PROGRESS.md) for a list of implemented methods.
|
||||||
|
@ -24,7 +24,7 @@ public async override Task<T> ExecuteAsync()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
var httpClient = GetHttpClient();
|
||||||
var response = await httpClient.GetAsync(Url);
|
var response = await httpClient.GetAsync(Url);
|
||||||
return await HandleResponse(response);
|
return await HandleResponse(response);
|
||||||
}
|
}
|
||||||
|
@ -54,5 +54,16 @@ protected void DisableCaching()
|
|||||||
|
|
||||||
public abstract Task<T> HandleResponse(HttpResponseMessage response);
|
public abstract Task<T> HandleResponse(HttpResponseMessage response);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
protected HttpClient GetHttpClient()
|
||||||
|
{
|
||||||
|
var client = new HttpClient();
|
||||||
|
|
||||||
|
// See http://stackoverflow.com/questions/14595021/how-to-disable-the-expect-100-continue-header-in-winrts-httpwebrequest
|
||||||
|
client.DefaultRequestHeaders.ExpectContinue = false;
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ public override async Task<T> ExecuteAsync()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
var httpClient = GetHttpClient();
|
||||||
var response = await httpClient.PostAsync(Url, postContent);
|
var response = await httpClient.PostAsync(Url, postContent);
|
||||||
return await HandleResponse(response);
|
return await HandleResponse(response);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user