class EvernoteUploader

Constants

EvernoteHost
EvernoteUrl
VERSION

Public Class Methods

new(filenames, options) click to toggle source
# File lib/evernote_uploader.rb, line 17
def initialize filenames, options
  @filenames = filenames
  @options   = options

  check_evernote_token

  evernote_api

  get_notebooks
  check_notebook

  @note = create_note(@options, @filenames, @notebook)
end

Public Instance Methods

check_evernote_token() click to toggle source
# File lib/evernote_uploader.rb, line 43
def check_evernote_token
  if @options[:token]
    if File.exist?(File.expand_path(@options[:token]))
      filename = File.expand_path(@options[:token])
      @token = File.open(filename) {|f| f.gets }.chomp
    else
      @token = @options[:token]
    end
  end

  raise TokenError, "Token is not specified properly" unless @token
end
check_notebook() click to toggle source
# File lib/evernote_uploader.rb, line 80
def check_notebook
  notebooks = @note_store.listNotebooks(@token)
  note_names = notebooks.map {|nb| nb.name }

  unless note_names.include?(@options[:notebook])
    puts "Note book \"#{@options[:notebook]}\" doesn't exist -- exit"
    exit
  else
    index = note_names.index(@options[:notebook])
    @notebook = notebooks[index]
  end
end
evernote_api() click to toggle source
# File lib/evernote_uploader.rb, line 56
def evernote_api
  user_store_transport = Thrift::HTTPClientTransport.new(EvernoteUrl)
  user_store_protocol  = Thrift::BinaryProtocol.new(user_store_transport)
  @user_store          =
    Evernote::EDAM::UserStore::UserStore::Client.new(user_store_protocol)

  version_ok =
    @user_store.checkVersion("Evernote EDAMTest (Ruby)",
                            Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
                            Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
  unless version_ok
    puts "Evernote API version not up-to-date"
    exit
  end
end
get_notebooks() click to toggle source
# File lib/evernote_uploader.rb, line 72
def get_notebooks
  note_store_url       = @user_store.getNoteStoreUrl(@token)
  note_store_transport = Thrift::HTTPClientTransport.new(note_store_url)
  note_store_protocol  = Thrift::BinaryProtocol.new(note_store_transport)
  @note_store          =
    Evernote::EDAM::NoteStore::NoteStore::Client.new(note_store_protocol)
end
upload() click to toggle source
# File lib/evernote_uploader.rb, line 31
def upload
  puts "uploading #{@filenames.join(", ")}"
  puts "Notebook: #{@notebook.name}"
  puts "Title: #{@note.title}"
  puts "tags #{@options[:tags]}"
  puts "..."

  @note_store.createNote(@token, @note)

  puts "done!"
end