Discogs-ObjC 0.1.1

Discogs-ObjC 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

未认领 维护。



 
依赖
DCKeyValueObjectMapping~> 1.4
AFNetworking~> 2.0
 

  • 作者
  • Nathaniel Jones

为 Discogs API v2.0 (http://discogs.com/developers/index.html)提供的 Objective-C 封装

使用 AFNetworking 2.0 和 KeyValueObjectMapper 1.4 封装对 Discogs 2.0 API 的请求。

特性

  • 目前支持艺术家、发布、母盘、标签和搜索请求
  • 将响应封装在格式良好的对象中
  • 所有属性都只读
  • 仅使用 blocks 进行异步请求

安装

  • 安装 Cocoapods - 在终端中键入

    [sudo] gem install cocoapods
    pod setup
    
  • 在项目根目录下创建一个名为 podfile 的文件

  • 将以下内容添加到 podfile

    platform :ios '6.0'
    pod 'Discogs-ObjC'
    
  • 在终端中键入

    pod install
    

用法

入门

导入头文件

#import "Discogs-ObjC.h"

在您的 AppDelegate.m 文件中,向 didFinishLaunchingWithOptions 添加以下一行。这将定义用于 API 的用户代理。

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

获取艺术家

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

获取艺术家的发行

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

获取发行

    DCDiscogsApiClient *client = [DCDiscogsApiClient new];
    [client getReleaseWithBlock:1 success:^(DCRelease *release) {

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

    } failure:^(NSError *error) {

        NSLog(@"Error %@", error.debugDescription);

    }];

获取母盘

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

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

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

    }];

获取母盘的版本

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

    }];

获取标签

    DCDiscogsApiClient *client = [DCDiscogsApiClient new];
    [client getLabelWithBlock:1 success:^(DCLabel *label) {

        NSLog(@"%@", label.name);

    } failure:^(NSError *error) {

        NSLog(@"Error %@", error.debugDescription);

    }];

获取标签的发行

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

    }];

发起搜索请求

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

    }];