From abf6d64a30feaa8d7e1b155fad989c930f1aaa7a Mon Sep 17 00:00:00 2001 From: Kip Cole Date: Sat, 6 Oct 2012 09:10:57 +0800 Subject: Refresh note content possible --- lib/evernote/note_store.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/evernote/note_store.rb b/lib/evernote/note_store.rb index 9293632..0f373a0 100644 --- a/lib/evernote/note_store.rb +++ b/lib/evernote/note_store.rb @@ -31,7 +31,7 @@ module Evernote @offset = 0 @max = 100 end - + def notes @notes || all end @@ -39,7 +39,7 @@ module Evernote 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,9 +72,9 @@ module Evernote @notestore = notestore @note = note end - + def content(options = :all) - @content ||= notestore.get_note(*args_from(options).unshift(note.guid)) + @content ||= get_content(options) end def enml @@ -101,6 +101,10 @@ module Evernote note.resources || [] end + def get_content(options = :all) + notestore.get_note(*args_from(options).unshift(note.guid)) + end + def method_missing(name, *args, &block) @note.send(name.to_s.camelize(:lower), *args, &block) end @@ -115,6 +119,7 @@ module Evernote return true, false, false, false end end + end -- cgit v1.2.3 From db09dd23cd9b520441397acc4f82961fc3f58790 Mon Sep 17 00:00:00 2001 From: Kip Cole Date: Sat, 6 Oct 2012 12:04:31 +0800 Subject: Further work on the Evernote wrapper API --- .gitignore | 2 ++ lib/evernote/note_store.rb | 70 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 71de91a..85ffe6d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ pkg *.bundle ext/Makefile ext/mkmf.log +Makefile +mkmf.log diff --git a/lib/evernote/note_store.rb b/lib/evernote/note_store.rb index 0f373a0..f6186ff 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) @@ -36,6 +47,9 @@ module Evernote @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 @@ -73,14 +87,18 @@ module Evernote @note = note end - def content(options = :all) - @content ||= get_content(options) + def content(options = :enml) + @content ||= content!(options) + end + + 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,11 +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 get_content(options = :all) - notestore.get_note(*args_from(options).unshift(note.guid)) + def tags + @tags ||= notestore.get_note_tag_names(note.guid) end def method_missing(name, *args, &block) @@ -111,16 +131,40 @@ module Evernote private 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 -- cgit v1.2.3 From e5264b0b1afaf2e7d64f379ab76ba69fd31ef49c Mon Sep 17 00:00:00 2001 From: Kip Cole Date: Sat, 6 Oct 2012 12:09:30 +0800 Subject: Bump version --- lib/evernote/note_store.rb | 1 + lib/evernote/version.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/evernote/note_store.rb b/lib/evernote/note_store.rb index f6186ff..ef0212e 100644 --- a/lib/evernote/note_store.rb +++ b/lib/evernote/note_store.rb @@ -130,6 +130,7 @@ module Evernote end private + # Arguments are with_data, with_recognition, with_attributes, with_alternate_data def args_from(options) options = :enml unless [:enml, :all].include?(options) case options 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 -- cgit v1.2.3 From 1e2076c22c470ea2566abd40de9d9be5eae71afa Mon Sep 17 00:00:00 2001 From: Kip Cole Date: Sun, 7 Oct 2012 14:44:28 +0800 Subject: Add activesupport dependency --- evernote.gemspec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/evernote.gemspec b/evernote.gemspec index 42516ec..288feae 100644 --- a/evernote.gemspec +++ b/evernote.gemspec @@ -5,8 +5,8 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) require "evernote/version" Gem::Specification.new do |s| - s.name = "evernote" - s.version = Evernote::VERSION + s.name = "evernote" + s.version = Evernote::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Kip Cole", "Chris Sepic"] s.email = ["kipcole9@gmail.com", "chris.sepic@gmail.com"] @@ -16,6 +16,9 @@ Gem::Specification.new do |s| s.required_rubygems_version = ">= 1.3.6" + # Activesupport provides the #camelize function we use + s.add_dependency "activesupport" + s.add_development_dependency "rspec" s.add_development_dependency "yard" -- cgit v1.2.3