evertils-common 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/evertils/common/entity/note.rb +118 -0
- data/lib/evertils/common/entity/notebook.rb +90 -0
- data/lib/evertils/common/entity/notebooks.rb +21 -0
- data/lib/evertils/common/entity/notes.rb +33 -0
- data/lib/evertils/common/evernote.rb +23 -195
- data/lib/evertils/common/results_helper.rb +22 -0
- data/lib/evertils/common/version.rb +1 -1
- metadata +7 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 802848f9bf8bcfb3aba2b79cb7d90cd037294e2d
         | 
| 4 | 
            +
              data.tar.gz: 3036cfd81d6cb710203a10020e13495270204258
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 04cafceb90639c8149be97103211fb7d37cc92d406a56585af820edc229c737f95c0b2caef87ace0ba1cfb6a73c55fbaf205bbd4712819c2a190ef0ece6a6d34
         | 
| 7 | 
            +
              data.tar.gz: 19c7427b1c0b941b7c7df7939c2d6b0a8c0eadc8da675aefba006d288a502fc945bd730cab9317a4086ede1791e534e2ae26b7abe5e9167d361bb7c336128db1
         | 
| @@ -0,0 +1,118 @@ | |
| 1 | 
            +
            require 'evertils/common/authentication'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Evertils
         | 
| 4 | 
            +
              module Common
         | 
| 5 | 
            +
                module Entity
         | 
| 6 | 
            +
                  class Note
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    def initialize
         | 
| 9 | 
            +
                      @evernote = Authentication.new.store
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    def create_from_yml(full_path)
         | 
| 13 | 
            +
                      begin
         | 
| 14 | 
            +
                        if File.exists? full_path
         | 
| 15 | 
            +
                          conf = YAML::load(File.open(full_path))
         | 
| 16 | 
            +
                          required = %w(title body)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                          if has_required_fields(conf, required)
         | 
| 19 | 
            +
                            create(conf['title'], conf['body'], conf['parent'])
         | 
| 20 | 
            +
                          else
         | 
| 21 | 
            +
                            raise ArgumentError, 'Configuration file is missing some required fields'
         | 
| 22 | 
            +
                          end
         | 
| 23 | 
            +
                        else
         | 
| 24 | 
            +
                          raise ArgumentError, "File not found: #{full_path}"
         | 
| 25 | 
            +
                        end
         | 
| 26 | 
            +
                      rescue ArgumentError => e
         | 
| 27 | 
            +
                        puts e.message
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def create(title, body = template_contents, p_notebook_name = nil, file = nil, share_note = false, created_on = nil)
         | 
| 32 | 
            +
                      # final output
         | 
| 33 | 
            +
                      output = {}
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                      # Create note object
         | 
| 36 | 
            +
                      our_note = ::Evernote::EDAM::Type::Note.new
         | 
| 37 | 
            +
                      our_note.resources = []
         | 
| 38 | 
            +
                      our_note.tagNames = []
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                      # only join when required
         | 
| 41 | 
            +
                      if body.is_a? Array
         | 
| 42 | 
            +
                        body = body.join
         | 
| 43 | 
            +
                      end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                      # a file was requested, lets prepare it for storage
         | 
| 46 | 
            +
                      if !file.nil?
         | 
| 47 | 
            +
                        media_resource = ENML.new(file)
         | 
| 48 | 
            +
                        body.concat(media_resource.embeddable_element)
         | 
| 49 | 
            +
                        our_note.resources << media_resource.element
         | 
| 50 | 
            +
                      end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                      n_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
         | 
| 53 | 
            +
                      n_body += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
         | 
| 54 | 
            +
                      n_body += "<en-note>#{body}</en-note>"
         | 
| 55 | 
            +
                     
         | 
| 56 | 
            +
                      # setup note properties
         | 
| 57 | 
            +
                      our_note.title = title
         | 
| 58 | 
            +
                      our_note.content = n_body
         | 
| 59 | 
            +
                      our_note.created = created_on if !created_on.nil?
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                      nb = Entity::Notebook.new
         | 
| 62 | 
            +
                      parent_notebook = nb.find(p_notebook_name)
         | 
| 63 | 
            +
                      
         | 
