Class: ResoWebApi::Client

Inherits:
BaseClient show all
Includes:
Resources
Defined in:
lib/reso_web_api/client.rb

Overview

Main class to run requests against a RESO Web API server.

Constant Summary

Constants included from Resources

Resources::STANDARD_RESOURCES

Constants inherited from BaseClient

BaseClient::USER_AGENT

Instance Method Summary collapse

Methods included from Resources

#resources

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
# File 'lib/reso_web_api/client.rb', line 15

def initialize(options = {})
  super(options)
  ensure_valid_auth_strategy!
end

Instance Method Details

#connection(&block) ⇒ Faraday::Connection

Return the Faraday::Connection object for this client. Yields the connection object being constructed (for customzing middleware).

Returns:

  • (Faraday::Connection)

    The connection object



29
30
31
32
33
34
# File 'lib/reso_web_api/client.rb', line 29

def connection(&block)
  super do |conn|
    conn.use Authentication::Middleware, @auth
    yield conn if block_given?
  end
end

#headersHash

Headers to be send along with requests

Returns:

  • (Hash)

    The request headers



22
23
24
# File 'lib/reso_web_api/client.rb', line 22

def headers
  super.merge({ accept: 'application/json' })
end

#serviceOData4::Service

Returns a proxied OData4::Service that attempts to ensure a properly authenticated and authorized connection

Returns:

  • (OData4::Service)

    The service instance.



39
40
41
42
# File 'lib/reso_web_api/client.rb', line 39

def service
  # puts odata, service_options
  @service ||= OData4::Service.new(connection, service_options)
end

#service_optionsHash

Returns the default options used by the by the OData service

Returns:

  • (Hash)

    The options hash



46
47
48
# File 'lib/reso_web_api/client.rb', line 46

def service_options
  @service_options ||= { logger: logger }.merge(odata || {})
end