evertils 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65d895569799db5920d1b76e561a6a363fae85ee
4
- data.tar.gz: f1acb30f9bbc5438504d9352977f2d1d159030e5
3
+ metadata.gz: 07a3dcfb90a36fe908d3631fd2913c8d11beb75d
4
+ data.tar.gz: 06ab1f37824726351c99669bbcd11be3a80aee32
5
5
  SHA512:
6
- metadata.gz: f3d37d95646c11d7478323ef7f71209babfc096ba21b3bd1f8bb1a0c9cae6e0026a8976a30a0052821283a76bbd6c63d5f1d3f31d9226775dbe4bb5a32df719f
7
- data.tar.gz: d005df3a6f82e6e30106816083ca3216730907908b4cb0b5bde02e6681bd90b67f1c6024d19fb5be6803313b0e4d8feeb396108235fb5b80ca08f49bc679f132
6
+ metadata.gz: 4f86f711952cf2be0a52e20a1b601158e945de39f1eb9c1ee6841d04ff85a67281e2809679d4101698783bec98ba7443c058d17734a3b5e56d2ea07cb93414cf
7
+ data.tar.gz: 9ec2672767c26c57e5241cf6fdd16c46daed47502b8751478244050439a4f85c45c5bb23b4aa1e948e17a9a208d6c47ec6c2e987f0adb7736b8bf9594392075f
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "rubocop"
4
- gem "notifaction"
5
- gem "evernote-thrift"
6
- gem "mime-types"
3
+ gem 'rubocop'
4
+ gem 'notifaction'
5
+ gem 'evernote-thrift'
6
+ gem 'mime-types'
7
+ gem 'rake'
data/README.md CHANGED
@@ -10,7 +10,7 @@ Utilities for talking to your Evernote account. Create notes, generate statisti
10
10
  Get your Evernote Developer Tokens [here](https://www.evernote.com/Login.action?targetUrl=%2Fapi%2FDeveloperToken.action).
11
11
 
12
12
  ## Logging Specification
13
- See [this document](LOGGING_SPECIFICATION.md) to see how it all gets organized.
13
+ See [this document](https://github.com/aapis/evertils/wiki/Logging-Specification) to see how it all gets organized.
14
14
 
15
15
  ## How to Use
16
16
 
@@ -20,3 +20,4 @@ See [this document](LOGGING_SPECIFICATION.md) to see how it all gets organized.
20
20
  |new|Manually create notes|`evertils new note "STUFF"`, `evertils new share_note "STUFF"`, `other task | evertils new share_note --title="Piped data note"`|
21
21
  |get|Get data from Evernote|`evertils get notebook`|
22
22
  |convert|Convert your notes to Markdown, then back to ENML|(coming soon)|
23
+ |status|View script information and other data|`evertils status`|
@@ -19,10 +19,9 @@ require_relative "../lib/kernel.rb"
19
19
  require_relative "../lib/version.rb"
20
20
  require_relative "../lib/helpers/time.rb"
21
21
  require_relative "../lib/helpers/results.rb"
22
+ require_relative "../lib/log.rb"
22
23
  require_relative "../lib/config.rb"
23
24
  require_relative "../lib/request.rb"
24
- require_relative "../lib/log.rb"
25
- require_relative "../lib/constants.rb"
26
25
  require_relative "../lib/utils.rb"
27
26
  require_relative "../lib/logs.rb"
28
27
  require_relative "../lib/command.rb"
@@ -1,4 +1,15 @@
1
1
  module Evertils
2
+ PACKAGE_NAME = "evertils"
3
+ INSTALLED_DIR = Gem::Specification.find_by_name(Evertils::PACKAGE_NAME).gem_dir
4
+ LOG_DIR = INSTALLED_DIR + "/logs"
5
+ DEFAULT_LOG = Evertils::Log.new # no args means default log
6
+ HELPER_DIR = INSTALLED_DIR + "/lib/helpers/"
7
+ CONTROLLER_DIR = INSTALLED_DIR + "/lib/controllers/"
8
+ MODEL_DIR = INSTALLED_DIR + "/lib/models/"
9
+ TEMPLATE_DIR = INSTALLED_DIR + "/lib/configs/templates/"
10
+ LOG_DIGEST_LENGTH = 20
11
+ DEBUG = false
12
+
2
13
  class Cfg
3
14
  def bootstrap!
4
15
  begin
@@ -10,5 +21,21 @@ module Evertils
10
21
  Notify.error("#{e.to_s}\n#{e.backtrace.join("\n")}")
11
22
  end
12
23
  end
24
+
25
+ def constant?(name)
26
+ name == name.upcase
27
+ end
28
+
29
+ def options
30
+ keys = Evertils.constants.select do |name|
31
+ constant? name
32
+ end
33
+
34
+ hash = {}
35
+ keys.each do |key|
36
+ hash[key] = Evertils.const_get(key)
37
+ end
38
+ hash
39
+ end
13
40
  end
14
41
  end
@@ -7,6 +7,18 @@ module Evertils
7
7
 
8
8
  # Perform pre-run tasks
9
9
  def pre_exec
10
+ begin
11
+ # interface with the Evernote API so we can use it later
12
+ @model = Evertils::Helper.load('evernote')
13
+
14
+ # user = @model.user
15
+ # Notify.success("Welcome, #{user.name} (#{user.username})")
16
+ rescue ::Evernote::EDAM::Error::EDAMSystemException => e
17
+ Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
18
+ rescue ::Evernote::EDAM::Error::EDAMUserException => e
19
+ Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
20
+ end
21
+
10
22
  OptionParser.new do |opt|
11
23
  opt.banner = "#{Evertils::PACKAGE_NAME} controller command [...-flags]"
12
24
 
@@ -18,7 +30,7 @@ module Evertils
18
30
  opt.on("-V", "--version", "Show app version") do |v|
19
31
  # short output
20
32
  @version = Evertils::PACKAGE_VERSION
21
- end
33
+ end
22
34
  end.parse!
23
35
  end
24
36
 
@@ -75,44 +87,45 @@ module Evertils
75
87
  end
76
88
 
77
89
  private
78
- # autoload and instantiate required libraries, models and helpers
79
- def auto_load_required(modules = [])
80
- loaded = {:controller => {}, :helper => {}, :model => {}}
81
-
82
- begin
83
- modules.each do |mod|
84
- if File.exists? "#{Evertils::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
85
- require "#{Evertils::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
86
-
87
- loaded[:controller][mod] = Evertils::Controller.const_get(mod.capitalize).new
88
- else
89
- raise StandardError, "Controller not found: #{mod}"
90
- end
91
-
92
- if File.exists? "#{Evertils::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
93
- require "#{Evertils::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
94
- loaded[:helper][mod] = Evertils::Helper.const_get(mod.capitalize).new
95
-
96
- # auto-instantiate new instance of helper for the new instance of the controller
97
- loaded[:controller][mod].helper = loaded[:helper][mod]
98
- end
99
-
100
- if File.exists? "#{Evertils::INSTALLED_DIR}/lib/models/#{mod}.rb"
101
- require "#{Evertils::INSTALLED_DIR}/lib/models/#{mod}.rb"
102
- loaded[:model][mod] = Evertils::Model.const_get(mod.capitalize).new
103
-
104
- # auto-instantiate new instance of model for the new instance of the controller
105
- loaded[:controller][mod].model = loaded[:model][mod]
106
- else
107
- loaded[:controller][mod].model = Model::Base.new
108
- end
90
+
91
+ # autoload and instantiate required libraries, models and helpers
92
+ def auto_load_required(modules = [])
93
+ loaded = {:controller => {}, :helper => {}, :model => {}}
94
+
95
+ begin
96
+ modules.each do |mod|
97
+ if File.exists? "#{Evertils::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
98
+ require "#{Evertils::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
99
+
100
+ loaded[:controller][mod] = Evertils::Controller.const_get(mod.capitalize).new
101
+ else
102
+ raise StandardError, "Controller not found: #{mod}"
103
+ end
104
+
105
+ if File.exists? "#{Evertils::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
106
+ require "#{Evertils::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
107
+ loaded[:helper][mod] = Evertils::Helper.const_get(mod.capitalize).new
108
+
109
+ # auto-instantiate new instance of helper for the new instance of the controller
110
+ loaded[:controller][mod].helper = loaded[:helper][mod]
109
111
  end
110
112
 
111
- loaded
112
- rescue StandardError => e
113
- Notify.error(e.message)
113
+ if File.exists? "#{Evertils::INSTALLED_DIR}/lib/models/#{mod}.rb"
114
+ require "#{Evertils::INSTALLED_DIR}/lib/models/#{mod}.rb"
115
+ loaded[:model][mod] = Evertils::Model.const_get(mod.capitalize).new
116
+
117
+ # auto-instantiate new instance of model for the new instance of the controller
118
+ loaded[:controller][mod].model = loaded[:model][mod]
119
+ else
120
+ loaded[:controller][mod].model = Model::Base.new
121
+ end
114
122
  end
123
+
124
+ loaded
125
+ rescue StandardError => e
126
+ Notify.error(e.message)
115
127
  end
128
+ end
116
129
  end
117
130
  end
118
131
  end
@@ -4,37 +4,22 @@ module Evertils
4
4
  attr_accessor :title, :file, :notebook
5
5
 
6
6
  def pre_exec
7
- begin
8
- # interface with the Evernote API so we can use it later
9
- @model = Evertils::Helper.load('evernote')
10
-
11
- # all methods require internet to make API calls
12
- @methods_require_internet.push(:daily, :weekly, :monthly)
13
-
14
- # command flag parser
15
- OptionParser.new do |opt|
16
- opt.banner = "#{Evertils::PACKAGE_NAME} new note [...-flags]"
17
-
18
- opt.on("-m", "--to-markdown", "Convert to MD format") do |b|
19
- @markdown = b
20
- end
21
-
22
- opt.on("-e", "--to-enml", "Convert to ENML") do |b|
23
- @file = b
24
- end
25
-
26
- opt.on("-n", "--notebook=PBOOK", "Attach a file to your custom note") do |notebook|
27
- @notebook = notebook.capitalize
28
- end
29
- end.parse!
30
-
31
- # user = @model.user
32
- # Notify.success("Welcome, #{user.name} (#{user.username})")
33
- rescue ::Evernote::EDAM::Error::EDAMSystemException => e
34
- Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
35
- rescue ::Evernote::EDAM::Error::EDAMUserException => e
36
- Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
37
- end
7
+ # command flag parser
8
+ OptionParser.new do |opt|
9
+ opt.banner = "#{Evertils::PACKAGE_NAME} new note [...-flags]"
10
+
11
+ opt.on("-m", "--to-markdown", "Convert to MD format") do |b|
12
+ @markdown = b
13
+ end
14
+
15
+ opt.on("-e", "--to-enml", "Convert to ENML") do |b|
16
+ @file = b
17
+ end
18
+
19
+ opt.on("-n", "--notebook=PBOOK", "Attach a file to your custom note") do |notebook|
20
+ @notebook = notebook.capitalize
21
+ end
22
+ end.parse!
38
23
 
39
24
  super
40
25
  end
@@ -4,20 +4,7 @@ module Evertils
4
4
  attr_accessor :force, :start
5
5
 
6
6
  def pre_exec
7
- begin
8
- # interface with the Evernote API so we can use it later
9
- @model = Evertils::Helper.load('evernote')
10
-
11
- # all methods require internet to make API calls
12
- @methods_require_internet.push(:daily, :weekly, :monthly, :deployment)
13
-
14
- # user = @model.user
15
- # Notify.success("Welcome, #{user.name} (#{user.username})")
16
- rescue ::Evernote::EDAM::Error::EDAMSystemException => e
17
- Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
18
- rescue ::Evernote::EDAM::Error::EDAMUserException => e
19
- Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
20
- end
7
+ @methods_require_internet.push(:daily, :weekly, :monthly, :deployment)
21
8
 
22
9
  OptionParser.new do |opt|
23
10
  opt.banner = "#{Evertils::PACKAGE_NAME} generate timeframe [...-flags]"
@@ -4,37 +4,22 @@ module Evertils
4
4
  attr_accessor :title, :file, :notebook
5
5
 
6
6
  def pre_exec
7
- begin
8
- # interface with the Evernote API so we can use it later
9
- @model = Evertils::Helper.load('evernote')
7
+ # command flag parser
8
+ OptionParser.new do |opt|
9
+ opt.banner = "#{Evertils::PACKAGE_NAME} new note [...-flags]"
10
10
 
11
- # all methods require internet to make API calls
12
- @methods_require_internet.push(:daily, :weekly, :monthly)
13
-
14
- # command flag parser
15
- OptionParser.new do |opt|
16
- opt.banner = "#{Evertils::PACKAGE_NAME} new note [...-flags]"
17
-
18
- opt.on("-t", "--title=TITLE", "Set a custom title") do |title|
19
- @title = title
20
- end
21
-
22
- opt.on("-f", "--file=PATH", "Attach a file to your custom note") do |file|
23
- @file = file
24
- end
11
+ opt.on("-t", "--title=TITLE", "Set a custom title") do |title|
12
+ @title = title
13
+ end
25
14
 
26
- opt.on("-n", "--notebook=PBOOK", "Attach a file to your custom note") do |notebook|
27
- @notebook = notebook
28
- end
29
- end.parse!
15
+ opt.on("-f", "--file=PATH", "Attach a file to your custom note") do |file|
16
+ @file = file
17
+ end
30
18
 
31
- # user = @model.user
32
- # Notify.success("Welcome, #{user.name} (#{user.username})")
33
- rescue ::Evernote::EDAM::Error::EDAMSystemException => e
34
- Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
35
- rescue ::Evernote::EDAM::Error::EDAMUserException => e
36
- Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
37
- end
19
+ opt.on("-n", "--notebook=PBOOK", "Attach a file to your custom note") do |notebook|
20
+ @notebook = notebook
21
+ end
22
+ end.parse!
38
23
 
39
24
  super
40
25
  end
@@ -4,55 +4,43 @@ module Evertils
4
4
  attr_accessor :title, :file, :notebook
5
5
 
6
6
  def pre_exec
7
- begin
8
- # interface with the Evernote API so we can use it later
9
- @model = Evertils::Helper.load('evernote')
7
+ # all methods require internet to make API calls
8
+ @methods_require_internet.push(:daily, :weekly, :monthly)
10
9
 
11
- # all methods require internet to make API calls
12
- @methods_require_internet.push(:daily, :weekly, :monthly)
13
-
14
- @title = "Evertils - Custom Note"
15
-
16
- # command flag parser
17
- OptionParser.new do |opt|
18
- opt.banner = "#{Evertils::PACKAGE_NAME} new note [...-flags]"
19
-
20
- opt.on("-t", "--title=TITLE", "Set a custom title") do |title|
21
- @title = title
22
- end
23
-
24
- opt.on("-f", "--file=PATH", "Attach a file to your custom note") do |file|
25
- @file = file
26
- end
27
-
28
- opt.on("-n", "--notebook=PBOOK", "Choose the notebook to add your note to") do |notebook|
29
- @notebook = notebook
30
- end
31
-
32
- opt.on("-b", "--body=BODY", "Note body") do |body|
33
- @body = body
34
- end
35
-
36
- opt.on("-t", "--tags=list", "Assign tags to the new note") do |tags|
37
- @tags = tags
38
- end
39
-
40
- opt.on("-c", "--created_on=DATE", "Set note created date") do |created_on|
41
- # Evernote cuts the last 3 values off of your timestamp because
42
- # it "accurate to milliseconds", so we have to add them back or
43
- # else the date is all messed up
44
- parsed = Date.parse(created_on)
45
- @created_on = (parsed.to_time.to_i.to_s + "000").to_i
46
- end
47
- end.parse!
48
-
49
- # user = @model.user
50
- # Notify.success("Welcome, #{user.name} (#{user.username})")
51
- rescue ::Evernote::EDAM::Error::EDAMSystemException => e
52
- Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
53
- rescue ::Evernote::EDAM::Error::EDAMUserException => e
54
- Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
55
- end
10
+ @title = "Evertils - Custom Note"
11
+
12
+ # command flag parser
13
+ OptionParser.new do |opt|
14
+ opt.banner = "#{Evertils::PACKAGE_NAME} new note [...-flags]"
15
+
16
+ opt.on("-t", "--title=TITLE", "Set a custom title") do |title|
17
+ @title = title
18
+ end
19
+
20
+ opt.on("-f", "--file=PATH", "Attach a file to your custom note") do |file|
21
+ @file = file
22
+ end
23
+
24
+ opt.on("-n", "--notebook=PBOOK", "Choose the notebook to add your note to") do |notebook|
25
+ @notebook = notebook
26
+ end
27
+
28
+ opt.on("-b", "--body=BODY", "Note body") do |body|
29
+ @body = body
30
+ end
31
+
32
+ opt.on("-t", "--tags=list", "Assign tags to the new note") do |tags|
33
+ @tags = tags
34
+ end
35
+
36
+ opt.on("-c", "--created_on=DATE", "Set note created date") do |created_on|
37
+ # Evernote cuts the last 3 values off of your timestamp because
38
+ # it "accurate to milliseconds", so we have to add them back or
39
+ # else the date is all messed up
40
+ parsed = Date.parse(created_on)
41
+ @created_on = (parsed.to_time.to_i.to_s + "000").to_i
42
+ end
43
+ end.parse!
56
44
 
57
45
  super
58
46
  end
@@ -0,0 +1,13 @@
1
+ module Evertils
2
+ module Controller
3
+ class Status < Controller::Base
4
+
5
+ def default
6
+ $config.options.each_pair do |key, value|
7
+ puts "#{key}: #{value}"
8
+ end
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -1,23 +1,7 @@
1
1
  module Evertils
2
2
  class Router
3
3
  def route
4
- # Populate request params
5
- $request = Request.new
6
-
7
- # include the controller
8
- if File.exists? "#{Evertils::CONTROLLER_DIR}#{$request.controller}.rb"
9
- require "#{Evertils::CONTROLLER_DIR}#{$request.controller}.rb"
10
- end
11
-
12
- # include helpers
13
- if File.exists? "#{Evertils::HELPER_DIR}#{$request.controller}.rb"
14
- require "#{Evertils::HELPER_DIR}#{$request.controller}.rb"
15
- end
16
-
17
- # include models
18
- if File.exists? "#{Evertils::MODEL_DIR}#{$request.controller}.rb"
19
- require "#{Evertils::MODEL_DIR}#{$request.controller}.rb"
20
- end
4
+ pre_exec
21
5
 
22
6
  # Create object context and pass it the required command line arguments
23
7
  begin
@@ -59,7 +43,13 @@ module Evertils
59
43
  end
60
44
 
61
45
  # Run the controller
62
- context.exec
46
+ # Call a default action for controllers which do not require a third
47
+ # argument, i.e. evertils status
48
+ if context.respond_to? :default
49
+ context.default
50
+ else
51
+ context.exec
52
+ end
63
53
 
64
54
  # Run cleanup commands
65
55
  context.post_exec
@@ -71,5 +61,25 @@ module Evertils
71
61
  Notify.error("#{e.to_s}\n#{e.backtrace.join("\n")}")
72
62
  end
73
63
  end
64
+
65
+ def pre_exec
66
+ # Populate request params
67
+ $request = Request.new
68
+
69
+ # include the controller
70
+ if File.exists? "#{Evertils::CONTROLLER_DIR}#{$request.controller}.rb"
71
+ require "#{Evertils::CONTROLLER_DIR}#{$request.controller}.rb"
72
+ end
73
+
74
+ # include helpers
75
+ if File.exists? "#{Evertils::HELPER_DIR}#{$request.controller}.rb"
76
+ require "#{Evertils::HELPER_DIR}#{$request.controller}.rb"
77
+ end
78
+
79
+ # include models
80
+ if File.exists? "#{Evertils::MODEL_DIR}#{$request.controller}.rb"
81
+ require "#{Evertils::MODEL_DIR}#{$request.controller}.rb"
82
+ end
83
+ end
74
84
  end
75
85
  end
@@ -1,3 +1,3 @@
1
1
  module Evertils
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
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: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -28,12 +28,12 @@ files:
28
28
  - lib/configs/templates/daily.enml
29
29
  - lib/configs/templates/monthly.enml
30
30
  - lib/configs/templates/weekly.enml
31
- - lib/constants.rb
32
31
  - lib/controller.rb
33
32
  - lib/controllers/convert.rb
34
33
  - lib/controllers/generate.rb
35
34
  - lib/controllers/get.rb
36
35
  - lib/controllers/new.rb
36
+ - lib/controllers/status.rb
37
37
  - lib/helper.rb
38
38
  - lib/helpers/evernote-enml.rb
39
39
  - lib/helpers/evernote-markdown.rb
@@ -1,12 +0,0 @@
1
- module Evertils
2
- PACKAGE_NAME = "evertils"
3
- INSTALLED_DIR = Gem::Specification.find_by_name(Evertils::PACKAGE_NAME).gem_dir
4
- LOG_DIR = INSTALLED_DIR + "/logs"
5
- DEFAULT_LOG = Log.new # no args means default log
6
- HELPER_DIR = INSTALLED_DIR + "/lib/helpers/"
7
- CONTROLLER_DIR = INSTALLED_DIR + "/lib/controllers/"
8
- MODEL_DIR = INSTALLED_DIR + "/lib/models/"
9
- TEMPLATE_DIR = INSTALLED_DIR + "/lib/configs/templates/"
10
- LOG_DIGEST_LENGTH = 20
11
- DEBUG = false
12
- end