| 64 | 
            +
                      ## parent_notebook is optional; if omitted, default notebook is used
         | 
| 65 | 
            +
                      if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
         | 
| 66 | 
            +
                        our_note.notebookGuid = parent_notebook.guid
         | 
| 67 | 
            +
                      end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                      ## Attempt to create note in Evernote account
         | 
| 70 | 
            +
                      begin
         | 
| 71 | 
            +
                        output[:note] = @evernote.createNote(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, our_note)
         | 
| 72 | 
            +
                        
         | 
| 73 | 
            +
                        if share_note
         | 
| 74 | 
            +
                          shareKey = @evernote.shareNote(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, output[:note].guid)
         | 
| 75 | 
            +
                          output[:share_url] = "https://#{Evertils::Common::EVERNOTE_HOST}/shard/#{@model.shardId}/sh/#{output[:note].guid}/#{shareKey}"
         | 
| 76 | 
            +
                        end
         | 
| 77 | 
            +
                      rescue ::Evernote::EDAM::Error::EDAMUserException => edue
         | 
| 78 | 
            +
                        ## Something was wrong with the note data
         | 
| 79 | 
            +
                        ## See EDAMErrorCode enumeration for error code explanation
         | 
| 80 | 
            +
                        ## http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
         | 
| 81 | 
            +
                        Notify.error "EDAMUserException: #{edue}\nCode #{edue.errorCode}: #{edue.parameter}"
         | 
| 82 | 
            +
                      rescue ::Evernote::EDAM::Error::EDAMNotFoundException => ednfe
         | 
| 83 | 
            +
                        ## Parent Notebook GUID doesn't correspond to an actual notebook
         | 
| 84 | 
            +
                        Notify.error "EDAMNotFoundException: Invalid parent notebook GUID"
         | 
| 85 | 
            +
                      end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                      # A parent notebook object exists, otherwise it was saved to the default
         | 
| 88 | 
            +
                      # notebook
         | 
| 89 | 
            +
                      if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
         | 
| 90 | 
            +
                        Notify.success("#{parent_notebook.stack}/#{parent_notebook.name}/#{our_note.title} created")
         | 
| 91 | 
            +
                      else
         | 
| 92 | 
            +
                        Notify.success("DEFAULT_NOTEBOOK/#{our_note.title} created")
         | 
| 93 | 
            +
                      end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                      output
         | 
| 96 | 
            +
                    end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                    def exists?(name)
         | 
| 99 | 
            +
                      notes = Notes.new
         | 
| 100 | 
            +
                      notes.findAll(name).totalNotes > 0
         | 
| 101 | 
            +
                    end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                    def destroy(name)
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                    end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                    private
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                    def has_required_fields(hash, required)
         | 
| 110 | 
            +
                      hash.keys.each do |key|
         | 
| 111 | 
            +
                        required.include? key
         | 
| 112 | 
            +
                      end
         | 
| 113 | 
            +
                    end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
            end
         | 
| @@ -0,0 +1,90 @@ | |
| 1 | 
            +
            require 'evertils/common/authentication'
         | 
| 2 | 
            +
            require 'evertils/common/entity/notebooks'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Evertils
         | 
| 5 | 
            +
              module Common
         | 
| 6 | 
            +
                module Entity
         | 
| 7 | 
            +
                  class Notebook
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    def initialize
         | 
| 10 | 
            +
                      @evernote = Authentication.new.store
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      self
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    def find(name)
         | 
| 16 | 
            +
                      notebooks = Notebooks.new.all
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                      notebooks.each do |notebook|
         | 
| 19 | 
            +
                        if notebook.name == name.to_s.capitalize
         | 
| 20 | 
            +
                          @notebook = notebook
         | 
| 21 | 
            +
                        end
         | 
| 22 | 
            +
                      end
         | 
| 23 | 
            +
                      
         | 
| 24 | 
            +
                      @notebook
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def create_from_yml(full_path)
         | 
| 28 | 
            +
                      begin
         | 
| 29 | 
            +
                        if File.exists? full_path
         | 
| 30 | 
            +
                          conf = YAML::load(File.open(full_path))
         | 
| 31 | 
            +
                          required = %w(name children)
         | 
| 32 | 
            +
                          
         | 
| 33 | 
            +
                          if has_required_fields(conf, required)
         | 
