Class: Everdone::Evernote

Inherits:
Object
  • Object
show all
Defined in:
lib/everdone/evernote.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Evernote

Returns a new instance of Evernote.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/everdone/evernote.rb', line 13

def initialize(config)
    @config = config
    # Set up the NoteStore client 
    @evernote_client = EvernoteOAuth::Client.new(
        token: @config.evernote_token,
        sandbox: @config.use_evernote_sandbox
    )
    @note_store = @evernote_client.note_store
    @notebook_guids = {}
    notebooks = @note_store.listNotebooks
    notebooks.each do |notebook|
        @notebook_guids[notebook.name] = notebook.guid
    end
    @tags = @note_store.listTags
    @tags.each { |tag| 
        if @config.tag and tag.name == @config.tag then
            @tag_guid = tag.guid
            break
        end
    }
end

Class Method Details

.convert_text_to_timestamp(dateText, date_format) ⇒ Object



68
69
70
71
# File 'lib/everdone/evernote.rb', line 68

def self.convert_text_to_timestamp(dateText, date_format)
    ret = DateTime.strptime(dateText, date_format).to_time.to_i * 1000
    return ret
end

Instance Method Details

#create_note(title, content, notebook, created) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/everdone/evernote.rb', line 35

def create_note(title, content, notebook, created)
    new_note = ::Evernote::EDAM::Type::Note.new()
    new_note.notebookGuid = @notebook_guids[notebook]
    new_note.title = title.strip.slice(0..254).scan(/[[:print:]]/).join
    new_note.created = created
    new_note.content = content
    new_note.tagNames = [@config.tag] if @config.tag

    begin
        created_note = @note_store.createNote(@config.evernote_token, new_note)
    rescue => err
        puts "ERROR: ----------- Evernote exception ------------------!!!"
        puts err.to_s
        puts "Note info:"
        puts "Title: #{title}"
        puts "Created: #{created}"
        puts "Content:\n#{content}"
    end
    
end

#find_note_counts(content_text, notebook) ⇒ Object

returns the count of notes within the context:

In the notebook NOTEBOOK_TARGET with tag (if defined) TAG_WITH and having content (if defined) content_text


58
59
60
61
62
63
64
65
66
# File 'lib/everdone/evernote.rb', line 58

def find_note_counts(content_text, notebook)
    filter = ::Evernote::EDAM::NoteStore::NoteFilter.new()
    filter.notebookGuid = @notebook_guids[notebook] if notebook
    filter.tagGuids = [@tag_guid] if @config.tag
    filter.words = content_text if content_text
    ret = @note_store.findNoteCounts(filter, false)
    # also: ret.tagCounts[@@tag_guid]
    return !ret.notebookCounts.nil? && notebook && ret.notebookCounts[@notebook_guids[notebook]] ? ret.notebookCounts[@notebook_guids[notebook]] : 0
end