class EnClient::SessionManager

Constants

REFRESH_LIMIT_SEC

Public Class Methods

new() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1133
def initialize
  @auth_token = nil
  @shared_id  = nil
  @note_store = nil
  @user_store = nil
  @expiration = nil
end

Public Instance Methods

auth_token() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1141
def auth_token
  raise NotAuthedException.new("Not authed") unless @auth_token
  @auth_token
end
authenticate(user, passwd) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1166
def authenticate(user, passwd)
  appname = "kawayuu"
  appid = "24b37bd1326624a0"
  @user_store = create_user_store
  auth_result = @user_store.authenticate user, passwd, appname, appid
  @auth_token, @shared_id, @expiration = get_session auth_result
  @note_store = create_note_store @shared_id
end
expiration() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1161
def expiration
  raise NotAuthedException.new("Not authed") unless @expiration
  @expiration
end
fix_note_store() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1184
def fix_note_store
  if @shared_id
    @note_store = create_note_store @shared_id
  else
    @note_store = nil
  end
end
note_store() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1151
def note_store
  raise NotAuthedException.new("Not authed") unless @note_store
  @note_store
end
refresh_authentication(current_time) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1175
def refresh_authentication(current_time)
  if current_time > @expiration - REFRESH_LIMIT_SEC * 1000
    LOG.info "refresh authentication"
    auth_result = @user_store.refreshAuthentication @auth_token
    @auth_token, dummy, @expiration = get_session auth_result
    @note_store = create_note_store @shared_id
  end
end
shared_id() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1146
def shared_id
  raise NotAuthedException.new("Not authed") unless @shared_id
  @shared_id
end
user_store() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1156
def user_store
  raise NotAuthedException.new("Not authed") unless @user_store
  @user_store
end

Private Instance Methods

create_note_store(shared_id) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1215
def create_note_store(shared_id)
  note_store_url = NOTE_STORE_URL_BASE + shared_id

  proxy_host, proxy_port = get_proxy
  if proxy_host
    note_store_transport = HTTPWithProxyClientTransport.new note_store_url, proxy_host, proxy_port
  else
    note_store_transport = HTTPWithProxyClientTransport.new note_store_url
  end

  note_store_protocol = Thrift::BinaryProtocol.new note_store_transport
  Evernote::EDAM::NoteStore::NoteStore::Client.new note_store_protocol
end
create_user_store() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1194
def create_user_store
  proxy_host, proxy_port = get_proxy

  if proxy_host
    user_store_transport = HTTPWithProxyClientTransport.new USER_STORE_URL, proxy_host, proxy_port
  else
    user_store_transport = HTTPWithProxyClientTransport.new USER_STORE_URL
  end
  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("Emacs Client",
                                       Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
                                       Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)

  unless version_ok
    raise IllegalStateException.new("UserStore version invalid")
  end
  user_store
end
get_proxy() click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1236
def get_proxy
  proxy_str = ENV["EN_PROXY"]
  if proxy_str
    proxy_str =~ /((?:\w|\.)+):([0-9]+)/
    [$1, $2]
  else
    nil
  end
end
get_session(auth_result) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1229
def get_session(auth_result)
  auth_token = auth_result.authenticationToken
  shared_id  = auth_result.user.shardId if auth_result.user
  expiration = auth_result.expiration
  [auth_token, shared_id, expiration]
end