Class: Horoshop::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/horoshop.rb

Overview

Base class used to store data about authentication

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, login:, password:) ⇒ Client

Returns a new instance of Client.

Parameters:

  • url (URI)
  • login (String)
  • (String)


16
17
18
19
20
21
22
# File 'lib/horoshop.rb', line 16

def initialize(url:, login:, password:)
  @url = url
  @login = 
  @password = password
  @token = nil
  @expiration_timestamp = nil
end

Instance Attribute Details

#expiration_timestampObject

Returns the value of attribute expiration_timestamp.



11
12
13
# File 'lib/horoshop.rb', line 11

def expiration_timestamp
  @expiration_timestamp
end

#loginObject

Returns the value of attribute login.



11
12
13
# File 'lib/horoshop.rb', line 11

def 
  @login
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/horoshop.rb', line 11

def password
  @password
end

#tokenObject

Returns the value of attribute token.



11
12
13
# File 'lib/horoshop.rb', line 11

def token
  @token
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/horoshop.rb', line 11

def url
  @url
end

Instance Method Details

#refresh_token!Object



30
31
32
# File 'lib/horoshop.rb', line 30

def refresh_token!
  Horoshop::Authorization.new(self).authorize
end

#token_valid?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/horoshop.rb', line 24

def token_valid?
  return false if token.nil?

  expiration_timestamp < Time.now
end