1
1
# DiscogsClient
2
2
3
3
[ ![ Build status] ( https://img.shields.io/appveyor/ci/David-Desmaisons/DiscogsClient.svg?maxAge=2592000 )] ( https://ci.appveyor.com/project/David-Desmaisons/DiscogsClient )
4
- [ ![ NuGet Badge] ( https://buildstats.info /nuget/DiscogsClient )] ( https://www.nuget.org/packages/DiscogsClient/ )
4
+ [ ![ NuGet Badge] ( https://img.shields.io /nuget/v/ DiscogsClient.svg )] ( https://www.nuget.org/packages/DiscogsClient/ )
5
5
[ ![ MIT License] ( https://img.shields.io/github/license/David-Desmaisons/DiscogsClient.svg )] ( https://github.com/David-Desmaisons/DiscogsClient/blob/master/LICENSE )
6
6
7
7
8
8
C# Client library for [ Discogs API v2.0] ( https://www.discogs.com/developers/ )
9
9
10
- Nuget [ here] ( https://www.nuget.org/packages/DiscogsClient/ )
11
-
12
10
## Features
13
11
* Include API to authorize user (generating OAuth1.0 token and token secret)
14
12
* Full support to [ DataBase API] ( https://www.discogs.com/developers/#page:database ) including image download
@@ -19,81 +17,89 @@ Nuget [here](https://www.nuget.org/packages/DiscogsClient/)
19
17
20
18
## Sample usage
21
19
22
- #### Create discogs client
20
+ ### Create discogs client
23
21
22
+ * Oauth authentication
24
23
``` C#
25
24
// Create authentication object using private and public keys: you should fournish real keys here
26
25
var oAuthCompleteInformation = new OAuthCompleteInformation (" consumerKey" ,
27
26
" consumerSecret" , " token" , " tokenSecret" );
28
27
// Create discogs client using the authentication
29
28
var discogsClient = new DiscogsClient (oAuthCompleteInformation );
30
29
```
30
+ * Token based authentication
31
+ ``` C#
32
+ // Create authentication based on Discogs token
33
+ var tokenInformation = new TokenAuthenticationInformation (" my-token" );
34
+ // Create discogs client using the authentication
35
+ var discogsClient = new DiscogsClient (tokenInformation );
36
+ ```
31
37
#### Search The DataBase
32
38
33
39
Using IObservable:
34
40
``` C#
35
- var discogsSearch = new DiscogsSearch ()
36
- {
37
- artist = " Ornette Coleman" ,
38
- release_title = " The Shape Of Jazz To Come"
39
- };
41
+ var discogsSearch = new DiscogsSearch ()
42
+ {
43
+ artist = " Ornette Coleman" ,
44
+ release_title = " The Shape Of Jazz To Come"
45
+ };
40
46
41
- // Retrieve observable result from search
42
- var observable = _DiscogsClient .Search (discogsSearch );
47
+ // Retrieve observable result from search
48
+ var observable = _DiscogsClient .Search (discogsSearch );
43
49
```
44
50
45
51
Using IEnumerable:
46
52
``` C#
47
- // Alternatively retreive same result as enumerable
48
- var enumerable = _DiscogsClient .SearchAsEnumerable (discogsSearch );
53
+ // Alternatively retreive same result as enumerable
54
+ var enumerable = _DiscogsClient .SearchAsEnumerable (discogsSearch );
49
55
```
50
56
51
57
#### Get Release, Master, Artist or Label Information
52
58
``` C#
53
- var release = await _DiscogsClient .GetRelease (1704673 );
59
+ var release = await _DiscogsClient .GetReleaseAsync (1704673 );
54
60
```
55
61
56
62
``` C#
57
- var master = await _DiscogsClient .GetMaster (47813 );
63
+ var master = await _DiscogsClient .GetMasterAsync (47813 );
58
64
```
59
65
60
66
``` C#
61
- var artist = await _DiscogsClient .GetArtist (224506 );
67
+ var artist = await _DiscogsClient .GetArtistAsync (224506 );
62
68
```
63
69
64
70
``` C#
65
- var label = await _DiscogsClient .GetLabel (125 );
71
+ var label = await _DiscogsClient .GetLabelAsync (125 );
66
72
```
67
73
68
74
#### Download Image
69
75
``` C#
70
- // Retrieve Release information
71
- var res = await _DiscogsClient .GetMaster (47813 );
76
+ // Retrieve Release information
77
+ var res = await _DiscogsClient .GetMasterAsync (47813 );
72
78
73
- // Download the first image of the release
74
- await _DiscogsClient .SaveImage (res .images [0 ], Path .GetTempPath (), " Ornette-TSOAJTC" );
79
+ // Download the first image of the release
80
+ await _DiscogsClient .SaveImageAsync (res .images [0 ], Path .GetTempPath (), " Ornette-TSOAJTC" );
75
81
```
76
82
77
- #### Authorize new user
83
+ #### OAuth: Authorize new user
78
84
``` C#
79
- // Create authentificator information: you should fournish real keys here
80
- var oAuthConsumerInformation = new OAuthConsumerInformation (" consumerKey" , " consumerSecret" );
85
+ // Create authentificator information: you should fournish real keys here
86
+ var oAuthConsumerInformation = new OAuthConsumerInformation (" consumerKey" , " consumerSecret" );
81
87
82
- // Create Authentifier client
83
- var discogsAuthentifierClient = new DiscogsAuthentifierClient (oAuthConsumerInformation );
88
+ // Create Authentifier client
89
+ var discogsAuthentifierClient = new DiscogsAuthentifierClient (oAuthConsumerInformation );
84
90
85
- // Retreive Token and Token secret
86
- var aouth = discogsClient .Authorize (s => Task .FromResult (GetToken (s ))).Result ;
91
+ // Retreive Token and Token secret
92
+ var oauth = discogsClient .Authorize (s => Task .FromResult (GetToken (s ))).Result ;
87
93
```
88
94
89
95
Authorize takes a Func< string, Task< string>> as parameter, receiving the authentication url and returning the corresponding access key. Trivial implementation:
90
96
91
97
``` C#
92
- private static string GetToken (string url )
93
- {
94
- Console .WriteLine (" Please authorize the application and enter the final key in the console" );
95
- Process .Start (url );
96
- return Console .ReadLine ();
97
- }
98
+ private static string GetToken (string url )
99
+ {
100
+ Console .WriteLine (" Please authorize the application and enter the final key in the console" );
101
+ Process .Start (url );
102
+ return Console .ReadLine ();
103
+ }
98
104
```
99
105
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 commit comments