TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2017 |
Maintained by Maxime Epain.
An Objective-C interface for Discogs API v2.0.
The implementation is based on RestKit v0.27.0.
pod 'DiscogsAPI'
If you want to try it, simply run:
pod try DiscogsAPI
Or clone the repo and run pod install
from the Example directory first.
Configure the .plist for your project:
Right-click your .plist file and choose "Open As Source Code".
Copy & Paste the XML snippet into the body of your file (<dict>...</dict>
). You can use rather the key/secret pair or your personal access token (you can create them in your profile settings).
Replace DISCOGS_APP_CONSUMER_KEY and DISCOGS_APP_CONSUMER_SECRET with your Discogs App consumer key and secret.
<key>DiscogsConsumerKey</key>
<string>DISCOGS_APP_CONSUMER_Key</string>
<key>DiscogsConsumerSecret</key>
<string>DISCOGS_APP_CONSUMER_SECRET</string>
Replace DISCOGS_PERSONAL_ACCESS_TOKEN by you personal access token.
<key>DiscogsAccessToken</key>
<string>DISCOGS_PERSONAL_ACCESS_TOKEN</string>
Discogs supports two authentication methods: The Discogs Auth and OAuth. Please refer to the documentation for more details.
The key/secret or your personal access token will be automatically retrieved from your project configuration and used in your request headers. Nothing to be done on your side.
OAuth process is all handled by the 'authentication' endpoint. You just have to show the 'authView' view to let the user enter his credentials and authorize the application. The token will be automatically stored in the keychains.
[Discogs.api.authentication authenticateWithPreparedAuthorizationViewHandler:^(UIView *authView) {
// Show the authView
} success:^{
NSLog(@"The user has been successfully authentified");
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
The following examples shows how to access Discogs database objects through the api.
[Discogs.api.database getRelease:@249504 success:^(DGRelease *release) {
NSLog(@"Release: %@", release);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
[Discogs.api.database getMaster:@1000 success:^(DGMaster *master) {
NSLog(@"Master: %@", master);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
DGMasterVersionsRequest *request = [DGMasterVersionsRequest new];
request.masterID = @1000;
request.pagination.page = @3;
request.pagination.perPage = @25;
[Discogs.api.database getMasterVersion:request success:^(DGMasterVersionsResponse *response) {
NSLog(@"Versions: %@", response.versions);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
[Discogs.api.database getArtist:@108713 success:^(DGArtist *artist) {
NSLog(@"Artist: %@", artist);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
DGArtistReleasesRequest *request = [DGArtistReleasesRequest new];
request.artistID = @108713;
request.pagination.page = @3;
request.pagination.perPage = @25;
[Discogs.api.database getArtistReleases:request success:^(DGArtistReleasesResponse *response) {
NSLog(@"Releases: %@", response.releases);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
[Discogs.api.database getLabel:@1 success:^(DGLabel *label) {
NSLog(@"Label: %@", label);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
DGLabelReleasesRequest *request = [DGLabelReleasesRequest new];
request.labelID = @1;
request.pagination.page = @3;
request.pagination.perPage = @25;
[Discogs.api.database getLabelReleases:request success:^(DGLabelReleasesResponse *response) {
NSLog(@"Releases: %@", response.releases);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
DGSearchRequest *request = [DGSearchRequest new];
request.query = @"Cool band";
request.type = @"artist";
request.pagination.perPage = @25;
[Discogs.api.database searchFor:request success:^(DGSearchResponse *response) {
NSLog(@"Results: %@", response.results);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
From a paginated response, loading the next page is made easy by the DGPaginated
protocol:
[response loadNextPageWithSuccess:^{
// Update UI
} failure:^(NSError * _Nullable error) {
NSLog(@"Error : %@", error);
}];
Detailed usage instructions are available in the Wiki.
Documentation is available through CocoaDocs
DiscogsAPI is available under MIT License. See the LICENSE for more info.