Class: FlexmlsApi::Authentication::BaseAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/flexmls_api/authentication/base_auth.rb

Overview

Authentication Base

This base class defines the basic interface supported by all client authentication implementations.

Direct Known Subclasses

ApiAuth, OAuth2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ BaseAuth

All ihheriting classes should accept the flexmls_api client as a part of initialization



10
11
12
# File 'lib/flexmls_api/authentication/base_auth.rb', line 10

def initialize(client)
  @client = client
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



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

def session
  @session
end

Instance Method Details

#authenticateObject

Perform requests to authenticate the client with the API



15
16
17
# File 'lib/flexmls_api/authentication/base_auth.rb', line 15

def authenticate
  raise "Implement me!"
end

#authenticated?Boolean

Called prior to running authenticate (except in case of api authentication errors)

Returns:

  • (Boolean)


20
21
22
# File 'lib/flexmls_api/authentication/base_auth.rb', line 20

def authenticated?
  !(session.nil? || session.expired?)
end

#build_url_parameters(parameters = {}) ⇒ Object

Format a hash as request parameters

:returns:

Stringized form of the parameters as needed for an HTTP request


38
39
40
41
42
43
44
# File 'lib/flexmls_api/authentication/base_auth.rb', line 38

def build_url_parameters(parameters={})
  array = parameters.map do |key,value|
    escaped_value = CGI.escape("#{value}")
    "#{key}=#{escaped_value}"
  end
  array.join "&"
end

#logoutObject

Terminate the active session



25
26
27
# File 'lib/flexmls_api/authentication/base_auth.rb', line 25

def logout
  raise "Implement me!"
end

#request(method, path, body, options) ⇒ Object

Perform an HTTP request (no data)



30
31
32
# File 'lib/flexmls_api/authentication/base_auth.rb', line 30

def request(method, path, body, options)
  raise "Implement me!"
end