| 34 | 
            +
                            if !conf["children"].nil?
         | 
| 35 | 
            +
                              conf["children"].each do |name|
         | 
| 36 | 
            +
                                create(name, conf["name"])
         | 
| 37 | 
            +
                              end
         | 
| 38 | 
            +
                            end
         | 
| 39 | 
            +
                          else
         | 
| 40 | 
            +
                            raise ArgumentError, 'Configuration file is missing some required fields'
         | 
| 41 | 
            +
                          end
         | 
| 42 | 
            +
                        else
         | 
| 43 | 
            +
                          raise ArgumentError, "File not found: #{full_path}"
         | 
| 44 | 
            +
                        end
         | 
| 45 | 
            +
                      rescue ArgumentError => e
         | 
| 46 | 
            +
                        puts e.message
         | 
| 47 | 
            +
                      end
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    def create(name, stack = nil)
         | 
| 51 | 
            +
                      notebook = ::Evernote::EDAM::Type::Notebook.new
         | 
| 52 | 
            +
                      notebook.name = name
         | 
| 53 | 
            +
                      
         | 
| 54 | 
            +
                      if !stack.nil?
         | 
| 55 | 
            +
                        notebook.stack = stack
         | 
| 56 | 
            +
                        notebook.name = "#{stack}/#{name}"
         | 
| 57 | 
            +
                      end
         | 
| 58 | 
            +
                      
         | 
| 59 | 
            +
                      @evernote.createNotebook(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, notebook)
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    def destroy()
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    def notes(guid = nil)
         | 
| 67 | 
            +
                      filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
         | 
| 68 | 
            +
                      filter.notebookGuid = @notebook.guid
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                      result = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
         | 
| 71 | 
            +
                      result.includeTitle = true
         | 
| 72 | 
            +
                      result.includeUpdated = true
         | 
| 73 | 
            +
                      result.includeTagGuids = true
         | 
| 74 | 
            +
                      
         | 
| 75 | 
            +
                      notes = Notes.new
         | 
| 76 | 
            +
                      notes.find(nil, @notebook.guid)
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                    private
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                    def has_required_fields(hash, required)
         | 
| 82 | 
            +
                      hash.keys.each do |key|
         | 
| 83 | 
            +
                        required.include? key
         | 
| 84 | 
            +
                      end
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'evertils/common/authentication'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Evertils
         | 
| 4 | 
            +
              module Common
         | 
| 5 | 
            +
                module Entity
         | 
| 6 | 
            +
                  class Notebooks
         | 
| 7 | 
            +
                    
         | 
| 8 | 
            +
                    def initialize
         | 
| 9 | 
            +
                      @evernote = Authentication.new.store
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                      self
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    def all
         | 
| 15 | 
            +
                      @evernote.listNotebooks(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require 'evertils/common/authentication'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Evertils
         | 
| 4 | 
            +
              module Common
         | 
| 5 | 
            +
                module Entity
         | 
| 6 | 
            +
                  class Notes
         | 
| 7 | 
            +
                    
         | 
| 8 | 
            +
                    def initialize
         | 
| 9 | 
            +
                      @evernote = Authentication.new.store
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                      self
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    def findAll(title, notebook = nil)
         | 
| 15 | 
            +
                      filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
         | 
| 16 | 
            +
                      filter.words = "intitle:#{title}" if title
         | 
| 17 | 
            +
                      filter.notebookGuid = notebook if notebook
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      @evernote.findNotes(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, nil, 300)
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    def findOne(title, notebook = nil)
         | 
| 23 | 
            +
                      filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
         | 
| 24 | 
            +
                      filter.words = "intitle:#{title}" if title
         | 
| 25 | 
            +
                      filter.notebookGuid = notebook if notebook
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                      @evernote.findNotes(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, nil, 1)
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -1,16 +1,17 @@ | |
| 1 1 | 
             
            require 'yaml'
         | 
| 2 | 
            -
            require 'evertils/common/authentication'
         | 
| 3 2 | 
             
            require 'evertils/common/enml'
         | 
| 3 | 
            +
            require 'evertils/common/results_helper'
         | 
| 4 | 
            +
            require 'evertils/common/entity/notebooks'
         | 
| 5 | 
            +
            require 'evertils/common/entity/notebook'
         | 
| 6 | 
            +
            require 'evertils/common/entity/notes'
         | 
| 7 | 
            +
            require 'evertils/common/entity/note'
         | 
| 4 8 |  | 
| 5 9 | 
             
            module Evertils
         | 
| 6 10 | 
             
              module Common
         | 
| 7 11 | 
             
                class Evernote
         | 
| 8 | 
            -
                  def initialize
         | 
| 9 | 
            -
                    @evernote = Evertils::Common::Authentication.new
         | 
| 10 | 
            -
                  end
         | 
| 11 12 |  | 
| 12 13 | 
             
                  def notebooks
         | 
| 13 | 
            -
                     | 
| 14 | 
            +
                    Entity::Notebooks.new.all
         | 
| 14 15 | 
             
                  end
         | 
| 15 16 |  | 
| 16 17 | 
             
                  def tags
         | 
| @@ -18,219 +19,46 @@ module Evertils | |
| 18 19 | 
             
                  end
         | 
| 19 20 |  | 
| 20 21 | 
             
                  def notebook_by_name(name)
         | 
| 21 | 
            -
                     | 
| 22 | 
            -
                     | 
| 23 | 
            -
                      if notebook.name == name.to_s.capitalize
         | 
| 24 | 
            -
                        output = notebook
         | 
| 25 | 
            -
                      end
         | 
| 26 | 
            -
                    end
         | 
| 27 | 
            -
                    
         | 
| 28 | 
            -
                    output
         | 
| 22 | 
            +
                    nb = Entity::Notebook.new
         | 
| 23 | 
            +
                    nb.find(name)
         | 
| 29 24 | 
             
                  end
         | 
| 30 25 |  | 
| 31 26 | 
             
                  def notes_by_notebook(name)
         | 
| 32 | 
            -
                     | 
| 33 | 
            -
                     | 
| 34 | 
            -
             | 
| 35 | 
            -
                        filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
         | 
| 36 | 
            -
                        filter.notebookGuid = notebook.guid
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                        result = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
         | 
| 39 | 
            -
                        result.includeTitle = true
         | 
| 40 | 
            -
                        result.includeUpdated = true
         | 
| 41 | 
            -
                        result.includeTagGuids = true
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                        #output = @evernote.store.findNotesMetadata(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, 0, 400, result)
         | 
| 44 | 
            -
                        notes(nil, notebook.guid).notes.each do |note|
         | 
| 45 | 
            -
                          output[note.guid] = @evernote.store.getNoteContent(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, note.guid)
         | 
| 46 | 
            -
                        end
         | 
| 47 | 
            -
                      end
         | 
| 48 | 
            -
                    end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                    output
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                  def notebooks_by_stack(stack)
         | 
| 54 | 
            -
                    output = {}
         | 
| 55 | 
            -
                    notebooks.each do |notebook|
         | 
| 56 | 
            -
                      if notebook.stack == stack
         | 
| 57 | 
            -
                        #output[notebook.name] = []
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                        filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
         | 
| 60 | 
            -
                        filter.notebookGuid = notebook.guid
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                        result = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
         | 
| 63 | 
            -
                        result.includeTitle = true
         | 
| 64 | 
            -
                        result.includeUpdated = true
         | 
| 65 | 
            -
                        result.includeTagGuids = true
         | 
| 66 | 
            -
             | 
| 67 | 
            -
                        notes = @evernote.store.findNotesMetadata(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, 0, 400, result)
         | 
| 68 | 
            -
                        output[notebook.name] = notes
         | 
| 69 | 
            -
                      end
         | 
| 70 | 
            -
                    end
         | 
| 71 | 
            -
                    
         | 
| 72 | 
            -
                    output
         | 
| 27 | 
            +
                    nb = Entity::Notebook.new
         | 
| 28 | 
            +
                    nb.find(name)
         | 
| 29 | 
            +
                    nb.notes
         | 
| 73 30 | 
             
                  end
         | 
| 74 31 |  | 
| 75 32 | 
             
                  def create_stack_from(full_path)
         | 
| 76 | 
            -
                     | 
| 77 | 
            -
             | 
| 78 | 
            -
                      required = %w(name children)
         | 
| 79 | 
            -
                      
         | 
| 80 | 
            -
                      if has_required_fields(conf, required)
         | 
| 81 | 
            -
                        if !conf["children"].nil?
         | 
| 82 | 
            -
                          conf["children"].each do |name|
         | 
| 83 | 
            -
                            create_notebook(name, conf["name"])
         | 
| 84 | 
            -
                          end
         | 
| 85 | 
            -
                        end
         | 
| 86 | 
            -
                      else
         | 
| 87 | 
            -
                        raise ArgumentError, 'Configuration file is missing some required fields'
         | 
| 88 | 
            -
                      end
         | 
| 89 | 
            -
                    else
         | 
| 90 | 
            -
                      raise ArgumentError, "File not found: #{full_path}"
         | 
| 91 | 
            -
                    end
         | 
| 33 | 
            +
                    nb = Entity::Notebook.new
         | 
| 34 | 
            +
                    nb.create_from_yml(full_path)
         | 
| 92 35 | 
             
                  end
         | 
| 93 36 |  | 
| 94 37 | 
             
                  def create_note_from(full_path)
         | 
| 95 | 
            -
                     | 
| 96 | 
            -
             | 
| 97 | 
            -
                      required = %w(title body)
         | 
| 98 | 
            -
             | 
| 99 | 
            -
                      if has_required_fields(conf, required)
         | 
| 100 | 
            -
                        create_note(conf['title'], conf['body'], conf['parent'])
         | 
| 101 | 
            -
                      else
         | 
| 102 | 
            -
                        raise ArgumentError, 'Configuration file is missing some required fields'
         | 
| 103 | 
            -
                      end
         | 
| 104 | 
            -
                    else
         | 
| 105 | 
            -
                      raise ArgumentError, "File not found: #{full_path}"
         | 
| 106 | 
            -
                    end
         | 
| 107 | 
            -
                  end
         | 
| 108 | 
            -
             | 
| 109 | 
            -
                  def create_stack(name)
         | 
| 110 | 
            -
                    create_notebook(name)
         | 
| 38 | 
            +
                    note = Entity::Note.new
         | 
| 39 | 
            +
                    note.create_from_yml(full_path)
         | 
| 111 40 | 
             
                  end
         | 
| 112 41 |  | 
| 113 42 | 
             
                  def create_notebook(name, stack = nil)
         | 
| 114 | 
            -
                     | 
| 115 | 
            -
                     | 
| 116 | 
            -
                    
         | 
| 117 | 
            -
                    if !stack.nil?
         | 
| 118 | 
            -
                      notebook.stack = stack
         | 
| 119 | 
            -
                      notebook.name = "#{stack}/#{name}"
         | 
| 120 | 
            -
                    end
         | 
| 121 | 
            -
             | 
| 122 | 
            -
                    @evernote.store.createNotebook(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, notebook)
         | 
| 43 | 
            +
                    nb = Entity::Notebook.new
         | 
| 44 | 
            +
                    nb.create(name, stack)
         | 
| 123 45 | 
             
                  end
         | 
| 124 46 |  | 
| 125 47 | 
             
                  def find_note(title_filter = nil, notebook_filter = nil)
         | 
| 126 | 
            -
                     | 
| 127 | 
            -
                     | 
| 128 | 
            -
                    filter.notebookGuid = notebook_filter if notebook_filter
         | 
| 129 | 
            -
             | 
| 130 | 
            -
                    @evernote.store.findNotes(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, nil, 1)
         | 
| 131 | 
            -
                  end
         | 
| 132 | 
            -
             | 
| 133 | 
            -
                  def notes(title_filter = nil, notebook_filter = nil)
         | 
| 134 | 
            -
                    filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
         | 
| 135 | 
            -
                    filter.words = "intitle:#{title_filter}" if title_filter
         | 
| 136 | 
            -
                    filter.notebookGuid = notebook_filter if notebook_filter
         | 
| 137 | 
            -
             | 
| 138 | 
            -
                    @evernote.store.findNotes(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, nil, 300)
         | 
| 48 | 
            +
                    note = Entity::Note.new
         | 
| 49 | 
            +
                    note.find(title_filter, notebook_filter)
         | 
| 139 50 | 
             
                  end
         | 
| 140 51 |  | 
| 141 52 | 
             
                  def note_exists(requested_date = DateTime.now)
         | 
| 142 | 
            -
                     | 
| 143 | 
            -
                     | 
| 144 | 
            -
                    template = tmpl[command]
         | 
| 145 | 
            -
                    note = find_note(template)
         | 
| 146 | 
            -
             | 
| 147 | 
            -
                    # Evernote's search matches things like the following, so we have to get
         | 
| 148 | 
            -
                    # more specific
         | 
| 149 | 
            -
                    #   Daily Log [July 3 - F] == Daily Log [July 10 - F]
         | 
| 150 | 
            -
                    if note.totalNotes > 0
         | 
| 151 | 
            -
                      note.notes.each do |n|
         | 
| 152 | 
            -
                        results.add(n.title != template)
         | 
| 153 | 
            -
                      end
         | 
| 154 | 
            -
                    else
         | 
| 155 | 
            -
                      results.add(true)
         | 
| 156 | 
            -
                    end
         | 
| 157 | 
            -
             | 
| 158 | 
            -
                    results.should_eval_to(false)
         | 
| 53 | 
            +
                    note = Note.new
         | 
| 54 | 
            +
                    note.exists? nil, requested_date
         | 
| 159 55 | 
             
                  end
         | 
| 160 56 |  | 
| 161 57 | 
             
                  def create_note(title, body = template_contents, p_notebook_name = nil, file = nil, share_note = false, created_on = nil)
         | 
| 162 | 
            -
                     | 
| 163 | 
            -
                     | 
| 164 | 
            -
             | 
| 165 | 
            -
                    # Create note object
         | 
| 166 | 
            -
                    our_note = ::Evernote::EDAM::Type::Note.new
         | 
| 167 | 
            -
                    our_note.resources = []
         | 
| 168 | 
            -
                    our_note.tagNames = []
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                    # only join when required
         | 
| 171 | 
            -
                    if body.is_a? Array
         | 
| 172 | 
            -
                      body = body.join
         | 
| 173 | 
            -
                    end
         | 
| 174 | 
            -
             | 
| 175 | 
            -
                    # a file was requested, lets prepare it for storage
         | 
| 176 | 
            -
                    if !file.nil?
         | 
| 177 | 
            -
                      media_resource = ENML.new(file)
         | 
| 178 | 
            -
                      body.concat(media_resource.embeddable_element)
         | 
| 179 | 
            -
                      our_note.resources << media_resource.element
         | 
| 180 | 
            -
                    end
         | 
| 181 | 
            -
             | 
| 182 | 
            -
                    n_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
         | 
| 183 | 
            -
                    n_body += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
         | 
| 184 | 
            -
                    n_body += "<en-note>#{body}</en-note>"
         | 
| 185 | 
            -
                   
         | 
| 186 | 
            -
                    # setup note properties
         | 
| 187 | 
            -
                    our_note.title = title
         | 
| 188 | 
            -
                    our_note.content = n_body
         | 
| 189 | 
            -
                    our_note.created = created_on if !created_on.nil?
         | 
| 190 | 
            -
             | 
| 191 | 
            -
                    parent_notebook = notebook_by_name(p_notebook_name)
         | 
| 192 | 
            -
                    
         | 
| 193 | 
            -
                    ## parent_notebook is optional; if omitted, default notebook is used
         | 
| 194 | 
            -
                    if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
         | 
| 195 | 
            -
                      our_note.notebookGuid = parent_notebook.guid
         | 
| 196 | 
            -
                    end
         | 
| 197 | 
            -
             | 
| 198 | 
            -
                    ## Attempt to create note in Evernote account
         | 
| 199 | 
            -
                    begin
         | 
| 200 | 
            -
                      output[:note] = @evernote.store.createNote(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, our_note)
         | 
| 201 | 
            -
                      
         | 
| 202 | 
            -
                      if share_note
         | 
| 203 | 
            -
                        shareKey = @evernote.store.shareNote(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, output[:note].guid)
         | 
| 204 | 
            -
                        output[:share_url] = "https://#{Evertils::Common::EVERNOTE_HOST}/shard/#{@model.shardId}/sh/#{output[:note].guid}/#{shareKey}"
         | 
| 205 | 
            -
                      end
         | 
| 206 | 
            -
                    rescue ::Evernote::EDAM::Error::EDAMUserException => edue
         | 
| 207 | 
            -
                      ## Something was wrong with the note data
         | 
| 208 | 
            -
                      ## See EDAMErrorCode enumeration for error code explanation
         | 
| 209 | 
            -
                      ## http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
         | 
| 210 | 
            -
                      Notify.error "EDAMUserException: #{edue}\nCode #{edue.errorCode}: #{edue.parameter}"
         | 
| 211 | 
            -
                    rescue ::Evernote::EDAM::Error::EDAMNotFoundException => ednfe
         | 
| 212 | 
            -
                      ## Parent Notebook GUID doesn't correspond to an actual notebook
         | 
| 213 | 
            -
                      Notify.error "EDAMNotFoundException: Invalid parent notebook GUID"
         | 
| 214 | 
            -
                    end
         | 
| 215 | 
            -
             | 
| 216 | 
            -
                    # A parent notebook object exists, otherwise it was saved to the default
         | 
| 217 | 
            -
                    # notebook
         | 
| 218 | 
            -
                    if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
         | 
| 219 | 
            -
                      Notify.success("#{parent_notebook.stack}/#{parent_notebook.name}/#{our_note.title} created")
         | 
| 220 | 
            -
                    else
         | 
| 221 | 
            -
                      Notify.success("DEFAULT_NOTEBOOK/#{our_note.title} created")
         | 
| 222 | 
            -
                    end
         | 
| 223 | 
            -
             | 
| 224 | 
            -
                    output
         | 
| 58 | 
            +
                    note = Note.new
         | 
| 59 | 
            +
                    note.create(title, body, p_notebook_name, file, share_note, created_on)
         | 
| 225 60 | 
             
                  end
         | 
| 226 61 |  | 
| 227 | 
            -
                  private
         | 
| 228 | 
            -
             | 
| 229 | 
            -
                  def has_required_fields(hash, required)        
         | 
| 230 | 
            -
                    hash.keys.each do |key|
         | 
| 231 | 
            -
                      required.include? key
         | 
| 232 | 
            -
                    end
         | 
| 233 | 
            -
                  end
         | 
| 234 62 | 
             
                end
         | 
| 235 63 | 
             
              end
         | 
| 236 64 | 
             
            end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            module Evertils
         | 
| 2 | 
            +
              module Common
         | 
| 3 | 
            +
                class Results
         | 
| 4 | 
            +
                  attr_reader :bucket
         | 
| 5 | 
            +
                  
         | 
| 6 | 
            +
                  def initialize
         | 
| 7 | 
            +
                    @bucket = []
         | 
| 8 | 
            +
                    @bucket
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # Add a result for processing
         | 
| 12 | 
            +
                  def add(result)
         | 
| 13 | 
            +
                    @bucket.push(result.to_bool)
         | 
| 14 | 
            +
                    result.to_bool
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def should_eval_to(pass_value)
         | 
| 18 | 
            +
                    @bucket.all? == pass_value
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: evertils-common
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ryan Priebe
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-12- | 
| 11 | 
            +
            date: 2015-12-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -86,7 +86,12 @@ files: | |
| 86 86 | 
             
            - lib/evertils/common.rb
         | 
| 87 87 | 
             
            - lib/evertils/common/authentication.rb
         | 
| 88 88 | 
             
            - lib/evertils/common/enml.rb
         | 
| 89 | 
            +
            - lib/evertils/common/entity/note.rb
         | 
| 90 | 
            +
            - lib/evertils/common/entity/notebook.rb
         | 
| 91 | 
            +
            - lib/evertils/common/entity/notebooks.rb
         | 
| 92 | 
            +
            - lib/evertils/common/entity/notes.rb
         | 
| 89 93 | 
             
            - lib/evertils/common/evernote.rb
         | 
| 94 | 
            +
            - lib/evertils/common/results_helper.rb
         | 
| 90 95 | 
             
            - lib/evertils/common/version.rb
         | 
| 91 96 | 
             
            homepage: http://rubygems.org/gems/evertils-common
         | 
| 92 97 | 
             
            licenses:
         |