测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2014年12月 |
由 未认领 维护。
依赖 | |
DCKeyValueObjectMapping | ~> 1.4 |
AFNetworking | ~> 2.0 |
为 Discogs API v2.0 (http://discogs.com/developers/index.html)提供的 Objective-C 封装
使用 AFNetworking 2.0 和 KeyValueObjectMapper 1.4 封装对 Discogs 2.0 API 的请求。
安装 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);
}];