Sha256: 07f8fdf04480ef225aa406809e42579c8f3f1c0615f4eab23e66ee43a1934d9a

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

module Evertils
  module Common
    class Authentication
      attr_accessor :store, :shardId, :version

      def initialize
        if Evertils::Common::EVERNOTE_DEVELOPER_TOKEN.nil?
          Notify.error("Evernote developer token is not configured properly!\n$EVERTILS_TOKEN == nil")
        end

        userStoreUrl = "https://#{Evertils::Common::EVERNOTE_HOST}/edam/user"

        userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
        userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
        @@user = ::Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)

        versionOK = @@user.checkVersion("evernote-data",
                   ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
                   ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)

        @version = "#{::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR}.#{::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR}"
        @shardId = user.shardId

        if !versionOK
          Notify.error("Evernote API requires an update.  Latest version is #{@version}")
        end

        noteStoreUrl = @@user.getNoteStoreUrl(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)

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

      def info
        {
          :user => "#{user.name} (#{user.username}) - ID##{user.id}",
          :shard => user.shardId,
          :api_version => @version,
        }
      end

      def user
        @@user.getUser(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
      end

      def call(func, *args)
        if args.size > 0
          @store.method(func.to_s).call(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, *args)
        else
          @store.method(func.to_s).call(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evertils-common-0.2.7 lib/evertils/common/authentication.rb