Class: Evertils::Common::Authentication

Inherits:
Generic
  • Object
show all
Includes:
Singleton
Defined in:
lib/evertils/common/authentication.rb

Overview

Since:

  • 0.3.0

Instance Method Summary collapse

Methods inherited from Generic

#bytesize, #deprecation_notice, #encoding, #force_encoding, #has_required_fields

Constructor Details

#initializeAuthentication

Returns a new instance of Authentication.

Since:

  • 0.3.0



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/evertils/common/authentication.rb', line 8

def initialize
  begin
    # attempt to login as the Evernote user
    prepare_user

    # quit with message if requirements not met
    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

Instance Method Details

#call(func, *args) ⇒ Object

Since:

  • 0.3.0



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/evertils/common/authentication.rb', line 38

def call(func, *args)
  begin
    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
    handle_edam_errors(e)
  end
end

#call_user(func, *args) ⇒ Object

Since:

  • 0.3.0



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/evertils/common/authentication.rb', line 52

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
    handle_edam_errors(e)
  end
end

#infoObject

Since:

  • 0.3.0



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/evertils/common/authentication.rb', line 26

def info
  {
    user: {
      name: @user.name,
      username: @user.username,
      id: @user.id
    },
    shard: @user.shardId,
    api_version: @version,
  }
end