Class: Evertils::Controller::New
- Defined in:
- lib/evertils/controllers/new.rb
Constant Summary
Constants inherited from Base
Base::OK, Base::QUIT, Base::QUIT_SOFT
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#notebook ⇒ Object
Returns the value of attribute notebook.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Base
Instance Method Summary collapse
-
#note ⇒ Object
Create a new Evernote note from data or terminal output.
- #pre_exec ⇒ Object
-
#share_note ⇒ Object
Create a new note and automatically share it.
Methods inherited from Base
#can_exec?, #exec, #initialize, #post_exec, #sample
Constructor Details
This class inherits a constructor from Evertils::Controller::Base
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/evertils/controllers/new.rb', line 4 def file @file end |
#notebook ⇒ Object
Returns the value of attribute notebook.
4 5 6 |
# File 'lib/evertils/controllers/new.rb', line 4 def notebook @notebook end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/evertils/controllers/new.rb', line 4 def title @title end |
Instance Method Details
#note ⇒ Object
Create a new Evernote note from data or terminal output
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/evertils/controllers/new.rb', line 49 def note if @body.nil? = JSON.parse(STDIN.gets.to_s).join = .gsub!("\n", '<br />') else = @body end note = @model.create_note(title: @title, body: , parent_notebook: @notebook, files: @file, shareable: false, created_on: @created_on) if note[:note] Notify.success("Note created") else Notify.error("Unable to create note, are you authenticated?") end end |
#pre_exec ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/evertils/controllers/new.rb', line 6 def pre_exec # all methods require internet to make API calls @methods_require_internet.push(:daily, :weekly, :monthly) @title = "Evertils - Custom Note" # command flag parser OptionParser.new do |opt| opt. = "#{Evertils::PACKAGE_NAME} new note [...-flags]" opt.on("-t", "--title=TITLE", "Set a custom title") do |title| @title = title end opt.on("-f", "--file=PATH", "Attach a file to your custom note") do |file| @file = file end opt.on("-n", "--notebook=PBOOK", "Choose the notebook to add your note to") do |notebook| @notebook = notebook end opt.on("-b", "--body=BODY", "Note body") do |body| @body = body end opt.on("-t", "--tags=list", "Assign tags to the new note") do || @tags = end opt.on("-c", "--created_on=DATE", "Set note created date") do |created_on| # Evernote cuts the last 3 values off of your timestamp because # it "accurate to milliseconds", so we have to add them back or # else the date is all messed up parsed = Date.parse(created_on) @created_on = (parsed.to_time.to_i.to_s + "000").to_i end end.parse! super end |
#share_note ⇒ Object
Create a new note and automatically share it
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/evertils/controllers/new.rb', line 67 def share_note if @body.nil? = JSON.parse(STDIN.gets).join = .gsub!("\n", '<br />') else = @body end # Prefix title to indicate it's shared status @title = "[SHARED] #{@title}" note = @model.create_note(title: @title, body: , parent_notebook: @notebook, files: @file, shareable: true, created_on: @created_on) if note[:share_url] Notify.success("Note created and shared:\n#{note[:share_url]}") else Notify.error("Something dreadful happened!") end end |