GithubHelp home page GithubHelp logo

discogsapi's Introduction

DiscogsAPI

CI Status Version License Platform

An Objective-C interface for Discogs API v2.0.

The implementation is based on RestKit.

Features

  • Supports OAuth process and store the token in keychain.
  • Supports Discogs Auth.
  • Database support: Release, Master Release, Master Release Versions, Artist, Artist Releases, Label, All Label Releases, Search.
  • User support: Identify, Profile, Collection, Wantlist.
  • Marketplace: Inventory, Listing.
  • Image support.

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects.

Podfile
pod 'DiscogsAPI'

Usage

If you want to try it, simply run:

pod try DiscogsAPI

Or clone the repo and run pod install from the Example directory first.

Authentication

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).

Key/Secret

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>
Personal Access Token

Replace DISCOGS_PERSONAL_ACCESS_TOKEN by you personal access token.

<key>DiscogsAccessToken</key>
<string>DISCOGS_PERSONAL_ACCESS_TOKEN</string>

Authentication flow

Discogs supports two authentication methods: The Discogs Auth and OAuth. Please refer to the documentation for more details.

Discogs Auth

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

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);
    }];

Database

The following examples shows how to access Discogs database objects through the api.

Release
    [Discogs.api.database getRelease:@249504 success:^(DGRelease *release) {
        NSLog(@"Release: %@", release);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
Master Release
    [Discogs.api.database getMaster:@1000 success:^(DGMaster *master) {
        NSLog(@"Master: %@", master);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
Master Release Versions
    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);
    }];
Artist
    [Discogs.api.database getArtist:@108713 success:^(DGArtist *artist) {
        NSLog(@"Artist: %@", artist);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
Artist Releases
    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);
    }];
Label
    [Discogs.api.database getLabel:@1 success:^(DGLabel *label) {
        NSLog(@"Label: %@", label);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
Label Releases
    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);
    }];
Search
    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);
    }];

Pagination

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);
    }];

More usage

Detailed usage instructions are available in the Wiki.

Documentation

Documentation is available through CocoaDocs

Author

Maxime Epain

Twitter

License

DiscogsAPI is available under MIT License. See the LICENSE for more info.

discogsapi's People

Contributors

maxep avatar nrivard avatar ryonandesukedo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

discogsapi's Issues

Getting an OAuth error

Getting this error when trying the example:

This URL is an OAuth endpoint, but the request you made doesn't appear to
conform to the OAuth 1.0a protocol.

Please consult these resources:

    - Discogs OAuth docs: http://www.discogs.com/developers/#page:authentication
    - the OAuth specification: http://tools.ietf.org/html/rfc5849
    - the documentation for your OAuth library

for information on how to use this endpoint.

- Discogs, NSErrorFailingURLKey=https://api.discogs.com/oauth/request_token, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x15c6629d0> { URL: https://api.discogs.com/oauth/request_token }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x15c625fc0> { URL: https://api.discogs.com/oauth/request_token } { status code: 400, headers {
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "public, must-revalidate";
    Connection = close;
    "Content-Length" = 408;
    "Content-Type" = "text/plain";
    Date = "Sun, 04 Oct 2015 21:12:56 GMT";
    "Reproxy-Status" = yes;
    Server = lighttpd;
    "X-Discogs-Media-Type" = "discogs.v2";
} }, NSLocalizedDescription=Expected status code in (200-299), got 400}

Is there something I can do to get this working? I'm using Xcode 7.

I've also had to add this to the info.plist file

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

Errors using with xcode 7 and swift 2

Hi there maxine, trying to install the DiscogsAPI cocoapod into a project using Xcode Version 7.0 beta (7A121l) swift 2, using a podfile containing the following:

platform :ios, '7.1'
pod 'DiscogsAPI'
use_frameworks!
xcodeproj '/path to my actual project.xcodeproj'

Ignoring the warnings (46), I get 29 errors before it gives up, as follows. Would really appreciate any help you could give me!

Command /usr/bin/ditto failed with exit code 1
(null): Directory not found for option '-F/Users/haansplosion/Library/Developer/Xcode/DerivedData/MyApp-gzjulonionecwzdqoybpxhoopwbi/Build/Intermediates/SwiftMigration/MyApp/Products/Debug-iphonesimulator/Pods'
(null): Linker command failed with exit code 1 (use -v to see invocation)
Command /bin/sh failed with exit code 23
MyAppUITests Group
Command /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Command /usr/bin/ditto failed with exit code 1
(null): Linker command failed with exit code 1 (use -v to see invocation)
MyAppTests Group
(null): Linker command failed with exit code 1 (use -v to see invocation)

