Class: Yinx::NoteStore

Inherits:
Object
  • Object
show all
Defined in:
lib/yinx/note_store.rb

Constant Summary collapse

NOTE_FILTERS =
[:order, :ascending, :words,
:notebookGuid, :tagGuids, :timeZone,
:inactive, :emphasized]
NOTE_META_RESULT_SPECS =
[:includeTitle, :includeContentLength,
:includeCreated, :includeUpdated,
:includeDeleted, :includeUpdateSequenceNum,
:includeNotebookGuid, :includeTagGuids,
:includeAttributes, :includeLargestResourceMime,
:includeLargestResourceSize]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(userStore, authToken) ⇒ NoteStore

Returns a new instance of NoteStore.



23
24
25
26
27
28
29
# File 'lib/yinx/note_store.rb', line 23

def initialize userStore, authToken
  noteStoreUrl = userStore.getNoteStoreUrl(authToken)
  noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
  noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
  @auth_token = authToken
  @noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



6
7
8
# File 'lib/yinx/note_store.rb', line 6

def auth_token
  @auth_token
end

Instance Method Details

#book_name(id) ⇒ Object



46
47
48
49
# File 'lib/yinx/note_store.rb', line 46

def book_name id
  @book_hash ||= Hash[listNotebooks.map{|book| [book.guid, book.name]}]
  @book_hash[id]
end

#findNotes(opt = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/yinx/note_store.rb', line 56

def findNotes opt = {}
  fl, start, ending, sp = filter(opt), 0, 250, spec(opt)
  md_list = note_store. auth_token, fl, start, ending, sp
  result = md_list.notes
  while md_list.totalNotes > start + ending
	start += ending
    md_list = note_store. auth_token, fl, start, ending, sp
	result.concat md_list.notes
  end
  result
end

#listNotebooks(authToken = auth_token, &blk) ⇒ Object



31
32
33
34
# File 'lib/yinx/note_store.rb', line 31

def listNotebooks authToken = auth_token, &blk
  @notebooks ||= note_store.listNotebooks(authToken)
  block_given? ? @notebooks.select(&blk) : @notebooks
end

#listTags(&blk) ⇒ Object



36
37
38
39
# File 'lib/yinx/note_store.rb', line 36

def listTags &blk
  @tags ||= note_store.listTags(auth_token)
  block_given? ? @tags.select(&blk) : @tags
end

#note_storeObject



19
20
21
# File 'lib/yinx/note_store.rb', line 19

def note_store
  @noteStore
end

#stack_name(id) ⇒ Object



41
42
43
44
# File 'lib/yinx/note_store.rb', line 41

def stack_name id
  @stack_hash ||= Hash[listNotebooks.map{|book| [book.guid, book.stack]}]
  @stack_hash[id]
end

#tag_name(id) ⇒ Object



51
52
53
54
# File 'lib/yinx/note_store.rb', line 51

def tag_name id
  @tag_hash ||= Hash[listTags.map{|tag| [tag.guid, tag.name]}]
  @tag_hash[id]
end