diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | evernote.gemspec | 7 | ||||
| -rw-r--r-- | lib/evernote/note_store.rb | 74 | ||||
| -rw-r--r-- | lib/evernote/version.rb | 2 | 
4 files changed, 70 insertions, 15 deletions
| @@ -7,3 +7,5 @@ pkg  *.bundle  ext/Makefile  ext/mkmf.log +Makefile +mkmf.log diff --git a/evernote.gemspec b/evernote.gemspec index 4bb6394..e6ec144 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" 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 | 