Pods-DiscogsAPI Group
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/ObjectMapping/RKObjectMapping.h
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/ObjectMapping/RKObjectMapping.h:23:9: Include of non-modular header inside framework module 'RestKit.RKObjectMapping'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/ObjectMapping.h
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/ObjectMapping.h:24:9: Include of non-modular header inside framework module 'RestKit.ObjectMapping'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/ObjectMapping.h:21:9: Could not build module 'RestKit'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Network/RKHTTPRequestOperation.h
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Network/RKHTTPRequestOperation.h:21:9: Include of non-modular header inside framework module 'RestKit.RKHTTPRequestOperation'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Network/RKHTTPRequestOperation.h:22:9: Include of non-modular header inside framework module 'RestKit.RKHTTPRequestOperation'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Network/RKObjectManager.h
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Network/RKObjectManager.h:24:9: Include of non-modular header inside framework module 'RestKit.RKObjectManager'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Vendor/LibComponentLogging/Core/lcl_RK.h
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Vendor/LibComponentLogging/Core/lcl_RK.h:134:1: Expected identifier
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Vendor/LibComponentLogging/Core/lcl_RK.h:134:1: Expected '}'
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Vendor/LibComponentLogging/Core/lcl_RK.h:130:31: Expected ';' after enum
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:52:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:53:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:54:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:55:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:56:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:57:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:58:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:59:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:60:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:61:1: Initializer element is not a compile-time constant
/Users/haansplosion/Dropbox/GIT/MyApp/MyApp/Pods/RestKit/Code/Support/lcl_config_components_RK.h:62:1: Initializer element is not a compile-time constant
Too many errors emitted, stopping now

Can't logout

You are storing credentials in multiple places, not niling out access tokens appropriately etc. I have modified the code to allow DGIdentity.current to be readwrite which does clear out the identity. but subsequent calls to identityWithSuccess succeed immediately when they shouldn't, we should be presented with oauth signin flow.

Fail to authenticate

Hi,
I am running DiscogsAPI example project, but I get lots of errors related to the authentication:

Unable to fetch credential with identifier "DGOAuthCredentialDiscogsAccount" (Error -25300)
2015-09-06 13:46:55.846 DiscogsAPI[2341:33891457] T restkit.network:RKObjectRequestOperation.m:148 GET 'https://api.discogs.com/oauth/identity':
request.headers={
Accept = "application/vnd.discogs.v2.discogs+json";
"Accept-Language" = "en-US;q=1";
Authorization = "Discogs key=My Discogs key, secret=My secret";
"User-Agent" = "DiscogsAPI/1 (iPhone; iOS 9.0; Scale/2.00)";
}

In the Info.plist I replaced DISCOGS_APP_CONSUMER_Key with my app's actual consumer key, and DISCOGS_APP_CONSUMER_SECRET with my app's actual consumer secret. I need only Discogs Auth while OAuth is not required by my app.

Did I miss anything in my configuration?

BTW, I am running on XCode 7 Beta 6 on iPhone 6 Simulator.

Delete of wantlist item returns an error even though it succeeded

Delete a wantlist item. I get a 204 (aka "success") yet i get back an error saying it expected 400 level status code?

Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (400-499), got 204" UserInfo={NSLocalizedRecoverySuggestion=, AFRKNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x618000008210> { URL: https://api.discogs.com/users/nrivard/wants/6686431?notes=&rating=0 }, NSErrorFailingURLKey=https://api.discogs.com/users/nrivard/wants/6686431?notes=&rating=0, AFRKNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x61000022d880> { URL: https://api.discogs.com/users/nrivard/wants/6686431?notes=&rating=0 } { status code: 204, headers {
    "Access-Control-Allow-Headers" = "Content-Type, authorization";
    "Access-Control-Allow-Methods" = "GET,PUT,POST,DELETE,PATCH";
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "public, must-revalidate";
    "Content-Length" = 0;
    "Content-Type" = "text/plain";
    Date = "Tue, 28 Mar 2017 03:13:06 GMT";
    Server = nginx;
    "Strict-Transport-Security" = "max-age=16000000";
    "X-Content-Type-Options" = nosniff;
    "X-Discogs-Media-Type" = "discogs.v2";
    "X-Discogs-Ratelimit" = 240;
    "X-Discogs-Ratelimit-Remaining" = 236;
    "X-Discogs-Ratelimit-Used" = 4;
    "X-Frame-Options" = SAMEORIGIN;
    "X-XSS-Protection" = "1; mode=block";
} }, NSLocalizedDescription=Expected status code in (400-499), got 204}

