Sha256: 3d1f54c47def133b6c89594d30bf908e4cc90fce8db5e963b655d0f64a4cdb62

Contents?: true

Size: 1.92 KB

Versions: 29

Compression:

Stored size: 1.92 KB

Contents

module Granify
  module Controller
    class Convert < Controller::Base
      attr_accessor :title, :file, :notebook

      def pre_exec
        begin
          # interface with the Evernote API so we can use it later
          @model = Granify::Helper.load('evernote')

          # all methods require internet to make API calls
          @methods_require_internet.push(:daily, :weekly, :monthly)

          # command flag parser
          OptionParser.new do |opt|
            opt.banner = "#{Granify::PACKAGE_NAME} new note [...-flags]"

            opt.on("-m", "--to-markdown", "Convert to MD format") do |b|
              @markdown = b
            end

            opt.on("-e", "--to-enml", "Convert to ENML") do |b|
              @file = b
            end

            opt.on("-n", "--notebook=PBOOK", "Attach a file to your custom note") do |notebook|
              @notebook = notebook.capitalize
            end
          end.parse!

          # user = @model.user
          # Notify.success("Welcome, #{user.name} (#{user.username})")
        rescue ::Evernote::EDAM::Error::EDAMSystemException => e
          Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})")
        rescue ::Evernote::EDAM::Error::EDAMUserException => e
          Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})")
        end

        super
      end

      def notes_in
        unless @notebook
          Notify.error("Notebook (--notebook=) is a required argument")
        end

        metadata = @model.notes_by_notebook(@notebook)

        if metadata.is_a? Hash
          Notify.info("#{metadata.size} notes in #{@notebook}")
          Notify.info("Printing list of notes")

          metadata.each_pair do |note_guid, note_content|
            # convert it here!
            puts note_content
          end
        else
          Notify.error("Could not pull data for notebook #{@notebook}")
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
evertils-0.1.20 lib/controllers/convert.rb
evertils-0.1.19 lib/controllers/convert.rb
evertils-0.1.18 lib/controllers/convert.rb
evertils-0.1.17 lib/controllers/convert.rb
evertils-0.1.15 lib/controllers/convert.rb
evertils-0.1.14 lib/controllers/convert.rb
evertils-0.1.13 lib/controllers/convert.rb
evertils-0.1.12 lib/controllers/convert.rb
evertils-0.1.11 lib/controllers/convert.rb
evertils-0.1.9 lib/controllers/convert.rb
evertils-0.1.8 lib/controllers/convert.rb
evertils-0.1.7 lib/controllers/convert.rb
evertils-0.1.6 lib/controllers/convert.rb
evertils-0.1.5 lib/controllers/convert.rb
evertils-0.1.4 lib/controllers/convert.rb
evertils-0.1.3 lib/controllers/convert.rb
evertils-0.1.2 lib/controllers/convert.rb
evertils-0.1.1 lib/controllers/convert.rb
evertils-0.1.0 lib/controllers/convert.rb
evertils-0.0.11 lib/controllers/convert.rb