Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Desmaisons committed Mar 24, 2017
2 parents b56cdd9 + 1a9642d commit 1a05786
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# DiscogsClient

[![Build status](https://img.shields.io/appveyor/ci/David-Desmaisons/DiscogsClient.svg?maxAge=2592000)](https://ci.appveyor.com/project/David-Desmaisons/DiscogsClient)
[![NuGet Badge](https://buildstats.info/nuget/DiscogsClient)](https://www.nuget.org/packages/DiscogsClient/)
[![NuGet Badge](https://img.shields.io/nuget/v/DiscogsClient.svg)](https://www.nuget.org/packages/DiscogsClient/)
[![MIT License](https://img.shields.io/github/license/David-Desmaisons/DiscogsClient.svg)](https://github.com/David-Desmaisons/DiscogsClient/blob/master/LICENSE)


C# Client library for [Discogs API v2.0](https://www.discogs.com/developers/)

Nuget [here](https://www.nuget.org/packages/DiscogsClient/)

## Features
* Include API to authorize user (generating OAuth1.0 token and token secret)
* Full support to [DataBase API](https://www.discogs.com/developers/#page:database) including image download
Expand All @@ -19,81 +17,89 @@ Nuget [here](https://www.nuget.org/packages/DiscogsClient/)

## Sample usage

#### Create discogs client
### Create discogs client

* Oauth authentication
```C#
//Create authentication object using private and public keys: you should fournish real keys here
var oAuthCompleteInformation = new OAuthCompleteInformation("consumerKey",
"consumerSecret", "token", "tokenSecret");
//Create discogs client using the authentication
var discogsClient = new DiscogsClient(oAuthCompleteInformation);
```
* Token based authentication
```C#
//Create authentication based on Discogs token
var tokenInformation = new TokenAuthenticationInformation("my-token");
//Create discogs client using the authentication
var discogsClient = new DiscogsClient(tokenInformation);
```
#### Search The DataBase

Using IObservable:
```C#
var discogsSearch = new DiscogsSearch()
{
artist = "Ornette Coleman",
release_title = "The Shape Of Jazz To Come"
};
var discogsSearch = new DiscogsSearch()
{
artist = "Ornette Coleman",
release_title = "The Shape Of Jazz To Come"
};

//Retrieve observable result from search
var observable = _DiscogsClient.Search(discogsSearch);
//Retrieve observable result from search
var observable = _DiscogsClient.Search(discogsSearch);
```

Using IEnumerable:
```C#
//Alternatively retreive same result as enumerable
var enumerable = _DiscogsClient.SearchAsEnumerable(discogsSearch);
//Alternatively retreive same result as enumerable
var enumerable = _DiscogsClient.SearchAsEnumerable(discogsSearch);
```

#### Get Release, Master, Artist or Label Information
```C#
var release = await _DiscogsClient.GetRelease(1704673);
var release = await _DiscogsClient.GetReleaseAsync(1704673);
```

```C#
var master = await _DiscogsClient.GetMaster(47813);
var master = await _DiscogsClient.GetMasterAsync(47813);
```

```C#
var artist = await _DiscogsClient.GetArtist(224506);
var artist = await _DiscogsClient.GetArtistAsync(224506);
```

```C#
var label = await _DiscogsClient.GetLabel(125);
var label = await _DiscogsClient.GetLabelAsync(125);
```

#### Download Image
```C#
//Retrieve Release information
var res = await _DiscogsClient.GetMaster(47813);
//Retrieve Release information
var res = await _DiscogsClient.GetMasterAsync(47813);

//Download the first image of the release
await _DiscogsClient.SaveImage(res.images[0], Path.GetTempPath(), "Ornette-TSOAJTC");
//Download the first image of the release
await _DiscogsClient.SaveImageAsync(res.images[0], Path.GetTempPath(), "Ornette-TSOAJTC");
```

#### Authorize new user
#### OAuth: Authorize new user
```C#
//Create authentificator information: you should fournish real keys here
var oAuthConsumerInformation = new OAuthConsumerInformation("consumerKey", "consumerSecret");
//Create authentificator information: you should fournish real keys here
var oAuthConsumerInformation = new OAuthConsumerInformation("consumerKey", "consumerSecret");

//Create Authentifier client
var discogsAuthentifierClient = new DiscogsAuthentifierClient(oAuthConsumerInformation);
//Create Authentifier client
var discogsAuthentifierClient = new DiscogsAuthentifierClient(oAuthConsumerInformation);

//Retreive Token and Token secret
var aouth = discogsClient.Authorize(s => Task.FromResult(GetToken(s))).Result;
//Retreive Token and Token secret
var oauth = discogsClient.Authorize(s => Task.FromResult(GetToken(s))).Result;
```

Authorize takes a Func< string, Task< string>> as parameter, receiving the authentication url and returning the corresponding access key. Trivial implementation:

```C#
private static string GetToken(string url)
{
Console.WriteLine("Please authorize the application and enter the final key in the console");
Process.Start(url);
return Console.ReadLine();
}
private static string GetToken(string url)
{
Console.WriteLine("Please authorize the application and enter the final key in the console");
Process.Start(url);
return Console.ReadLine();
}
```
See [DiscogsClientTest](https://github.com/David-Desmaisons/DiscogsClient/blob/master/DiscogsClient.Test/DiscogsClientTest.cs) and [DiscogsAuthenticationConsole](https://github.com/David-Desmaisons/DiscogsClient/blob/master/DiscogsAuthenticationConsole/Program.cs) for full samples of available APIs.

0 comments on commit 1a05786

Please sign in to comment.