diff options
| author | Kip Cole | 2013-12-08 11:20:56 +0800 |
|---|---|---|
| committer | Kip Cole | 2013-12-08 11:20:56 +0800 |
| commit | 3148ae082f3b11f2bbd790ee9f51a4b8962174ae (patch) | |
| tree | 2701b0fc7e07a292e79e83a121e5e3e40b43c4e0 /lib | |
| parent | 2ebc0504d3b5e11676bf37d5322cf48a24b3785c (diff) | |
| parent | 1e2076c22c470ea2566abd40de9d9be5eae71afa (diff) | |
| download | evernote-3148ae082f3b11f2bbd790ee9f51a4b8962174ae.tar.bz2 | |
Merge branch 'master' of https://github.com/kipcole9/evernote
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/evernote/note_store.rb | 74 | ||||
| -rw-r--r-- | lib/evernote/version.rb | 2 |
2 files changed, 63 insertions, 13 deletions
diff --git a/lib/evernote/note_store.rb b/lib/evernote/note_store.rb index 9293632..ef0212e 100644 --- a/lib/evernote/note_store.rb +++ b/lib/evernote/note_store.rb @@ -1,3 +1,6 @@ +# Needed for camelize +require 'active_support/core_ext/string/inflections' + module Evernote class NoteStore attr_reader :access_token, :notestore @@ -15,6 +18,14 @@ module Evernote end end + def update_count + sync_state.updateCount + end + + def sync_state + @sync_state ||= self.get_sync_state + end + # Camelize the method names for ruby consistency and push the access_token to the front of the args array def method_missing(name, *args, &block) @notestore.send(name.to_s.camelize(:lower), *(args.unshift(@access_token)), &block) @@ -31,15 +42,18 @@ module Evernote @offset = 0 @max = 100 end - + def notes @notes || all end + # TODO turn filter params into options + # where(:created => 'since', :updated => 'since', :words => '.....') + # ie. mimic the AR interface as much as practical def all(rows = max) @filter = NoteFilter.new @filter.notebook_guid = notebook.guid - @notes = wrap_notes(notestore.find_notes(filter, offset, rows).notes) + @notes = wrap_notes(notestore.find_notes(filter.filter, offset, rows).notes) end def updated_since(time, rows = max) @@ -72,15 +86,19 @@ module Evernote @notestore = notestore @note = note end + + def content(options = :enml) + @content ||= content!(options) + end - def content(options = :all) - @content ||= notestore.get_note(*args_from(options).unshift(note.guid)) + def content!(options = :enml) + @content = notestore.get_note(*args_from(options).unshift(note.guid)) end def enml content.content end - + def created @created ||= Time.at(note.created / 1000) end @@ -98,7 +116,13 @@ module Evernote end def resources - note.resources || [] + @resources ||= note.resources.inject([]) do |resources, resource| + resources.push Resource.new(notestore, resource) + end rescue [] + end + + def tags + @tags ||= notestore.get_note_tag_names(note.guid) end def method_missing(name, *args, &block) @@ -106,16 +130,42 @@ module Evernote end private + # Arguments are with_data, with_recognition, with_attributes, with_alternate_data def args_from(options) - if options == :all - return true, true, false, false - elsif options == :enml - return true, false, false, false - else - return true, false, false, false + options = :enml unless [:enml, :all].include?(options) + case options + when :all + [true, true, false, false] + when :enml + [true, false, false, false] end end + end + + class Resource + attr_reader :notestore, :resource + WITH_DATA = true + WITH_RECOGNITION = false + WITH_ATTRIBUTES = false + WITH_ALTERNATE_DATA = false + + def initialize(notestore, resource) + @notestore = notestore + @resource = resource + end + def body + @body ||= resource.data.body || + notestore.get_resource(self.guid, WITH_DATA, WITH_RECOGNITION, WITH_ATTRIBUTES, WITH_ALTERNATE_DATA).data.body + end + + def mime_type + defined?(Mime::Type) ? Mime::Type.lookup(self.mime) : self.mime + end + + def method_missing(name, *args, &block) + @resource.send(name.to_s.camelize(:lower), *args, &block) + end end class NoteFilter diff --git a/lib/evernote/version.rb b/lib/evernote/version.rb index 4549970..99a29e5 100644 --- a/lib/evernote/version.rb +++ b/lib/evernote/version.rb @@ -1,3 +1,3 @@ module Evernote - VERSION = "1.2.3" + VERSION = "1.3.0" end |
