Module: Growatt::Connection

Included in:
API
Defined in:
lib/growatt/connection.rb

Overview

Create connection and use cookies for authentication tokens

Instance Method Summary collapse

Instance Method Details

#connectionObject

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/growatt/connection.rb', line 7

def connection
  raise ConfigurationError, "Option for endpoint is not defined" unless endpoint

  options = setup_options
  @connection ||= Faraday::Connection.new(options) do |connection|
    connection.use :cookie_jar

    connection.use Faraday::Response::RaiseError
    connection.adapter Faraday.default_adapter
    setup_authorization(connection)
    setup_headers(connection)
    connection.response :json, content_type: /\bjson$/
    connection.use Faraday::Request::UrlEncoded

    setup_logger_filtering(connection, logger) if logger
  end
end