Module: Simplewoo::Authentication

Included in:
Client
Defined in:
lib/simplewoo/authentication.rb

Instance Method Summary collapse

Instance Method Details

#api_tokenObject



16
17
18
# File 'lib/simplewoo/authentication.rb', line 16

def api_token
  self.api_token ||= authenticate if authenticated?
end

#authenticate(args = {}) ⇒ Object

Authenticates the user with their email and password returning an api token

Parameters:

  • args (Hash) (defaults to: {})

    a customizable set of options

Options Hash (args):

  • email (String)
    • the email of the user

  • password (String)
    • the password of the user



24
25
26
27
28
29
30
31
32
33
# File 'lib/simplewoo/authentication.rb', line 24

def authenticate(args = {})
  self.email ||= args.delete(:email)
  self.password ||= args.delete(:password)

  unless token_authenticated?
    self.api_token = me.access_token
  end

  self.api_token
end

#authenticated?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/simplewoo/authentication.rb', line 12

def authenticated?
  !!(basic_authenticated? || token_authenticated?)
end

#basic_authenticated?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/simplewoo/authentication.rb', line 4

def basic_authenticated?
  !!(self.email && self.password)
end

#token_authenticated?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/simplewoo/authentication.rb', line 8

def token_authenticated?
  !!(self.api_token)
end