Giter Club home page Giter Club logo

discogs-objc's Introduction

Discogs-ObjC

An Objective-C wrapper for the Discogs API v2.0 (http://discogs.com/developers/index.html)

Uses AFNetworking 2.0 and KeyValueObjectMapper 1.4 to wrap requests to the Discogs 2.0 API.

Features

  • Currently supports Artist, Release, Master, Label and Search requests
  • Wraps responses in well formatted objects
  • Keeps all properties read only
  • Async-only requests using blocks
  • Must generate a developer token on Discogs

Installation

  • Install Cocoapods - in terminal type:

      [sudo] gem install cocoapods
      pod setup
    
  • Create a file called podfile in your project root

  • Add following text to your podfile:

      platform :ios '6.0'
      pod 'Discogs-ObjC'
    
  • In terminal, type

      pod install
    

Usage

Getting Started

Import the header file

#import "Discogs-ObjC.h"

In your AppDelegate.m file add the following line to didFinishLaunchingWithOptions. This will define your user agent to be used against the API.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [DCDiscogsApiConfiguration setUserAgent:@"My User Agent" andTokenString:"My Token"];
    return YES;
}

Retrieving an Artist

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
    [client getArtistWithBlock:45
                       success:^(DCArtist *artist) {
                           NSLog(@"%@", artist.name);
                       } failure:^(NSError *error) {
                           NSLog(@"Error %@", error.debugDescription);
                       }];

Retrieving and Artist's Releases

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
    [client getArtistReleasesWithBlock:45 forPage:1 withNumberOfResults:10 success:^(DCArtistReleases *releases) {
        
        for (DCArtistRelease *release in releases.releases) {
            NSLog(@"%@", release.title);
        }
        
    } failure:^(NSError *error) {
        
        NSLog(@"Error %@", error.debugDescription);
    }];

Retrieving a Release

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
	[client getReleaseWithBlock:1 success:^(DCRelease *release) {
        
        NSLog(@"%@", release.title);
        
    } failure:^(NSError *error) {
        
        NSLog(@"Error %@", error.debugDescription);
        
    }];

Retrieving a Master

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
	[client getMasterWithBlock:5427 success:^(DCMaster *master) {
        
        NSLog(@"%@", master.title);
        
    } failure:^(NSError *error) {
        NSLog(@"Error %@", error.debugDescription);
        
    }];

Retrieving a Versions of a Master

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
	[client getMasterVersionsWithBlock:5427 forPage:1 withNumberOfResults:10 success:^(DCMasterVersions *versions) {
        NSLog(@"%lu", (unsigned long)[versions.versions count]);
        
        for (DCMasterVersion *master in versions.versions) {
            NSLog(@"%@", master.title);
        }
        
    } failure:^(NSError *error) {
        
        NSLog(@"Error %@", error.debugDescription);
        
    }];

Retrieving a Label

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
	[client getLabelWithBlock:1 success:^(DCLabel *label) {
        
        NSLog(@"%@", label.name);
        
    } failure:^(NSError *error) {
        
        NSLog(@"Error %@", error.debugDescription);
        
    }];

Retrieving a Label's Releases

	DCDiscogsApiClient *client = [DCDiscogsApiClient new];
	[client getLabelReleasesWithBlock:1 forPage:1 withNumberOfResults:10 success:^(DCLabelReleases *releases) {
        
        for (DCLabelRelease *release in releases.releases) {
            NSLog(@"%@", release.title);
        }

    } failure:^(NSError *error) {
        
        NSLog(@"Error %@", error.debugDescription);
        
    }];

Making a Search Request

	DCSearchRequest *search = [DCSearchRequest new];
    search.query = @"Rolling Stones";
    search.searchType = artist;
    
    DCDiscogsApiClient *client = [DCDiscogsApiClient new];
    [client getSearchResultsWithBlock:search forPage:1 withNumberOfResults:10 success:^(DCSearchResults *results) {
        
        for (DCSearchResult *result in results.results) {
            NSLog(@"%@", result.title);
        }
        
    } failure:^(NSError *error) {
        
        NSLog(@"Error %@", error.debugDescription);
        
    }];

discogs-objc's People

Contributors

n8j1s avatar ryleysill93 avatar

Stargazers

Steven David avatar Dmitry Volevodz avatar Slavo avatar Dustin avatar Vincent Garrigues avatar Jesse Read avatar Jonathan Crooke avatar Ullrich Schäfer avatar Thomas Heß avatar Max Desiatov avatar

Watchers

 avatar James Cloos avatar Mustafa Kamal Ismail Ahmed avatar Yoash Adato avatar

