Class: Justa::Client

Inherits:
Object show all
Defined in:
lib/justa/authenticator.rb

Overview

Class to hold client authetication data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Client

Initialize Client instance

Parameters:

  • **options (Hash)

    Options required



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/justa/authenticator.rb', line 24

def initialize(**options)
  @username = options.fetch(:username, Justa.username)
  @password = options.fetch(:password, Justa.password)
  @client_id = options.fetch(:client_id, Justa.client_id)
  @client_secret = options.fetch(:client_secret, Justa.client_secret)
  @integrator_id = options.fetch(:integrator_id, Justa.integrator_id)

  @key = Justa::Util.to_sym(options.fetch(:key, options.fetch(:document, nil) || Justa.default_client_key))
  @default = options.fetch(:default, true)
  @document = options.fetch(:document, Justa.document)
  @token = options.fetch(:token)
rescue KeyError => e
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def client_secret
  @client_secret
end

#defaultObject

Returns the value of attribute default.



10
11
12
# File 'lib/justa/authenticator.rb', line 10

def default
  @default
end

#documentObject (readonly)

Returns the value of attribute document.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def document
  @document
end

#expire_atObject (readonly)

Returns the value of attribute expire_at.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def expire_at
  @expire_at
end

#integrator_idObject (readonly)

Returns the value of attribute integrator_id.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def integrator_id
  @integrator_id
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def key
  @key
end

#passwordObject (readonly)

Returns the value of attribute password.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def password
  @password
end

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def token
  @token
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/justa/authenticator.rb', line 9

def username
  @username
end

Instance Method Details

#to_hHash

Convert Client instance to hash

Returns:

  • (Hash)

    Return Client in hash form



43
44
45
46
47
48
49
50
51
52
# File 'lib/justa/authenticator.rb', line 43

def to_h
  {
    username: @username,
    password: @password,
    client_id: @client_id,
    token: @token,
    document: @document,
    key: @key
  }
end