Class: ENUtils::Note
- Inherits:
-
Object
- Object
- ENUtils::Note
- Defined in:
- lib/evernote_utils/note.rb
Constant Summary collapse
- DEFAULT_LIMIT =
10
Instance Attribute Summary collapse
-
#edam_note ⇒ Object
readonly
Evernote::EDAM::Type::Note fields guid:“f1df2a4d-5852-4cb6-82f7-6240ee4e2b5c” title:“Note title” contentHash:eeeeeeee6bxxxxxxxxxxxxxxxa889ca7 contentLength:2246 created:1266881336000 updated:1266881347000 active:true updateSequenceNum:2653 notebookGuid:“4xxxxxda-xxxx-xxxx-xxxx-zzzzzzzzzzzz” attributes:<Evernote::EDAM::Type::NoteAttributes >.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
- #content=(val) ⇒ Object
-
#created ⇒ Object
not delegated methods.
-
#initialize(core, edam_note) ⇒ Note
constructor
A new instance of Note.
- #inspect ⇒ Object
- #notebook ⇒ Object
- #notebook=(val) ⇒ Object
- #save ⇒ Object
- #tags ⇒ Object
- #tags=(val) ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(core, edam_note) ⇒ Note
Returns a new instance of Note.
54 55 56 57 |
# File 'lib/evernote_utils/note.rb', line 54 def initialize(core, edam_note) @core = core @edam_note = edam_note end |
Instance Attribute Details
#edam_note ⇒ Object (readonly)
Evernote::EDAM::Type::Note fields
guid:"f1df2a4d-5852-4cb6-82f7-6240ee4e2b5c"
title:"Note title"
contentHash:eeeeeeee6bxxxxxxxxxxxxxxxa889ca7
contentLength:2246
created:1266881336000
updated:1266881347000
active:true
updateSequenceNum:2653
notebookGuid:"4xxxxxda-xxxx-xxxx-xxxx-zzzzzzzzzzzz"
attributes:<Evernote::EDAM::Type::NoteAttributes >
22 23 24 |
# File 'lib/evernote_utils/note.rb', line 22 def edam_note @edam_note end |
Class Method Details
.create(core, attrs) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/evernote_utils/note.rb', line 37 def self.create(core, attrs) edam_note = Evernote::EDAM::Type::Note.new(parse_attrs(attrs)) begin res = core.notestore.createNote(core.token, edam_note) rescue Evernote::EDAM::Error::EDAMUserException # build error message because $!.message is nil raise $!.class, "[ErrorCode: #{$!.errorCode}] #{$!.parameter}", $!.backtrace end new(core, res) end |
.delete(core, guid) ⇒ Object
48 49 50 51 52 |
# File 'lib/evernote_utils/note.rb', line 48 def self.delete(core, guid) core.notestore.deleteNote(core.token, guid) rescue Evernote::EDAM::Error::EDAMUserException raise $!.class, "[ErrorCode: #{$!.errorCode}] #{$!.parameter}", $!.backtrace end |
.where(core, options = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/evernote_utils/note.rb', line 30 def self.where(core, ={}) offset = .delete(:offset) || 0 limit = .delete(:limit) || DEFAULT_LIMIT result = core.notestore.findNotes(core.token, NoteFilter.build(core, ), offset, limit).notes.map{|n| new(core, n) } NoteList.new(core, result, ) end |
Instance Method Details
#content ⇒ Object
67 68 69 |
# File 'lib/evernote_utils/note.rb', line 67 def content @content ||= remote_content end |
#content=(val) ⇒ Object
71 72 73 |
# File 'lib/evernote_utils/note.rb', line 71 def content=(val) @content = @edam_note.content = val end |
#created ⇒ Object
not delegated methods
64 |
# File 'lib/evernote_utils/note.rb', line 64 def created; Time.at(@edam_note.created/1000); end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/evernote_utils/note.rb', line 59 def inspect "<#{self.class} @edam_note=#{@edam_note.inspect}>" end |
#notebook ⇒ Object
75 76 77 |
# File 'lib/evernote_utils/note.rb', line 75 def notebook @notebook ||= Notebook.find_by_guid(@core, notebookGuid) end |
#notebook=(val) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/evernote_utils/note.rb', line 79 def notebook=(val) case val when ENUtils::Notebook self.notebookGuid = val.guid when String self.notebookGuid = val end end |
#save ⇒ Object
102 103 104 105 106 |
# File 'lib/evernote_utils/note.rb', line 102 def save @edam_note.updated = Time.now.to_i * 1000 @core.notestore.updateNote(@core.token, @edam_note) true end |
#tags ⇒ Object
88 89 90 91 |
# File 'lib/evernote_utils/note.rb', line 88 def return nil unless tagGuids @tags ||= tagGuids.map{|guid| Tag.find_by_guid(@core, guid) }.compact end |
#tags=(val) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/evernote_utils/note.rb', line 93 def (val) return false unless val.is_a? Array if val.all?{|v| v.is_a? ENUtils::Tag } self.tagGuids = val.map(&:guid) elsif val.all?{|v| v.is_a? String } self.tagGuids = val end end |
#updated ⇒ Object
65 |
# File 'lib/evernote_utils/note.rb', line 65 def updated; Time.at(@edam_note.updated/1000); end |