discogs-objc's Issues

Add support for authenticated Discogs endpoints

It would be great if this library supports not only the public endpoints, but also the ones which retrieve user-specific information from discos and require authentication (user identity, collection, want list). I am mainly creating this issue to know if there are plans for this. I am new to Obj-C myself, but if I play long enough I may submit a PR for this.

Missing files?

Hi,

DCKeyValueObjectMapping.h & DCArrayMapping.h are missing ?

Regards

Search requests are all failing with 401 unauthorized

It seems like the search requests this library seems to support require authentication with Discogs. Is there any way I can authenticate so my requests will work, or was this requirement introduced after the development of this library (a breaking change)?

Thanks!

Crashing on -(void)getMasterWithBlock:(NSUInteger)masterId

I installed the cocoaPod and and was testing your service calls because I want to use your wrapper. All the sample calls you provide work well expect getMasterWithBlock :

DCDiscogsApiClient *client = [DCDiscogsApiClient new];
[client getMasterWithBlock:5427 success:^(DCMaster *master) {

    NSLog(@"%@", master.title);

} failure:^(NSError *error) {
    NSLog(@"Error %@", error.debugDescription);

}];

I am getting the following crash:

Terminating app due to uncaught exception 'NSRangeException', reason: '-[**NSCFConstantString substringWithRange:]: Range {0, 1} out of bounds; string length 0'
* First throw call stack:
(
0 CoreFoundation 0x019eb5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0176e8b6 objc_exception_throw + 44
2 CoreFoundation 0x019eb3bb +[NSException raise:format:] + 139
3 CoreFoundation 0x019c45e8 -[__NSCFString substringWithRange:] + 136
4 DiscogsSample 0x0004bcd1 -[DCReferenceKeyParser splitKeyAndMakeCamelcased:] + 577
5 DiscogsSample 0x0004aebf -[DCPropertyFinder findAttributeForKey:onClass:] + 319
6 DiscogsSample 0x0004511d -[DCKeyValueObjectMapping setValuesOnObject:withDictionary:] + 813
7 DiscogsSample 0x00044d6a -[DCKeyValueObjectMapping parseDictionary:forParentObject:] + 314
8 DiscogsSample 0x000449a3 -[DCKeyValueObjectMapping parseArray:forParentObject:] + 563
9 DiscogsSample 0x000469e5 -[DCNSArrayConverter transformValue:forDynamicAttribute:dictionary:parentObject:] + 917
10 DiscogsSample 0x000439b1 -[DCGenericConverter parseValueForParsers:forDynamicAttribute:dictionary:parentObject:] + 705
11 DiscogsSample 0x0004363a -[DCGenericConverter parseSimpleValue:forDynamicAttribute:dictionary:parentObject:] + 314
12 DiscogsSample 0x00042f25 -[DCGenericConverter transformValue:forDynamicAttribute:dictionary:parentObject:] + 901
13 DiscogsSample 0x00045d50 -[DCKeyValueObjectMapping parseValue:forObject:inAttribute:dictionary:] + 496
14 DiscogsSample 0x00045186 -[DCKeyValueObjectMapping setValuesOnObject:withDictionary:] + 918
15 DiscogsSample 0x00044d6a -[DCKeyValueObjectMapping parseDictionary:forParentObject:] + 314
16 DiscogsSample 0x00044be5 -[DCKeyValueObjectMapping parseDictionary:] + 101
17 DiscogsSample 0x0005179c -[DCMaster initWithDictionary:] + 940
18 DiscogsSample 0x0004e7dd __57-[DCDiscogsApiClient getMasterWithBlock:success:failure:]_block_invoke + 157
19 DiscogsSample 0x0000472b __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke46 + 43
20 libdispatch.dylib 0x01d827f8 _dispatch_call_block_and_release + 15
21 libdispatch.dylib 0x01d974b0 _dispatch_client_callout + 14
22 libdispatch.dylib 0x01d8575e _dispatch_main_queue_callback_4CF + 340
23 CoreFoundation 0x01a50a5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
+ 14
24 CoreFoundation 0x019916bb __CFRunLoopRun + 1963
25 CoreFoundation 0x01990ac3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x019908db CFRunLoopRunInMode + 123
27 GraphicsServices 0x0365f9e2 GSEventRunModal + 192
28 GraphicsServices 0x0365f809 GSEventRun + 104
29 UIKit 0x004dcd3b UIApplicationMain + 1225
30 DiscogsSample 0x000031dd main + 141
31 libdyld.dylib 0x0202970d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

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.