-
-
Save evernotegists/3c9b62e83684b2e864b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are the resources that are handed in file io objects?