Sha256: cb9fb71069bb22f083da53495cff468b7dd47f4703810bbf52ca62eb1db7b800

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require "evernote_utils/version"

require 'evernote-thrift'
require "evernote_utils/note"
require "evernote_utils/notebook"
require "evernote_utils/tag"

module ENUtils
  class InvalidVersion < StandardError; end

  class Core
    attr_accessor :token, :notestore

    def initialize(token, production=true)

      userStoreUrl = "https://#{production ? 'www' : 'sandbox'}.evernote.com/edam/user"
      userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
      userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
      userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)

      versionOK = userStore.checkVersion("Evernote EDAMTest (Ruby)",
                                         Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
                                         Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
      raise InvalidVersion unless versionOK

      noteStoreUrl = userStore.getNoteStoreUrl(token)

      noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
      noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
      @notestore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)

      @token = token
    end

    def notes(options={})
      Note.where(self, options)
    end

    def notebooks(options={})
      Notebook.where(self, options)
    end

    def tags(options={})
      Tag.where(self, options)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evernote_utils-0.0.3 lib/evernote_utils.rb
evernote_utils-0.0.2 lib/evernote_utils.rb
evernote_utils-0.0.1 lib/evernote_utils.rb