Skip to content

Instantly share code, notes, and snippets.

@evernotegists evernotegists/example.rb Secret
Last active Dec 18, 2015

Embed
What would you like to do?
def make_note(note_store, note_title, note_body, resources=[], parent_notebook=nil)
#Create a Note instance with title and body
# Send Note object to user's account
our_note = Evernote::EDAM::Type::Note.new
our_note.title = note_title
## Build body of note
n_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
n_body += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
n_body += "<en-note>#{note_body}"
unless resources.empty?
### Add Resource objects to note body
n_body += "<br /><br />"
our_note.resources = resources
resources.each do |resource|
hash_func = Digest::MD5.new
hexhash = hash_func.hexdigest(resource.data.body)
n_body += "Attachment with hash #{hexhash}: <br /><en-media type=\"#{resource.mime}\" hash=\"#{hexhash}\" /><br />"
end
end
n_body += "</en-note>"
our_note.content = n_body
## Attempt to create note in Evernote account
begin
note = note_store.createNote(our_note)
rescue Evernote::EDAM::Error::EDAMUserException => edue
## Something was wrong with the note data
## See EDAMErrorCode enumeration for error code explanation
## http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
puts "EDAMUserException: #{edue}"
rescue Evernote::EDAM::Error::EDAMNotFoundException => ednfe
## Parent Notebook GUID doesn't correspond to an actual notebook
puts "EDAMNotFoundException: Invalid parent notebook GUID"
end
## Return created note object
note
end
@danielpclark

This comment has been minimized.

Copy link

commented Jun 12, 2014

Are the resources that are handed in file io objects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.