TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2015 |
Maintained by Alex Pretzlav.
Build awesome things with email! We take the pain out of syncing email data with your app so you can focus on what makes your product great.
CIOAPIClient is an easy to use iOS and OS X library for communicating with the Context.IO 2.0 API. It is built upon NSURLSession and provides convenient asynchronous block based methods for interacting with the API.
After cloning the git repository, make sure to install cocoapods used by the example app:
cd <repository path>/Example
pod install
open "Context.IO iOS Example App.xcworkspace"
To run the example application, you will need to insert your Context.IO consumer key and secret in CIOAppDelegate.m
.
There is a pre-configured Xcode Playground (currently targeting Xcode 6.4 + Swift 1.2) in the CIOPlayground
directory. Playgrounds with library dependencies are slightly finicky with Xcode 6.4, follow these steps to get it working:
cd CIOPlayground
pod install
CIOPlayground.xcworkspace
CIOAPIClient
Scheme in the Xcode scheme selection dropdown (it should have a dynamic framework yellow toolbox icon)CIOPlayground.playground
from the CIOPlayground
project in the Project navigator left sidebarlet s: CIOAPISession = CIOAPISession(consumerKey: "", consumerSecret: "")
authenticator.withAuthentication() { session in
block in the playgroundUse CIOAPISession
to construct and execute signed NSURLRequests
against the Context.IO API.
Initialize CIOAPISession
with your API key consumer key and consumer secret:
CIOAPISession *session = [[CIOAPISession alloc] initWithConsumerKey:@"your-consumer-key"
consumerSecret:@"your-consumer-secret"];
CIOAPISession
uses Connect Tokens to authorize individual user's email accounts. Please see the example application for an overview of the authentication process. Feel free to re-use or subclass CIOAuthViewController
in your own project - it takes care of the details of authentication and should work out of the box for most purposes.
[[session getMessagesWithParams:nil]
executeWithSuccess:^(NSArray *responseArray) {
self.messagesArray = responseArray;
} failure:^(NSError *error) {
NSLog(@"error getting messages: %@", error);
}];
[[session updateFoldersForMessageWithID:message[@"message_id"]
params:@{@"add": @"Test Label"}]
executeWithSuccess:^(NSDictionary *response) {
NSLog(@"Response: %@", response);
} failure:^(NSError *error) {
NSLog(@"error moving message: %@", error);
}];
// 0 is an alias for the first source of an account
[[session getFoldersForSourceWithLabel:@"0" params:nil]
executeWithSuccess:^void(NSArray *folders) {
NSLog(@"Folders: %@", folders);
} failure:^void(NSError *error) {
NSLog(@"Error getting folders: %@", error);
}];
NSDictionary *file = [message[@"files"] firstObject];
CIODownloadRequest *downloadRequest = [session downloadContentsOfFileWithID:file[@"file_id"]];
// Save file with attachment's filename in NSDocumentDirectory
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
NSURL *fileURL = [documentsURL URLByAppendingPathComponent:file[@"file_name"]];
[session downloadRequest:downloadRequest
toFileURL:fileURL
success:^{
NSLog(@"File downloaded: %@", [fileURL path]);
}
failure:^(NSError *error) {
NSLog(@"Download error: %@", error);
}
progress:^(int64_t bytesRead, int64_t totalBytesRead, int64_t totalBytesExpected){
NSLog(@"Download progress: %0.2f%%",
((double)totalBytesExpected / (double)totalBytesRead) * 100);
}];
CIOAPIClient
requires either iOS 7.0 and above or Mac OS 10.9 or above.
Thanks to Kevin Lord who wrote the original version of this library, Sam Soffes for sskeychain, and TweetDeck for TDOAuth which is used for the OAuth signature generation in CIOAPIClient.
CIOAPIClient
is licensed under the MIT License. See the LICENSE
file for details.