Class: Log4ever::Note

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

Instance Method Summary collapse

Constructor Details

#initialize(notebook, auth_store) ⇒ Note

Returns a new instance of Note.



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/log4r/evernote.rb', line 111

def initialize(notebook, auth_store)
  return unless @params.nil? || @params.empty?
  @params = {}
  if !notebook.kind_of? ::Evernote::EDAM::Type::Notebook
    raise EvernoteError, "Expected kind of Notebook, got #{notebook.class}", caller
  elsif !notebook.respond_to? 'guid'
    raise NoMethodError, "#{notebook.class} do not has method: guid", caller
  end
  @notebook = notebook
  @auth_store = auth_store
end

Instance Method Details

#addContent(text) ⇒ Object

append content



147
148
149
150
151
# File 'lib/log4r/evernote.rb', line 147

def addContent(text)
  new_html = "<div style='font-family: Courier New'>" + text + "</div>"
  content_xml.at('en-note').inner_html += new_html
  @params[:content] = @content_ = content_xml.to_xml
end

#clearObject

clear



230
231
232
# File 'lib/log4r/evernote.rb', line 230

def clear
  @note = @content_ = @content_xml = nil
end

#contentObject

get note content text



162
163
164
165
166
# File 'lib/log4r/evernote.rb', line 162

def content
  return @content_ unless @content_.nil?
  @note.nil? and get
  @content_ = !@note.nil? && !@note.guid.nil? ? @auth_store.note_store.getNoteContent(@auth_store.auth_token, @note.guid) : ""
end

#content=(text) ⇒ Object

set new content



154
155
156
157
158
159
# File 'lib/log4r/evernote.rb', line 154

def content=(text)
  @params[:content] = @content_ = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
  "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n" +
  "<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\">\n" +
  "<div style=\"font-family: Courier New\">" + text + "</div></en-note>"
end

#content_xmlObject

get note content xml object



169
170
171
172
# File 'lib/log4r/evernote.rb', line 169

def content_xml
  return @content_xml unless @content_xml.nil?
  @content_xml = Nokogiri::XML(content)
end

#createObject

create note



175
176
177
# File 'lib/log4r/evernote.rb', line 175

def create
  @auth_store.note_store.createNote(@auth_store.auth_token, createNote)
end

#created_atObject

get created time



223
224
225
226
227
# File 'lib/log4r/evernote.rb', line 223

def created_at
  time = get.created.to_s
  ut = time.slice(0, time.length - 3)
  Time.at(ut.to_f)
end

#createNoteObject

create note object



208
209
210
211
212
213
# File 'lib/log4r/evernote.rb', line 208

def createNote
  @note = ::Evernote::EDAM::Type::Note.new
  @note.notebookGuid = @notebook.guid
  @params.each{|method, value| @note.send("#{method.to_s}=", value)}
  @note
end

#getObject

get latest note object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/log4r/evernote.rb', line 185

def get
  return @note unless @note.nil?
  filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
  filter.order = ::Evernote::EDAM::Type::NoteSortOrder::CREATED
  filter.notebookGuid = @notebook.guid
  filter.timeZone = "Asia/Tokyo"
  filter.ascending = false # descending
  note_list = @auth_store.note_store.findNotes(@auth_store.auth_token, filter, 0, 1)
  if note_list.notes.empty?
    Log4r::Logger.log_internal { "Note not found at #{@notebook.guid}" }
    @note = ::Evernote::EDAM::Type::Note.new
  else
    @note = note_list.notes[0]
  end
  @note
end

#get!Object

force get latest note object



203
204
205
# File 'lib/log4r/evernote.rb', line 203

def get!
  clear and get
end

#guidObject

note guid



129
# File 'lib/log4r/evernote.rb', line 129

def guid; @note.guid end

#sizeObject

content size



124
125
126
# File 'lib/log4r/evernote.rb', line 124

def size
  content.bytesize
end

#tagsObject

get tag’s guid list



137
138
139
# File 'lib/log4r/evernote.rb', line 137

def tags
  get.tagGuids
end

#tags=(tagGuids) ⇒ Object

set tags



142
143
144
# File 'lib/log4r/evernote.rb', line 142

def tags=(tagGuids)
  @params[:tagGuids] = tagGuids
end

#title=(str) ⇒ Object

set new title



132
133
134
# File 'lib/log4r/evernote.rb', line 132

def title=(str)
  @params[:title] = str
end

#updateObject

update note



180
181
182
# File 'lib/log4r/evernote.rb', line 180

def update
  @auth_store.note_store.updateNote(@auth_store.auth_token, updateNote)
end

#updateNoteObject

get note object



216
217
218
219
220
# File 'lib/log4r/evernote.rb', line 216

def updateNote
  @note.nil? and get
  @note.content = @params[:content]
  @note
end