Objective-C client for the Zotero API.
SZNZotero is a Zotero API client for iOS and Mac OS X, built on top of AFNetworking.
CocoaPods is the recommended way to add SZNZotero to your project. CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like SZNZotero in your projects.
Here’s an example podfile that installs SZNZotero and all its dependencies.
platform :ios, '5.0'
pod 'SZNZotero', '~> 0.3.4'
The Zotero API v2 uses 3leg OAuth 1.0 authentication. In order to gain access to protected resources, your application will open Mobile Safari and prompt for user credentials. iOS will then switch back to your application using a custom URL scheme. It means that you need to set it up in your Xcode project.
- Open the project editor, select your main target, click the Info button.
- Add a URL Type, and type a unique URL scheme (for instance ’myzoteroclient’).
- Update your app delegate to notify SZNZotero as following:
#import "AFOAuth1Client.h"
NSString * const SZNURLScheme = @"##my_URL_scheme##";
(…)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if ([url.scheme isEqualToString:SZNURLScheme]) {
NSNotification *notification = [NSNotification notificationWithName:kAFApplicationLaunchedWithURLNotification object:nil userInfo:@{kAFApplicationLaunchOptionsURLKey: url}];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
return YES;
}
You need to instanciate the Zotero API client with your API consumer key and secret:
NSString *clientKey = @"###my_consumer_key###";
NSString *clientSecret = @"###my_consumer_secret###";
SZNZoteroAPIClient *client = [[SZNZoteroAPIClient alloc] initWithKey:clientKey secret:clientSecret URLScheme:SZNURLScheme];
If you don’t have a consumer key and secret, you must register your application with Zotero.
SZNCollection *parentCollection = ...;
[parentCollection fetchTopItemsSuccess:^(NSArray *items) {
/* ... */
} failure:^(NSError *error) {
/* ... */
}];
SZNLibrary *library = ...;
NSDictionary *itemFields = ...;
[SZNItem createItemInLibrary:library content:itemFields success:^(SZNItem *newItem) {
/* ... */
} failure:^(NSError *error) {
/* ... */
}];
SZNZotero requires Xcode 4.4 with either the iOS 5.0 or Mac OS X 10.7, as well as AFNetworking, AFOAuth1Client, TBXML, and ISO8601DateFormatter. SZNZotero uses ARC.
SZNZotero is developed by shazino.
SZNZotero is available under the MIT license. See the LICENSE file for more info.