Do not return any Videos

In DGRelease class,

  • (NSArray *)videos{
    return [_videos filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"embed == true"]];
    }
    is not return DGVideo list.

property of "videos" is Array of DGVideo, so predicateWithFormat can't be worked.

Memory leak on every request to Discogs

I think this is a RestKit issue but I'm seeing memory leaks on every single request. Here's the callstack:

   0 libsystem_malloc.dylib malloc_zone_malloc
   1 libsystem_malloc.dylib malloc
   2 Foundation -[NSObject(NSKeyValueCoding) validateValue:forKey:error:]
   3 Foundation -[NSObject(NSKeyValueCoding) validateValue:forKeyPath:error:]
   4 RestKit -[RKMappingOperation validateValue:atKeyPath:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMappingOperation.m:561
   5 RestKit -[RKMappingOperation shouldSetValue:forKeyPath:usingMapping:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMappingOperation.m:586
   6 RestKit -[RKMappingOperation applyAttributeMapping:withValue:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMappingOperation.m:732
   7 RestKit -[RKMappingOperation applyAttributeMappings:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMappingOperation.m:782
   8 RestKit -[RKMappingOperation main] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMappingOperation.m:1240
   9 RestKit -[RKMapperOperation mapRepresentation:toObject:isNew:atKeyPath:usingMapping:metadataList:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMapperOperation.m:266
  10 RestKit -[RKMapperOperation mapRepresentation:atKeyPath:usingMapping:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMapperOperation.m:197
  11 RestKit -[RKMapperOperation mapRepresentationOrRepresentations:atKeyPath:usingMapping:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMapperOperation.m:0
  12 RestKit -[RKMapperOperation mapSourceRepresentationWithMappingsDictionary:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMapperOperation.m:383
  13 RestKit -[RKMapperOperation main] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/ObjectMapping/RKMapperOperation.m:422
  14 Foundation -[__NSOperationInternal _start:]
  15 RestKit -[RKObjectResponseMapperOperation performMappingWithObject:error:] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/Network/RKResponseMapperOperation.m:430
  16 RestKit -[RKResponseMapperOperation main] /Users/nrivard/Code/DiscogsAPI/Pods/RestKit/Code/Network/RKResponseMapperOperation.m:381
  17 Foundation -[__NSOperationInternal _start:]
  18 Foundation __NSOQSchedule_f
  19 libdispatch.dylib _dispatch_client_callout
  20 libdispatch.dylib _dispatch_continuation_pop
  21 libdispatch.dylib _dispatch_async_redirect_invoke
  22 libdispatch.dylib _dispatch_root_queue_drain
  23 libdispatch.dylib _dispatch_worker_thread3
  24 libsystem_pthread.dylib _pthread_wqthread
  25 libsystem_pthread.dylib start_wqthread

Xcode project for working on DiscogsAPI

Can we get an Xcode project so we can actually help contribute to this project? It seems a ton of stuff is broken (this for example: #4) and in order to fix them, there needs to be an Xcode project.

Authentication in auth view doesn't work with google login

My app was rejected by Apple because Google requires their login flow to occur in a system browser, not as part of a webview in a 3rd party app. Not sure what the best solution is here. Perhaps best to explore use of SFAuthenticationSession here, so SFSafariViewController will get automatically launched instead? Otherwise, everyone will have to kick out to regular Safari using the custom callback scheme.

Getting tons of keychain save failures on ios 10

(OSStatus) $13 = -34018
2016-09-19 20:19:39.116014 [38153:3716592] [] tcp_connection_cancel 6
2016-09-19 20:19:39.115 [38153:3690891] Unable to add credential with identifier "DGOAuthCredentialDiscogsAccount" (Error -34018)

I get the following error everytime i authorize via oauth on ios 10. The workaround noted here http://stackoverflow.com/questions/29740952/osstatus-error-code-34018 didn't work. Are you seeing tons of failures in new code compiled in xcode 8 on ios 10?

Rate-limiting ignored

My BatchReleases branch has some work to start to listen to rate-limiting but as it stands, DiscogsAPI just blasts the server with a million concurrent requests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.