Skip to content

Instantly share code, notes, and snippets.

View evernotegists's full-sized avatar

Evernote Gists evernotegists

  • Evernote Corporation
  • Redwood City, CA
View GitHub Profile
@evernotegists
evernotegists / gist:5647969
Last active December 17, 2015 17:39
Create a simple note
- (void) makeNoteWithTitle:(NSString*)noteTile withBody:(NSString*) noteBody withParentNotebook:(EDAMNotebook*)parentNotebook {
NSString *noteContent = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
"<en-note>"
"%@"
"</en-note>",noteBody];
// Parent notebook is optional; if omitted, default notebook is used
NSString* parentNotebookGUID;
if(parentNotebook) {
@@ error
<html>
<head>
<title>Evernote Ruby Example App &mdash; Error</title>
</head>
<body>
<p>An error occurred: <%= @last_error %></p>
<p>Please <a href="/reset">start over</a>.</p>
</body>
</html>
@@ index
<html>
<head>
<title>Evernote Ruby Example App</title>
</head>
<body>
<a href="/requesttoken">Click here</a> to authenticate this application using OAuth.
<% if session[:notebooks] %>
<hr />
<h3>The current user is <%= session[:username] %> and there are <%= session[:total_notes] %> notes in their account</h3>
get '/callback' do
unless params['oauth_verifier'] || session['request_token']
@last_error = "Content owner did not authorize the temporary credentials"
halt erb :error
end
session[:oauth_verifier] = params['oauth_verifier']
begin
session[:access_token] = session[:request_token].get_access_token(:oauth_verifier => session[:oauth_verifier])
redirect '/list'
rescue => e
get '/authorize' do
if session[:request_token]
redirect session[:request_token].authorize_url
else
# You shouldn't be invoking this if you don't have a request token
@last_error = "Request token not set."
erb :error
end
end
get '/requesttoken' do
callback_url = request.url.chomp("requesttoken").concat("callback")
begin
session[:request_token] = client.authentication_request_token(:oauth_callback => callback_url)
redirect '/authorize'
rescue => e
@last_error = "Error obtaining temporary credentials: #{e.message}"
erb :error
end
get '/list' do
begin
# Get notebooks
session[:notebooks] = notebooks.map(&:name)
# Get username
session[:username] = en_user.username
# Get total note count
session[:total_notes] = total_note_count
erb :index
rescue => e
get '/reset' do
session.clear
redirect '/'
end
get '/' do
erb :index
end
def total_note_count
filter = Evernote::EDAM::NoteStore::NoteFilter.new
counts = note_store.findNoteCounts(auth_token, filter, false)
notebooks.inject(0) do |total_count, notebook|
total_count + (counts.notebookCounts[notebook.guid] || 0)
end
end