Skip to content

Instantly share code, notes, and snippets.

@evernotegists
Last active December 18, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evernotegists/3c9b62e83684b2e864b1 to your computer and use it in GitHub Desktop.
Save evernotegists/3c9b62e83684b2e864b1 to your computer and use it in GitHub Desktop.
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
Copy link

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