Class: CloudFile::Evernote

Inherits:
Service show all
Defined in:
lib/cloud_file/providers/evernote.rb

Instance Method Summary collapse

Methods inherited from Service

auth_value, #files, for_user, #open, #read_format, register, register_converter, uri_format

Instance Method Details

#create_note(book, title, content) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/cloud_file/providers/evernote.rb', line 34

def create_note(book,title,content)
  note = ::Evernote::EDAM::Type::Note.new
  note.title = title
  #note.content = ""
  note.content = '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>' + content + '</en-note>'
  note.notebookGuid = get_notebook(book).guid

  note_store.createNote(note)
end

#get_note(book, title) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/cloud_file/providers/evernote.rb', line 26

def get_note(book,title)
  shell = get_note_shell(book,title)
  unless shell
    raise "no note found"
  end

  note_store.getNote(shell.guid, true, true, false, false)
end

#get_note_shell(book, title) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/cloud_file/providers/evernote.rb', line 16

def get_note_shell(book,title)
  book = get_notebook(book)

  filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
  filter.notebookGuid = book.guid
  #filter.words = title
  notes = note_store.findNotes(filter,0,10)

  notes.notes.find { |x| x.title == title }
end

#get_notebook(book) ⇒ Object



13
14
15
# File 'lib/cloud_file/providers/evernote.rb', line 13

def get_notebook(book)
  note_store.listNotebooks.find { |x| x.name == book }
end

#read(loc) ⇒ Object



62
63
64
65
66
# File 'lib/cloud_file/providers/evernote.rb', line 62

def read(loc)
  res = get_note(loc[:notebook],loc[:title]).content
  #raise "no match" unless res =~ /<en-note>(.*)<\/en-note>/
  #$1
end

#update_note(book, title, content) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/cloud_file/providers/evernote.rb', line 44

def update_note(book,title,content)
  note = get_note(book,title)
  unless content =~ /DOCTYPE/
    content = '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
    <en-note>' + content + '</en-note>'
  end
  note.content = content
  note_store.updateNote(note)
end

#write(loc, content) ⇒ Object

raise “no match” unless res =~ /<en-note>(.*)</en-note>/ $1



67
68
69
# File 'lib/cloud_file/providers/evernote.rb', line 67

def write(loc,content)
  write_note(loc[:notebook],loc[:title],content)
end

#write_note(book, title, content) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/cloud_file/providers/evernote.rb', line 53

def write_note(book,title,content)
  if get_note_shell(book,title)
    update_note(book,title,content)
  else
    create_note(book,title,content)
  end
end