class EnClient::ListNoteCommand

Attributes

notebook_guid[RW]
tag_guids[RW]

Public Class Methods

new() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 807
def initialize
  @tag_guids = []
end

Public Instance Methods

exec_impl() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 811
def exec_impl
  check_auth
  if dm.during_full_sync?
    get_result_from_server
  else
    get_result_from_local_cache
  end
end

Private Instance Methods

get_result_from_local_cache() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 822
def get_result_from_local_cache
  LOG.debug "return notes from cache"
  notes = []
  dm.transaction do
    dm.open_note do |db|
      db.each_value do |value|
        n = Evernote::EDAM::Type::Note.new
        n.deserialize value
        if @tag_guids == nil || (n.tagGuids != nil && (@tag_guids - n.tagGuids).empty?)
          if @notebook_guid == nil || @notebook_guid == n.notebookGuid
            notes << n
          end
        end
      end
    end
  end
  notes.sort! do |a, b|
    b.updated <=> a.updated
  end
  reply = ListNoteReply.new
  reply.notes = notes
  shell.reply self, reply
end
get_result_from_server() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 846
def get_result_from_server
  LOG.debug "return notes from server"
  server_task do
    filter = Evernote::EDAM::NoteStore::NoteFilter.new
    filter.order = Evernote::EDAM::Type::NoteSortOrder::UPDATED
    filter.tagGuids = @tag_guids
    filter.notebookGuid = @notebook_guid

    notelist = sm.note_store.findNotes(sm.auth_token,
                                       filter,
                                       0,
                                       Evernote::EDAM::Limits::EDAM_USER_NOTES_MAX)
    DBUtils.sync_updated_notes dm, sm, tm, notelist.notes
    reply = ListNoteReply.new
    reply.notes = notelist.notes
    shell.reply self, reply
  end
end