Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Evernote API wrapper: EVNConnect

日本語の説明はこちら

This library is a wrapper of Evernote API.

  • ARC enabled project.
  • I did not implemented all of evernote API, only what I needed. check out EvernoteRequest.h.

Concept

1, Authentication with OAuth

I don't want to store username and password in our app.
(I don't need dialog, supports only oauth using safari for multitasking ios)

2, Synchronous/Asynchronous API wrapper

//synchronous
- (EDAMNote*)createNoteInNotebook:(EDAMNotebook *)notebook
                            title:(NSString*)title 
                          content:(NSString*)content
                             tags:(NSArray *)tags
                     andResources:(NSArray*)resources;
//asynchronous
- (EvernoteRequest *)createNoteInNotebook:(EDAMNotebook *)notebook 
                                    title:(NSString*)title
                                  content:(NSString*)content
                                     tags:(NSArray *)tags
                                resources:(NSArray*)resources
                              andDelegate:(id<EvernoteRequestDelegate>)delegate;

(I haven't implemented other wrapper methods yet, but asynchronous request implementation is already in EvernoteNoteStoreClient.h)

3, Request delegate

I want to know the progress of request, implemented subclass of thrift's THTTPClient, EvernoteHTTPClient to do it. And added EvernoteRequestDelegate. Currently this feature works with asynchronous request only.

@protocol EvernoteRequestDelegate <NSObject>
@optional
- (void)requestLoading:(EvernoteRequest*)request;
- (void)request:(EvernoteRequest*)request didReceiveResponse:(NSURLResponse*)response;
- (void)request:(EvernoteRequest*)request didFailWithError:(NSError*)error;
- (void)request:(EvernoteRequest*)request didLoad:(id)result;
- (void)request:(EvernoteRequest*)request didLoadRawResponse:(NSData*)data;
- (void)request:(EvernoteRequest*)client 
    didSendBodyData:(NSInteger)bytesWritten
    totalBytesWritten:(NSInteger)totalBytesWritten 
    totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;
@end

Usage

1, Copy source files in EVNConnect into your project.

2, Put 3rd party libraries into your project and configure them.

Libraries are stored in Libraries

3, Code.

MainViewController.h

#import "EVNConnect.h"
@interface MainViewController : UIViewController<EvernoteSessionDelegate, EvernoteRequestDelegate>{
    __strong Evernote *evernote_;
}
@property (nonatomic, readonly) Evernote *evernote; 
@end

MainViewController.m

3.1, initialize evernote wrapper

Initialize Evernote class as below. Where EVERNOTE_CONSUMER_KEY and EVERNOTE_CONSUMER_SECRET are provided by evernote. And callbackScheme is url scheme which you configured in your project. useSandBox is flag to select http://www.evernote.com or http://sandbox.evernote.com for API endpoint.

//create instance of evernote
evernote_ =
    [[Evernote alloc] initWithAuthType:EvernoteAuthTypeOAuthConsumer
                           consumerKey:EVERNOTE_CONSUMER_KEY
                        consumerSecret:EVERNOTE_CONSUMER_SECRET
                        callbackScheme:@"evnconnecttest://authorize"
                            useSandBox:YES
                           andDelegate:self];

3.2, load credential

If you call [evernote_ saveCredential] when previous authentication succeeded, you can load credential via calling loadCredential method. If valid credential loaded, you can call noteStore method without switching to safari to authenticate user.

[evernote_ loadCredential];

3.3, login to evernote

Now you can call [evernote_ login] method to login to Evernote with oauth. When there is no valid authToken saved, this method will switch to safari to authenticate user.

[evernote_ login];

3.4, EvernoteSessionDelegate

You may save credential when user did login, or clear credential when login failed.

#pragma mark - EvernoteSessionDelegate
-(void)evernoteDidLogin{
    [evernote_ saveCredential];
}
- (void)evernoteDidLogout{
    [evernote_ clearCredential];
}
- (void)evernoteDidNotLogin{
    [evernote_ clearCredential];
}

3.5, send request

Now you can request to Evernote API. If you call asynchronous requests, you may implement EvernoteRequestDelegate to handle response from server.

//sync request
EDAMNotebook *notebook = [evernote_ notebookNamed:@"test"];

if(notebook == nil){
    notebook = [evernote_ createNotebookWithTitle:@"test"];
}

EDAMResource *resource1 = 
[evernote_ createResourceFromUIImage:[UIImage imageNamed:@"sample1.jpg"]];

//async request
[evernote_ createNoteInNotebook:notebook 
                          title:@"testnote" 
                        content:@"testnotemogemoge" 
                           tags:[NSArray arrayWithObjects:@"Photo", @"Bear", nil]
                      resources:[NSArray arrayWithObject:resource1]
                    andDelegate:self];

License

Copyright (c) 2011, ISHITOYA Kentaro.

New BSD License. See LICENSE file.

3rd Party Library Licenses

  • Evernote API
    Copyright (c) 2007-2011 by Evernote Corporation, All rights reserved.
    Evernote API's License is here

  • Apache Thrift
    Apache thrift is Licensed under Apache License 2.0. You can read full text of the license here

  • OAuthConsumer
    OAuthConsumer is Licensed under MIT License.

  • KissXML
    I could not find out mention of license in their repository.

  • PDKeychainBindingsController
    Copyright (C) 2010-2011 by Carl Brown of PDAgent, LLC.
    PDKeychainBindingsController is licensed under MIT license. You can read full text of the license here.

  • RegexKitLite
    Copyright © 2008-2010, John Engelhart
    RegexKitLite is licensed under BSD License. You can read full text of the license here

About

Evernote API wrapper for ios5

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages