evertils 2.0.2 → 2.1.0
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/README.md +2 -1
- data/evertils.gemspec +1 -1
- data/lib/evertils/action.rb +1 -1
- data/lib/evertils/action_runner.rb +23 -0
- data/lib/evertils/actions/create.rb +9 -1
- data/lib/evertils/actions/create_multiple.rb +24 -0
- data/lib/evertils/actions/duplicate_previous.rb +2 -2
- data/lib/evertils/config.rb +4 -17
- data/lib/evertils/controllers/render.rb +5 -30
- data/lib/evertils/helpers/formatting.rb +15 -0
- data/lib/evertils/type.rb +43 -0
- data/lib/evertils/version.rb +1 -1
- data/lib/evertils.rb +3 -0
- metadata +8 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 21365e228004a470654bca7506cdcbb1b650de3f533a9a9526378b886512feb6
         | 
| 4 | 
            +
              data.tar.gz: 88d857222088fc6614df75c79f598fb5f478ba6a42b29bc7ab2eb4a0d1681463
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4d51d610da5f984f3451d4ea3318f94921a05ec14b0560ecdbf8399bcb8ef1f9b1d39be2a6b724392b4cefc95cc1aeb8b2acd153039436eba964d811686af1c9
         | 
| 7 | 
            +
              data.tar.gz: 6eb94bfa2dff49d231eae40b2fe1d70e2e006706194a2532babb3b5f8c1c1745e373d396a9c23dc1ec3b63ba2741979bab9131c4bcc6f689effa31dbff8897a2
         | 
    
        data/README.md
    CHANGED
    
    | @@ -5,7 +5,8 @@ Evertils is a command line utility for interacting with your Evernote account. | |
| 5 5 | 
             
            ## Installation
         | 
| 6 6 |  | 
| 7 7 | 
             
            1. `gem install evertils`
         | 
| 8 | 
            -
            2.  | 
| 8 | 
            +
            2. `git clone git@github.com:aapis/evertils-config.git ~/.evertils`
         | 
| 9 | 
            +
            3. `mv ~/.evertils/config.dist.yml ~/.evertils/config.yml && nano ~/.config.yml`
         | 
| 9 10 |  | 
| 10 11 | 
             
            Get your Evernote Developer Tokens [here](https://www.evernote.com/Login.action?targetUrl=%2Fapi%2FDeveloperToken.action).
         | 
| 11 12 |  | 
    
        data/evertils.gemspec
    CHANGED
    
    | @@ -20,7 +20,7 @@ Gem::Specification.new do |s| | |
| 20 20 | 
             
              s.add_runtime_dependency 'notifaction', '~> 0.4.4'
         | 
| 21 21 | 
             
              s.add_runtime_dependency 'mime-types', '~> 3.3.1'
         | 
| 22 22 | 
             
              s.add_runtime_dependency 'evertils-common', '~> 0.3.7'
         | 
| 23 | 
            -
              s.add_runtime_dependency 'nokogiri'
         | 
| 23 | 
            +
              s.add_runtime_dependency 'nokogiri', '~> 1.10.9'
         | 
| 24 24 |  | 
| 25 25 | 
             
              s.add_development_dependency "bundler", "~> 1.10"
         | 
| 26 26 | 
             
              s.add_development_dependency "rake", "~> 12.3.3"
         | 
    
        data/lib/evertils/action.rb
    CHANGED
    
    
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Evertils
         | 
| 4 | 
            +
              class ActionRunner
         | 
| 5 | 
            +
                attr_accessor :params
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def execute
         | 
| 8 | 
            +
                  case params.action
         | 
| 9 | 
            +
                  when nil
         | 
| 10 | 
            +
                    Notify.info 'Action not provided, creating new note...'
         | 
| 11 | 
            +
                    Action::Create.new(params)
         | 
| 12 | 
            +
                  when 'create'
         | 
| 13 | 
            +
                    Action::Create.new(params)
         | 
| 14 | 
            +
                  when 'create_multiple'
         | 
| 15 | 
            +
                    Action::CreateMultiple.new(params.notes)
         | 
| 16 | 
            +
                  when 'duplicate_previous'
         | 
| 17 | 
            +
                    Action::DuplicatePrevious.new(params)
         | 
| 18 | 
            +
                  else
         | 
| 19 | 
            +
                    Action::Default.new(action: action)
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -6,8 +6,16 @@ module Evertils | |
| 6 6 | 
             
              module Action
         | 
| 7 7 | 
             
                class Create < Action::Base
         | 
| 8 8 | 
             
                  def initialize(args)
         | 
| 9 | 
            +
                    @args = args
         | 
| 9 10 | 
             
                    query = Evertils::Common::Query::Simple.new
         | 
| 10 | 
            -
             | 
| 11 | 
            +
             | 
| 12 | 
            +
                    query.create_note_from_hash(allowed_args)
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  private
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def allowed_args
         | 
| 18 | 
            +
                    @args.to_h.reject { |key, _| key == :action }
         | 
| 11 19 | 
             
                  end
         | 
| 12 20 | 
             
                end
         | 
| 13 21 | 
             
              end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Evertils
         | 
| 4 | 
            +
              module Action
         | 
| 5 | 
            +
                class CreateMultiple < Action::Base
         | 
| 6 | 
            +
                  def initialize(notes)
         | 
| 7 | 
            +
                    return unless notes.is_a? Array
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    notes.each do |child|
         | 
| 10 | 
            +
                      Notify.info("Creating #{child['label']}")
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      # avoid infinite recursion
         | 
| 13 | 
            +
                      next if ['create_multiple'].include?(child['action'])
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                      child['path'].gsub!('%EVERTILS_CONF_TYPE_PATH%', '~/.evertils/templates/type')
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                      runner = ActionRunner.new
         | 
| 18 | 
            +
                      runner.params = Evertils::Type.new(child['path']).params
         | 
| 19 | 
            +
                      runner.execute
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
| @@ -6,10 +6,10 @@ module Evertils | |
| 6 6 | 
             
                  def initialize(args)
         | 
| 7 7 | 
             
                    super(args)
         | 
| 8 8 |  | 
| 9 | 
            -
                    @args | 
| 9 | 
            +
                    @args.content = find_previous
         | 
| 10 10 |  | 
| 11 11 | 
             
                    query = Evertils::Common::Query::Simple.new
         | 
| 12 | 
            -
                    query.create_note_from_hash(@args)
         | 
| 12 | 
            +
                    query.create_note_from_hash(@args.to_h)
         | 
| 13 13 | 
             
                  end
         | 
| 14 14 |  | 
| 15 15 | 
             
                  private
         | 
    
        data/lib/evertils/config.rb
    CHANGED
    
    | @@ -47,7 +47,7 @@ module Evertils | |
| 47 47 | 
             
                # Populates the internal hash which stores any values set in the config file
         | 
| 48 48 | 
             
                def populate_config
         | 
| 49 49 | 
             
                  file = File.expand_path("~/.evertils/config.yml")
         | 
| 50 | 
            -
                  @yml = symbolize_keys(::YAML.load_file(file))
         | 
| 50 | 
            +
                  @yml = Evertils::Helper::Formatting.symbolize_keys(::YAML.load_file(file))
         | 
| 51 51 |  | 
| 52 52 | 
             
                  set_evertils_token
         | 
| 53 53 |  | 
| @@ -94,6 +94,8 @@ module Evertils | |
| 94 94 | 
             
                  title_format = @yml[:title].dup
         | 
| 95 95 |  | 
| 96 96 | 
             
                  @yml.map do |item|
         | 
| 97 | 
            +
                    break if item.last.is_a? Hash
         | 
| 98 | 
            +
             | 
| 97 99 | 
             
                    REPLACEMENTS.each_pair do |k, v|
         | 
| 98 100 | 
             
                      item.last.gsub!(k.to_s, v.to_s) if item.last.is_a? String
         | 
| 99 101 | 
             
                      item.last.map { |i| i.gsub!(k.to_s, v.to_s) } if item.last.is_a? Array
         | 
| @@ -102,25 +104,10 @@ module Evertils | |
| 102 104 |  | 
| 103 105 | 
             
                  @yml[:title_format] = title_format unless @yml.key? :title_format
         | 
| 104 106 |  | 
| 105 | 
            -
                  symbolize_keys(@yml)
         | 
| 107 | 
            +
                  Evertils::Helper::Formatting.symbolize_keys(@yml)
         | 
| 106 108 | 
             
                  self
         | 
| 107 109 | 
             
                end
         | 
| 108 110 |  | 
| 109 | 
            -
                def symbolize_keys(hash)
         | 
| 110 | 
            -
                  hash.inject({}){ |result, (key, value)|
         | 
| 111 | 
            -
                    new_key = case key
         | 
| 112 | 
            -
                              when String then key.to_sym
         | 
| 113 | 
            -
                              else key
         | 
| 114 | 
            -
                              end
         | 
| 115 | 
            -
                    new_value = case value
         | 
| 116 | 
            -
                                when Hash then symbolize_keys(value)
         | 
| 117 | 
            -
                                else value
         | 
| 118 | 
            -
                                end
         | 
| 119 | 
            -
                    result[new_key] = new_value
         | 
| 120 | 
            -
                    result
         | 
| 121 | 
            -
                  }
         | 
| 122 | 
            -
                end
         | 
| 123 | 
            -
             | 
| 124 111 | 
             
                private
         | 
| 125 112 |  | 
| 126 113 | 
             
                def set_evertils_token
         | 
| @@ -4,28 +4,14 @@ module Evertils | |
| 4 4 | 
             
              module Controller
         | 
| 5 5 | 
             
                class Render < Controller::Base
         | 
| 6 6 | 
             
                  def from_file
         | 
| 7 | 
            -
                     | 
| 7 | 
            +
                    configure_allowed_fields
         | 
| 8 8 |  | 
| 9 | 
            -
                     | 
| 9 | 
            +
                    runner = ActionRunner.new
         | 
| 10 | 
            +
                    runner.params = Evertils::Type.new(@allowed_fields[:path]).params
         | 
| 11 | 
            +
                    runner.execute
         | 
| 10 12 | 
             
                  end
         | 
| 11 13 |  | 
| 12 | 
            -
                  def  | 
| 13 | 
            -
                    case action
         | 
| 14 | 
            -
                    when nil
         | 
| 15 | 
            -
                      Notify.info 'Action not provided, creating new note...'
         | 
| 16 | 
            -
                      Action::Create.new(@allowed_fields)
         | 
| 17 | 
            -
                    when 'create'
         | 
| 18 | 
            -
                      Action::Create.new(@allowed_fields)
         | 
| 19 | 
            -
                    when 'duplicate_previous'
         | 
| 20 | 
            -
                      Action::DuplicatePrevious.new(@allowed_fields)
         | 
| 21 | 
            -
                    else
         | 
| 22 | 
            -
                      Action::Default.new(action: action)
         | 
| 23 | 
            -
                    end
         | 
| 24 | 
            -
                  end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  private
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  def set_allowed_fields
         | 
| 14 | 
            +
                  def configure_allowed_fields
         | 
| 29 15 | 
             
                    @allowed_fields = config.translate_placeholders.pluck(
         | 
| 30 16 | 
             
                      :title,
         | 
| 31 17 | 
             
                      :title_format,
         | 
| @@ -35,17 +21,6 @@ module Evertils | |
| 35 21 | 
             
                      :tags
         | 
| 36 22 | 
             
                    )
         | 
| 37 23 | 
             
                  end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                  def grammar
         | 
| 40 | 
            -
                    terms = Grammar.new
         | 
| 41 | 
            -
                    terms.notebook = @allowed_fields[:notebook]
         | 
| 42 | 
            -
                    terms.tags = {
         | 
| 43 | 
            -
                      day: Date.today.yday,
         | 
| 44 | 
            -
                      week: Date.today.cweek
         | 
| 45 | 
            -
                    }
         | 
| 46 | 
            -
                    terms.created = Date.new(Date.today.year, 1, 1).strftime('%Y%m%d')
         | 
| 47 | 
            -
                    terms
         | 
| 48 | 
            -
                  end
         | 
| 49 24 | 
             
                end
         | 
| 50 25 | 
             
              end
         | 
| 51 26 | 
             
            end
         | 
| @@ -18,6 +18,21 @@ module Evertils | |
| 18 18 | 
             
                      :'Priority Queue' => "Queue For [#{current_date.strftime('%B %-d')} - #{week_stub}]"
         | 
| 19 19 | 
             
                    }
         | 
| 20 20 | 
             
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def self.symbolize_keys(hash)
         | 
| 23 | 
            +
                    hash.inject({}){ |result, (key, value)|
         | 
| 24 | 
            +
                      new_key = case key
         | 
| 25 | 
            +
                                when String then key.to_sym
         | 
| 26 | 
            +
                                else key
         | 
| 27 | 
            +
                                end
         | 
| 28 | 
            +
                      new_value = case value
         | 
| 29 | 
            +
                                  when Hash then symbolize_keys(value)
         | 
| 30 | 
            +
                                  else value
         | 
| 31 | 
            +
                                  end
         | 
| 32 | 
            +
                      result[new_key] = new_value
         | 
| 33 | 
            +
                      result
         | 
| 34 | 
            +
                    }
         | 
| 35 | 
            +
                  end
         | 
| 21 36 | 
             
                end
         | 
| 22 37 | 
             
              end
         | 
| 23 38 | 
             
            end
         | 
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'ostruct'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Evertils
         | 
| 6 | 
            +
              class Type
         | 
| 7 | 
            +
                attr_reader :params
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(path)
         | 
| 10 | 
            +
                  begin
         | 
| 11 | 
            +
                    type_path = File.expand_path(path)
         | 
| 12 | 
            +
                    contents = YAML.load_file(type_path)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    return if contents.empty?
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    translate_variables(contents)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    @params = OpenStruct.new(contents)
         | 
| 19 | 
            +
                  rescue Errno::ENOENT
         | 
| 20 | 
            +
                    Notify.error("File doesn't exist - #{type_path}")
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def translate_variables(hash)
         | 
| 27 | 
            +
                  title_format = hash[:title].dup
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  hash.map do |item|
         | 
| 30 | 
            +
                    break if item.last.is_a? Hash
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    Evertils::Cfg::REPLACEMENTS.each_pair do |k, v|
         | 
| 33 | 
            +
                      item.last.gsub!(k.to_s, v.to_s) if item.last.is_a? String
         | 
| 34 | 
            +
                      item.last.map { |i| break if i.is_a? Hash; i.gsub!(k.to_s, v.to_s) } if item.last.is_a? Array
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  hash[:title_format] = title_format unless hash.key? :title_format
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  Evertils::Helper::Formatting.symbolize_keys(hash)
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
    
        data/lib/evertils/version.rb
    CHANGED
    
    
    
        data/lib/evertils.rb
    CHANGED
    
    | @@ -20,9 +20,12 @@ require 'nokogiri' | |
| 20 20 | 
             
            require 'evertils/kernel'
         | 
| 21 21 | 
             
            require 'evertils/version'
         | 
| 22 22 | 
             
            require 'evertils/base'
         | 
| 23 | 
            +
            require 'evertils/type'
         | 
| 23 24 | 
             
            require 'evertils/action'
         | 
| 25 | 
            +
            require 'evertils/action_runner'
         | 
| 24 26 | 
             
            require 'evertils/actions/default'
         | 
| 25 27 | 
             
            require 'evertils/actions/create'
         | 
| 28 | 
            +
            require 'evertils/actions/create_multiple'
         | 
| 26 29 | 
             
            require 'evertils/actions/duplicate_previous'
         | 
| 27 30 | 
             
            require 'evertils/helpers/results'
         | 
| 28 31 | 
             
            require 'evertils/helpers/api-enml-handler'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: evertils
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.0 | 
| 4 | 
            +
              version: 2.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ryan Priebe
         | 
| @@ -56,16 +56,16 @@ dependencies: | |
| 56 56 | 
             
              name: nokogiri
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 | 
            -
                - - " | 
| 59 | 
            +
                - - "~>"
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                    version:  | 
| 61 | 
            +
                    version: 1.10.9
         | 
| 62 62 | 
             
              type: :runtime
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 | 
            -
                - - " | 
| 66 | 
            +
                - - "~>"
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            -
                    version:  | 
| 68 | 
            +
                    version: 1.10.9
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: bundler
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -111,7 +111,9 @@ files: | |
| 111 111 | 
             
            - evertils.gemspec
         | 
| 112 112 | 
             
            - lib/evertils.rb
         | 
| 113 113 | 
             
            - lib/evertils/action.rb
         | 
| 114 | 
            +
            - lib/evertils/action_runner.rb
         | 
| 114 115 | 
             
            - lib/evertils/actions/create.rb
         | 
| 116 | 
            +
            - lib/evertils/actions/create_multiple.rb
         | 
| 115 117 | 
             
            - lib/evertils/actions/default.rb
         | 
| 116 118 | 
             
            - lib/evertils/actions/duplicate_previous.rb
         | 
| 117 119 | 
             
            - lib/evertils/base.rb
         | 
| @@ -135,6 +137,7 @@ files: | |
| 135 137 | 
             
            - lib/evertils/kernel.rb
         | 
| 136 138 | 
             
            - lib/evertils/request.rb
         | 
| 137 139 | 
             
            - lib/evertils/router.rb
         | 
| 140 | 
            +
            - lib/evertils/type.rb
         | 
| 138 141 | 
             
            - lib/evertils/vendor/enml.dtd
         | 
| 139 142 | 
             
            - lib/evertils/version.rb
         | 
| 140 143 | 
             
            homepage: http://rubygems.org/gems/evertils
         |