evertils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/command.rb +179 -0
- data/lib/config.rb +14 -0
- data/lib/configs/templates/daily-friday.enml +14 -0
- data/lib/configs/templates/daily.enml +9 -0
- data/lib/configs/templates/monthly.enml +21 -0
- data/lib/configs/templates/quarterly.enml +0 -0
- data/lib/configs/templates/weekly.enml +18 -0
- data/lib/constants.rb +12 -0
- data/lib/controller.rb +113 -0
- data/lib/controllers/convert.rb +63 -0
- data/lib/controllers/generate.rb +51 -0
- data/lib/controllers/get.rb +70 -0
- data/lib/controllers/new.rb +88 -0
- data/lib/helper.rb +19 -0
- data/lib/helpers/evernote-enml.rb +33 -0
- data/lib/helpers/evernote-markdown.rb +210 -0
- data/lib/helpers/evernote.rb +260 -0
- data/lib/helpers/generate.rb +39 -0
- data/lib/helpers/time.rb +28 -0
- data/lib/log.rb +111 -0
- data/lib/logs.rb +34 -0
- data/lib/model.rb +26 -0
- data/lib/model_data.rb +97 -0
- data/lib/request.rb +20 -0
- data/lib/router.rb +73 -0
- data/lib/utils.rb +123 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 136d79a7dda1df2c273df2fb0e228da3e71f3a29
|
4
|
+
data.tar.gz: c83fea36ee66af27bd096e6c42431c1a45d15137
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88a6de1348dbeb8b6c44acf49a8b9a6ea1e0c3a349d47a962760b9254b533eb26aaa6e41759b7412ff411522064a272770f3073ccb8657932188039803ffaf2a
|
7
|
+
data.tar.gz: a4cfaaae6c4f1a0d8f6f146c497262270e5047dadcd290e348d73a5804a4dd048e849a90c6281cbb65d38861de401d4a9b4e0459c2988d0032e3893a40fc6b23
|
data/lib/command.rb
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
module Granify
|
2
|
+
module Command
|
3
|
+
class Exec
|
4
|
+
attr_reader :response, :exitcode
|
5
|
+
attr_accessor :enable_logging
|
6
|
+
|
7
|
+
#
|
8
|
+
# class methods
|
9
|
+
#
|
10
|
+
class << self
|
11
|
+
def git_queue_status
|
12
|
+
if global("git log origin/#{git_current_branch}..HEAD --oneline")
|
13
|
+
response = @response.split("\n")
|
14
|
+
response.size > 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def git_push
|
19
|
+
global("git push -q origin #{git_current_branch}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def git_checkout
|
23
|
+
begin
|
24
|
+
curr_branch = git_current_branch
|
25
|
+
branch = $request.custom.nil? ? curr_branch : $request.custom[0]
|
26
|
+
|
27
|
+
if !git_branch_verify branch
|
28
|
+
raise "Requested branch not found in the working copy: #{branch}"
|
29
|
+
end
|
30
|
+
|
31
|
+
if branch == curr_branch
|
32
|
+
return Notify.warning("Requested branch is already checked out, skipping checkout")
|
33
|
+
else
|
34
|
+
global("git checkout -q #{branch}")
|
35
|
+
end
|
36
|
+
|
37
|
+
# not found locally, checkout from origin
|
38
|
+
if !@response
|
39
|
+
branch = "origin/#{branch}"
|
40
|
+
global("git checkout -q #{branch}")
|
41
|
+
end
|
42
|
+
|
43
|
+
if !@response
|
44
|
+
Notify.error("Unable to locate #{branch} on the remote server or local working copy")
|
45
|
+
end
|
46
|
+
|
47
|
+
branch
|
48
|
+
rescue SystemExit, Interrupt
|
49
|
+
Notify.error("Interrupt caught, exiting")
|
50
|
+
rescue RuntimeError => e
|
51
|
+
Notify.error(e.message)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def git_current_branch
|
56
|
+
global("git rev-parse --abbrev-ref HEAD")
|
57
|
+
end
|
58
|
+
|
59
|
+
def git_branch_verify(branch = nil)
|
60
|
+
if branch.nil?
|
61
|
+
branch = git_current_branch
|
62
|
+
end
|
63
|
+
|
64
|
+
global("git rev-parse --verify #{branch}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def global(command, file = nil)
|
68
|
+
begin
|
69
|
+
# disable logging if user settings prohibit it
|
70
|
+
#file = nil if !@enable_logging
|
71
|
+
# default value for exit code is an error
|
72
|
+
@exitcode = 1
|
73
|
+
|
74
|
+
@response = `#{command}`.chomp
|
75
|
+
@exitcode = $?.exitstatus
|
76
|
+
|
77
|
+
# Log output to a file
|
78
|
+
# This method is better than redirecting output to a file because now
|
79
|
+
# the response is always populated instead of being empty when output
|
80
|
+
# is sent to the log file
|
81
|
+
if file
|
82
|
+
File.open(file.path, 'w+') do |f|
|
83
|
+
f.write(@response)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
@response
|
88
|
+
rescue SystemExit, Interrupt
|
89
|
+
Notify.error("Interrupt caught, exiting")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# instance methods
|
96
|
+
#
|
97
|
+
def minify(file, destination)
|
98
|
+
begin
|
99
|
+
min_file = "#{destination}#{File.basename(file, File.extname(file))}.min.js"
|
100
|
+
|
101
|
+
@response = `uglifyjs #{file} -cm -o "#{min_file}"`
|
102
|
+
|
103
|
+
Notify.success("Minified #{file}")
|
104
|
+
|
105
|
+
$?.exitstatus == 0
|
106
|
+
rescue SystemExit, Interrupt
|
107
|
+
Notify.error("Interrupt caught, exiting")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def lint(file, log_file)
|
112
|
+
begin
|
113
|
+
command = `coffeelint -f "#{Granify::INSTALLED_DIR}/lib/configs/coffeelint.json" #{file}`
|
114
|
+
|
115
|
+
@response = command.include?("Ok!")
|
116
|
+
|
117
|
+
# only send errors to the log file
|
118
|
+
if !@response
|
119
|
+
File.open(log_file.path, 'a') do |f|
|
120
|
+
f.write("Logged at #{Time.now}\n============================================================\n\n")
|
121
|
+
f.write(command)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
$?.exitstatus == 0
|
126
|
+
rescue SystemExit, Interrupt
|
127
|
+
Notify.error("Interrupt caught, exiting")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def open_editor(file=nil)
|
132
|
+
begin
|
133
|
+
log_file = file || Granify::DEFAULT_LOG
|
134
|
+
|
135
|
+
# System editor is not set/unavailable, use system default to open the
|
136
|
+
# file
|
137
|
+
if `echo $EDITOR` == ""
|
138
|
+
if Utils.os == :macosx
|
139
|
+
`open #{log_file.path}`
|
140
|
+
else
|
141
|
+
`xdg-open #{log_file.path}`
|
142
|
+
end
|
143
|
+
else
|
144
|
+
`$EDITOR #{log_file.path}`
|
145
|
+
end
|
146
|
+
rescue SystemExit, Interrupt
|
147
|
+
Notify.error("Interrupt caught, exiting")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def arbitrary(command, file = nil)
|
152
|
+
begin
|
153
|
+
# default value for exit code is an error
|
154
|
+
@exitcode = 1
|
155
|
+
@response = `#{command}`.chomp
|
156
|
+
@exitcode = $?.exitstatus
|
157
|
+
|
158
|
+
# Log output to a file
|
159
|
+
# This method is better than redirecting output to a file because now
|
160
|
+
# the response is always populated instead of being empty when output
|
161
|
+
# is sent to the log file
|
162
|
+
if file
|
163
|
+
File.open(file.path, 'w+') do |f|
|
164
|
+
f.write("Logged at #{Time.now}\n============================================================\n\n")
|
165
|
+
f.write(@response)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
@exitcode == 0
|
170
|
+
|
171
|
+
# support chaining
|
172
|
+
self
|
173
|
+
rescue SystemExit, Interrupt
|
174
|
+
Notify.error("Interrupt caught, exiting")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<div><span style="font-size: 18px;">Logs</span></div>
|
2
|
+
<ul>
|
3
|
+
<li>...</li>
|
4
|
+
</ul>
|
5
|
+
<br />
|
6
|
+
<div><span style="font-size: 18px;">Tasks completed</span></div>
|
7
|
+
<ul>
|
8
|
+
<li>...</li>
|
9
|
+
</ul>
|
10
|
+
<br />
|
11
|
+
<div><span style="font-size: 18px;">EOD</span></div>
|
12
|
+
<div><en-todo checked="false"/><a href="https://granify2000.harvestapp.com/">Harvest</a></div>
|
13
|
+
<div><en-todo checked="false"/><a href="https://docs.google.com/a/granify.com/spreadsheets/d/1tYFS_Yy-6bMQyn5VPBfg2yXRRA3kYrRcwq1hS1jfG2w/edit#gid=0">Fill out expense report</a></div>
|
14
|
+
<div><en-todo checked="false"/>Update meeting notes</div>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<ul>
|
2
|
+
<li>...</li>
|
3
|
+
</ul>
|
4
|
+
<div>
|
5
|
+
<div><br/></div>
|
6
|
+
<div><span style="font-size: 18px;">Highlights</span></div>
|
7
|
+
<div>
|
8
|
+
<ul>
|
9
|
+
<li>...</li>
|
10
|
+
</ul>
|
11
|
+
<div>
|
12
|
+
<div><br/></div>
|
13
|
+
<div><span style="font-size: 18px;">Weekly Goals</span></div>
|
14
|
+
</div>
|
15
|
+
<ul>
|
16
|
+
<li><en-todo/>...</li>
|
17
|
+
</ul>
|
18
|
+
<br />
|
19
|
+
<div><span style="font-size: 18px;">Quarterly Goals</span></div>
|
20
|
+
</div>
|
21
|
+
</div>
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<div>
|
2
|
+
<div><span style="font-size: 18px;">Logs</span></div>
|
3
|
+
<ul>
|
4
|
+
<li>...</li>
|
5
|
+
</ul>
|
6
|
+
</div>
|
7
|
+
<div>
|
8
|
+
<div><br/></div>
|
9
|
+
<div><span style="font-size: 18px;">Highlights</span></div>
|
10
|
+
<ul>
|
11
|
+
<li>...</li>
|
12
|
+
</ul>
|
13
|
+
<div><br/></div>
|
14
|
+
<div><span style="font-size: 18px;">Goals</span></div>
|
15
|
+
</div>
|
16
|
+
<ul>
|
17
|
+
<li>...</li>
|
18
|
+
</ul>
|
data/lib/constants.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Granify
|
2
|
+
PACKAGE_NAME = "evertils"
|
3
|
+
INSTALLED_DIR = File.dirname($0)
|
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
|
data/lib/controller.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Base
|
4
|
+
attr_accessor :model, :helper, :methods_require_internet, :default_method
|
5
|
+
|
6
|
+
@@options = Hash.new
|
7
|
+
|
8
|
+
# Perform pre-run tasks
|
9
|
+
def pre_exec
|
10
|
+
OptionParser.new do |opt|
|
11
|
+
opt.banner = "#{Granify::PACKAGE_NAME} controller command [...-flags]"
|
12
|
+
|
13
|
+
opt.on("-v", "--verbose", "Verbose output") do |v|
|
14
|
+
# short output
|
15
|
+
@@options[:verbose] = v
|
16
|
+
end
|
17
|
+
end.parse!
|
18
|
+
end
|
19
|
+
|
20
|
+
# Handle the request
|
21
|
+
def exec(args = [])
|
22
|
+
self.send(@default_method.to_sym)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Perform post-run cleanup tasks, such as deleting old logs
|
26
|
+
def post_exec(total_errors = 0, total_warnings = 0, total_files = 0)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# Determines if the command can execute
|
31
|
+
def can_exec?(command = nil, name = nil)
|
32
|
+
@model = Granify::Model.const_get(command.capitalize).new rescue nil
|
33
|
+
@helper = Granify::Helper.const_get(command.capitalize).new rescue nil
|
34
|
+
@methods_require_internet = []
|
35
|
+
|
36
|
+
# get user-defined methods to use as a fallback
|
37
|
+
user_defined_methods = []
|
38
|
+
|
39
|
+
# timeout is the first system defined method after the user defined
|
40
|
+
# ones
|
41
|
+
for i in 0..public_methods.index(:to_json) -1
|
42
|
+
user_defined_methods.push(public_methods[i].to_sym)
|
43
|
+
end
|
44
|
+
|
45
|
+
@default_method = name || user_defined_methods.first || :sample
|
46
|
+
|
47
|
+
if !respond_to? default_method.to_sym, true
|
48
|
+
Notify.error("Command not found: #{name}")
|
49
|
+
end
|
50
|
+
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
# default method called by exec if no argument is passed
|
55
|
+
def sample
|
56
|
+
Notify.warning("Method not implemented");
|
57
|
+
end
|
58
|
+
|
59
|
+
def required_modules(*modules)
|
60
|
+
auto_load_required(modules).each do |type, hash|
|
61
|
+
# Make each auto-loaded module available as an instance variable
|
62
|
+
# i.e. [:hound]: @hound_controller, @hound_model, @hound_helper
|
63
|
+
# i.e. [:test]: @test_controller, @test_model, @test_helper
|
64
|
+
# Only files that exist and can be called are loaded
|
65
|
+
hash.each do |key, value|
|
66
|
+
instance_variable_set("@#{key}_#{type}".to_sym, value)
|
67
|
+
@last_model = instance_variable_get("@#{key}_model")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
# autoload and instantiate required libraries, models and helpers
|
74
|
+
def auto_load_required(modules = [])
|
75
|
+
loaded = {:controller => {}, :helper => {}, :model => {}}
|
76
|
+
|
77
|
+
begin
|
78
|
+
modules.each do |mod|
|
79
|
+
if File.exists? "#{Granify::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
|
80
|
+
require "#{Granify::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
|
81
|
+
|
82
|
+
loaded[:controller][mod] = Granify::Controller.const_get(mod.capitalize).new
|
83
|
+
else
|
84
|
+
raise StandardError, "Controller not found: #{mod}"
|
85
|
+
end
|
86
|
+
|
87
|
+
if File.exists? "#{Granify::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
|
88
|
+
require "#{Granify::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
|
89
|
+
loaded[:helper][mod] = Granify::Helper.const_get(mod.capitalize).new
|
90
|
+
|
91
|
+
# auto-instantiate new instance of helper for the new instance of the controller
|
92
|
+
loaded[:controller][mod].helper = loaded[:helper][mod]
|
93
|
+
end
|
94
|
+
|
95
|
+
if File.exists? "#{Granify::INSTALLED_DIR}/lib/models/#{mod}.rb"
|
96
|
+
require "#{Granify::INSTALLED_DIR}/lib/models/#{mod}.rb"
|
97
|
+
loaded[:model][mod] = Granify::Model.const_get(mod.capitalize).new
|
98
|
+
|
99
|
+
# auto-instantiate new instance of model for the new instance of the controller
|
100
|
+
loaded[:controller][mod].model = loaded[:model][mod]
|
101
|
+
else
|
102
|
+
loaded[:controller][mod].model = Model::Base.new
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
loaded
|
107
|
+
rescue StandardError => e
|
108
|
+
Notify.error(e.message)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Convert < Controller::Base
|
4
|
+
attr_accessor :title, :file, :notebook
|
5
|
+
|
6
|
+
def pre_exec
|
7
|
+
begin
|
8
|
+
# interface with the Evernote API so we can use it later
|
9
|
+
@model = Granify::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 = "#{Granify::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
|
38
|
+
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def notes_in
|
43
|
+
unless @notebook
|
44
|
+
Notify.error("Notebook (--notebook=) is a required argument")
|
45
|
+
end
|
46
|
+
|
47
|
+
metadata = @model.notes_by_notebook(@notebook)
|
48
|
+
|
49
|
+
if metadata.is_a? Hash
|
50
|
+
Notify.info("#{metadata.size} notes in #{@notebook}")
|
51
|
+
Notify.info("Printing list of notes")
|
52
|
+
|
53
|
+
metadata.each_pair do |note_guid, note_content|
|
54
|
+
# convert it here!
|
55
|
+
puts note_content
|
56
|
+
end
|
57
|
+
else
|
58
|
+
Notify.error("Could not pull data for notebook #{@notebook}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Generate < Controller::Base
|
4
|
+
def pre_exec
|
5
|
+
begin
|
6
|
+
# interface with the Evernote API so we can use it later
|
7
|
+
@model = Granify::Helper.load('evernote')
|
8
|
+
|
9
|
+
# all methods require internet to make API calls
|
10
|
+
@methods_require_internet.push(:daily, :weekly, :monthly)
|
11
|
+
|
12
|
+
# user = @model.user
|
13
|
+
# Notify.success("Welcome, #{user.name} (#{user.username})")
|
14
|
+
rescue ::Evernote::EDAM::Error::EDAMSystemException => e
|
15
|
+
Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
|
16
|
+
rescue ::Evernote::EDAM::Error::EDAMUserException => e
|
17
|
+
Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
|
18
|
+
end
|
19
|
+
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
# generate daily notes
|
24
|
+
def daily
|
25
|
+
if @model.note_exists
|
26
|
+
Notify.error("There's already a log for today!")
|
27
|
+
end
|
28
|
+
|
29
|
+
@model.create_note
|
30
|
+
end
|
31
|
+
|
32
|
+
# generate weekly notes
|
33
|
+
def weekly
|
34
|
+
if @model.note_exists
|
35
|
+
Notify.error("There's already a log for this week!")
|
36
|
+
end
|
37
|
+
|
38
|
+
@model.create_note
|
39
|
+
end
|
40
|
+
|
41
|
+
# generate monthly notes
|
42
|
+
def monthly
|
43
|
+
if @model.note_exists
|
44
|
+
Notify.error("There's already a log for this month!")
|
45
|
+
end
|
46
|
+
|
47
|
+
@model.create_note
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Get < Controller::Base
|
4
|
+
attr_accessor :title, :file, :notebook
|
5
|
+
|
6
|
+
def pre_exec
|
7
|
+
begin
|
8
|
+
# interface with the Evernote API so we can use it later
|
9
|
+
@model = Granify::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 = "#{Granify::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
|
25
|
+
|
26
|
+
opt.on("-n", "--notebook=PBOOK", "Attach a file to your custom note") do |notebook|
|
27
|
+
@notebook = notebook
|
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
|
38
|
+
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get data about a notebook, prints titles of each child note
|
43
|
+
def notebook
|
44
|
+
if !$request.custom.nil?
|
45
|
+
book = $request.custom[0]
|
46
|
+
metadata = @model.notes_by_notebook(book)
|
47
|
+
|
48
|
+
if metadata.is_a? ::Evernote::EDAM::NoteStore::NotesMetadataList
|
49
|
+
Notify.info("#{metadata.totalNotes} notes in #{book}")
|
50
|
+
Notify.info("Printing list of notes")
|
51
|
+
|
52
|
+
metadata.notes.each do |note|
|
53
|
+
puts note.title
|
54
|
+
end
|
55
|
+
else
|
56
|
+
Notify.error("Could not pull data for notebook #{$request.custom[0]}")
|
57
|
+
end
|
58
|
+
else
|
59
|
+
Notify.error("Notebook name is a required argument, i.e.\n#{Granify::PACKAGE_NAME} get notebook agendas")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def info
|
64
|
+
@model.info.each_pair do |key, value|
|
65
|
+
Notify.spit("#{key}: #{value}")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class New < Controller::Base
|
4
|
+
attr_accessor :title, :file, :notebook
|
5
|
+
|
6
|
+
def pre_exec
|
7
|
+
begin
|
8
|
+
# interface with the Evernote API so we can use it later
|
9
|
+
@model = Granify::Helper.load('evernote')
|
10
|
+
|
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 = "#{Granify::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", "Attach a file to your custom note") do |notebook|
|
29
|
+
@notebook = notebook
|
30
|
+
end
|
31
|
+
|
32
|
+
opt.on("-b", "--body=BODY", "Note body") do |body|
|
33
|
+
@body = body
|
34
|
+
end
|
35
|
+
end.parse!
|
36
|
+
|
37
|
+
# user = @model.user
|
38
|
+
# Notify.success("Welcome, #{user.name} (#{user.username})")
|
39
|
+
rescue ::Evernote::EDAM::Error::EDAMSystemException => e
|
40
|
+
Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
|
41
|
+
rescue ::Evernote::EDAM::Error::EDAMUserException => e
|
42
|
+
Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
|
43
|
+
end
|
44
|
+
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create a new Evernote note from data or terminal output
|
49
|
+
def note
|
50
|
+
if @body.nil?
|
51
|
+
message = JSON.parse(STDIN.gets).join
|
52
|
+
message = message.gsub!("\n", '<br />')
|
53
|
+
else
|
54
|
+
message = @body
|
55
|
+
end
|
56
|
+
|
57
|
+
note = @model.create_note(@title, message, @notebook, @file)
|
58
|
+
|
59
|
+
if note[:note]
|
60
|
+
Notify.success("Note created")
|
61
|
+
else
|
62
|
+
Notify.error("Unable to create note, are you authenticated?")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Create a new note and automatically share it
|
67
|
+
def share_note
|
68
|
+
if @body.nil?
|
69
|
+
message = JSON.parse(STDIN.gets).join
|
70
|
+
message = message.gsub!("\n", '<br />')
|
71
|
+
else
|
72
|
+
message = @body
|
73
|
+
end
|
74
|
+
|
75
|
+
# Prefix title to indicate it's shared status
|
76
|
+
@title = "[SHARED] #{@title}"
|
77
|
+
|
78
|
+
note = @model.create_note(@title, message, @notebook, @file, true)
|
79
|
+
|
80
|
+
if note[:share_url]
|
81
|
+
Notify.success("Note created and shared:\n#{note[:share_url]}")
|
82
|
+
else
|
83
|
+
Notify.error("Something dreadful happened!")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Granify
|
2
|
+
module Helper
|
3
|
+
def self.load(klass, args = nil)
|
4
|
+
begin
|
5
|
+
klass_instance = Granify::Helper.const_get(klass.capitalize)
|
6
|
+
|
7
|
+
if klass_instance
|
8
|
+
if args.nil?
|
9
|
+
klass_instance.new
|
10
|
+
else
|
11
|
+
klass_instance.new(args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
rescue => e
|
15
|
+
Notify.error(e.message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|