lib/evertils/common/authentication.rb in evertils-common-0.3.1 vs lib/evertils/common/authentication.rb in evertils-common-0.3.2
- old
+ new
@@ -1,10 +1,10 @@
require 'singleton'
module Evertils
module Common
- class Authentication
+ class Authentication < Common::Generic
include Singleton
def initialize
begin
# attempt to login as the Evernote user
@@ -14,10 +14,12 @@
Notify.error("Evernote developer token is not configured properly!\n$EVERTILS_TOKEN == nil") if Evertils.token.nil?
Notify.error("Evernote API requires an update. Latest version is #{@version}") if requires_update
# prepare the main data model access point
prepare_note_store
+ rescue Evernote::EDAM::Error::EDAMUserException => e
+ handle_edam_errors(e)
rescue Evernote::EDAM::Error::EDAMSystemException => e
handle_edam_errors(e)
end
end
@@ -34,26 +36,28 @@
if args.size > 0
@noteStore.method(func.to_s).call(Evertils.token, *args)
else
@noteStore.method(func.to_s).call(Evertils.token)
end
+ rescue Evernote::EDAM::Error::EDAMUserException => e
+ handle_edam_errors(e)
rescue Evernote::EDAM::Error::EDAMSystemException => e
- Notify.warning e.inspect
- nil
+ handle_edam_errors(e)
end
end
def call_user(func, *args)
begin
if args.size > 0
@userStore.method(func.to_s).call(*args)
else
@userStore.method(func.to_s).call
end
+ rescue Evernote::EDAM::Error::EDAMUserException => e
+ handle_edam_errors(e)
rescue Evernote::EDAM::Error::EDAMSystemException => e
- Notify.warning e.inspect
- nil
+ handle_edam_errors(e)
end
end
private
@@ -62,11 +66,15 @@
userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
@userStore = ::Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
@user = call_user(:getUser, Evertils.token)
+ @major_ver = ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR
+ @minor_ver = ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR
+ @version = "#{@major_ver}.#{@minor_ver}"
+
if Evertils.is_test?
Notify.spit "TEST USER: #{info[:user]}"
end
end
@@ -77,20 +85,18 @@
noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
@noteStore = ::Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
end
def requires_update
- #entity = @userStore.checkVersion("evernote-data", ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
- entity = call_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}"
-
- !entity
+ !call_user(:checkVersion, "evernote-data", @major_ver, @minor_ver)
end
+ private
+
def handle_edam_errors(e)
Notify.warning("Problem authenticating, EDAM code #{e.errorCode}")
+ Notify.warning("Type: #{e.class}")
case e.errorCode
when 1
message = 'An unknown error occurred'
when 2
@@ -129,13 +135,12 @@
message = 'Operation denied because access to the corresponding object is prohibited in response to a take-down notice'
when 19
minutes = (e.rateLimitDuration/60).to_i
message = "You are rate limited! Wait #{minutes} minutes"
end
-
+
Notify.warning(message)
exit(0)
end
-
end
end
end
\ No newline at end of file