26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/evernote_uploader/helper.rb', line 26
def create_note options, filenames, notebook = nil
note = Evernote::EDAM::Type::Note.new
note.title = options[:title] || File.basename(filenames.first, ".*")
note.tagNames = options[:tags]
if notebook
note.notebookGuid = notebook.guid
end
note.resources = []
note.content = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
EOF
filenames.each {|filename|
file_data = File.open(filename, "rb") {|f| f.read}
hash_func = Digest::MD5.new
data = Evernote::EDAM::Type::Data.new
data.size = file_data.size
data.bodyHash = hash_func.digest(file_data)
data.body = file_data
resource = Evernote::EDAM::Type::Resource.new
resource.mime = detect_mime_type(filename)
resource.data = data
resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new
resource.attributes.fileName = filename
hash_hex = hash_func.hexdigest(file_data)
note.resources << resource
note.content += " <en-media type=\"#{resource.mime}\" "
note.content += "hash = \"#{hash_hex}\"/>\n"
}
note.content += "</en-note>\n"
return note
end
|