Class: Evertils::Common::Entity::Notes

Inherits:
Base show all
Defined in:
lib/evertils/common/entity/notes.rb

Overview

Since:

  • 0.3.0

Constant Summary

Constants inherited from Base

Base::REPLACEMENTS

Instance Attribute Summary

Attributes inherited from Base

#entity

Instance Method Summary collapse

Methods inherited from Base

#end_of_day, #initialize, #placeholders_for, #prop, #start_of_day, #symbolize_keys, #to_s

Methods inherited from Generic

#bytesize, #deprecation_notice, #encoding, #force_encoding, #has_required_fields, #initialize

Constructor Details

This class inherits a constructor from Evertils::Common::Entity::Base

Instance Method Details

#all(keyword) ⇒ Object

Since:

  • 0.3.2



7
8
9
# File 'lib/evertils/common/entity/notes.rb', line 7

def all(keyword)
  find_all(keyword, nil, 1000)
end

#find_all(title, notebook = nil, limit = 300, include_note_body = false) ⇒ Object Also known as: find

Since:

  • 0.2.0



13
14
15
16
17
18
# File 'lib/evertils/common/entity/notes.rb', line 13

def find_all(title, notebook = nil, limit = 300, include_note_body = false)
  filters = find_filters(title, notebook)

  response = @evernote.call(:findNotesMetadata, filters, 0, limit, find_spec(include_note_body))
  response.notes
end

#find_by_date(date, period = :created) ⇒ Object

Since:

  • 0.2.9



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/evertils/common/entity/notes.rb', line 71

def find_by_date(date, period = :created)
  filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
  filter.words = "#{period}:year-#{year_diff(date.year)}"
  filter.order = 1

  spec = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
  spec.includeTitle = true
  spec.includeUpdated = true
  spec.includeCreated = true

  pool = @evernote.call(:findNotesMetadata, filter, 0, 300, spec)

  pool.notes.select do |note|
    n = note_date(note, period)

    n.strftime('%m-%d-%Y') == date.strftime('%m-%d-%Y')
  end
end

#find_by_date_range(start, finish = DateTime.now, period = :created) ⇒ Object

Since:

  • 0.2.9



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/evertils/common/entity/notes.rb', line 47

def find_by_date_range(start, finish = DateTime.now, period = :created)
  filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
  filter.words = "#{period}:year-#{year_diff(start.year)}"
  filter.order = 1

  spec = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
  spec.includeTitle = true
  spec.includeUpdated = true
  spec.includeCreated = true
  spec.includeContent = true if include_note_content

  pool = @evernote.call(:findNotesMetadata, filter, 0, 300, spec)

  pool.notes.select do |note|
    f = finish.to_time.to_i
    s = start.to_time.to_i
    n = note_date(note, period).to_time.to_i

    n <= f && n >= s
  end
end

#find_by_filter(filter) ⇒ Object

Since:

  • 0.3.2



92
93
94
95
96
97
98
99
# File 'lib/evertils/common/entity/notes.rb', line 92

def find_by_filter(filter)
  spec = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
  spec.includeTitle = true
  spec.includeUpdated = true
  spec.includeCreated = true

  @evernote.call(:findNotesMetadata, filter, 0, 300, spec)
end

#find_by_tag(tag_name) ⇒ Object

Since:

  • 0.2.0



34
35
36
37
38
39
40
41
42
43
# File 'lib/evertils/common/entity/notes.rb', line 34

def find_by_tag(tag_name)
  filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
  filter.words = "tag:#{tag_name}"

  spec = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
  spec.includeTitle = true

  response = @evernote.call(:findNotesMetadata, filter, nil, 300, spec)
  response.notes
end

#find_one(title, notebook = nil, include_note_body = false) ⇒ Object

Since:

  • 0.2.0



23
24
25
26
27
28
29
30
# File 'lib/evertils/common/entity/notes.rb', line 23

def find_one(title, notebook = nil, include_note_body = false)
  filters = find_filters(title, notebook)

  response = @evernote.call(:findNotesMetadata, filters, 0, 10, find_spec(include_note_body))

  notes = response.notes.detect { |note| note.title == title }
  notes
end