Class: Evertils::Common::Entity::Note
- Inherits:
-
Base
show all
- Defined in:
- lib/evertils/common/entity/note.rb
Overview
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
Instance Method Details
#attach_file(file) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/evertils/common/entity/note.rb', line 177
def attach_file(file)
if file.is_a? Array
file.each do |f|
media_resource = ENML.new(f)
body.concat(media_resource.embeddable_element)
@entity.resources << media_resource.element
end
else
media_resource = ENML.new(file)
body.concat(media_resource.embeddable_element)
@entity.resources << media_resource.element
end
@evernote.call(:updateNote, @entity)
end
|
#create(conf = {}) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/evertils/common/entity/note.rb', line 24
def create(conf = {})
note = Evertils::Common::Model::Note.new(conf)
@entity = @evernote.call(:createNote, note.entity)
return false unless @entity
share if note.shareable
Notify.success("#{note.entity.title} created")
self
end
|
#create_from_yml(full_path) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/evertils/common/entity/note.rb', line 7
def create_from_yml(full_path)
raise "File not found: #{full_path}" unless File.exist? full_path
begin
conf = placeholders_for(YAML.safe_load(File.read(full_path)))
required = %w[title]
return create(conf) if has_required_fields(conf, required) && !exists?
raise ArgumentError, 'Configuration file is missing some required fields'
rescue ArgumentError => e
Notify.error e.message
end
end
|
#destroy ⇒ Object
46
47
48
|
# File 'lib/evertils/common/entity/note.rb', line 46
def destroy
@evernote.call(:deleteNote, @entity.guid)
end
|
#exists? ⇒ Boolean
40
41
42
|
# File 'lib/evertils/common/entity/note.rb', line 40
def exists?
!@entity.nil?
end
|
#expunge! ⇒ Object
52
53
54
|
# File 'lib/evertils/common/entity/note.rb', line 52
def expunge!
@evernote.call(:expungeNote, @entity.guid)
end
|
#find(name) ⇒ Object
Also known as:
find_by_name
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/evertils/common/entity/note.rb', line 89
def find(name)
@entity = nil
filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
filter.words = "intitle:#{name}"
spec = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
spec.includeTitle = true
spec.includeTagGuids = true
spec.includeContentLength = true
spec.includeCreated = true
spec.includeUpdated = true
result = @evernote.call(:findNotesMetadata, filter, 0, 10, spec)
@entity = result.notes.detect { |note| note.title == name }
self if @entity
end
|
#find_note_contents_using_grammar(grammar) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/evertils/common/entity/note.rb', line 152
def find_note_contents_using_grammar(grammar)
find_result = find_with(grammar)
return if find_result.nil?
guid = find_result.entity.guid
result = @evernote.call(:getNote, guid, true, false, false, false)
@entity = result
self if @entity
end
|
#find_with(conf) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/evertils/common/entity/note.rb', line 112
def find_with(conf)
return unless conf.is_a?(String)
@entity = nil
filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
filter.words = conf
spec = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
spec.includeTitle = true
spec.includeTagGuids = true
spec.includeContentLength = true
spec.includeCreated = true
spec.includeUpdated = true
result = @evernote.call(:findNotesMetadata, filter, 0, 10, spec)
@entity = result.notes.first
self if @entity
end
|
#find_with_contents(name) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/evertils/common/entity/note.rb', line 138
def find_with_contents(name)
find_result = find(name)
return if find_result.nil?
guid = find_result.entity.guid
result = @evernote.call(:getNote, guid, true, false, false, false)
@entity = result
self if @entity
end
|
#move_to(notebook) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/evertils/common/entity/note.rb', line 58
def move_to(notebook)
nb = Evertils::Common::Manager::Notebook.instance
target = nb.find(notebook)
raise "Notebook not found: #{notebook}" if target.entity.nil?
@entity.notebookGuid = target.to_s
@evernote.call(:updateNote, @entity)
end
|
#share ⇒ Object
71
72
73
|
# File 'lib/evertils/common/entity/note.rb', line 71
def share
@evernote.call(:shareNote, @entity.guid)
end
|
#tag(*guids) ⇒ Object
166
167
168
169
170
171
172
173
|
# File 'lib/evertils/common/entity/note.rb', line 166
def tag(*guids)
guids = guids.map(&:to_s)
existing_tags = @entity.tagGuids
@entity.tagGuids = [] unless existing_tags.is_a?(Array)
@entity.tagGuids.concat(guids)
@evernote.call(:updateNote, @entity)
end
|
#unshare ⇒ Object
77
78
79
|
# File 'lib/evertils/common/entity/note.rb', line 77
def unshare
@evernote.call(:stopSharingNote, @entity.guid)
end
|
#update ⇒ Object
83
84
85
|
# File 'lib/evertils/common/entity/note.rb', line 83
def update
@evernote.call(:updateNote, @entity)
end
|