Class: Growatt::API

Inherits:
Object
  • Object
show all
Includes:
Authentication, Connection, WrAPI::Authentication, WrAPI::Connection, WrAPI::Request
Defined in:
lib/growatt/api.rb

Overview

The ‘API` class is an internal component of the Growatt module. It is responsible for managing API configurations, connections, and authentication.

This class should not be accessed directly. Instead, use ‘Growatt.client` to interact with the API.

Direct Known Subclasses

Client

Instance Method Summary collapse

Methods included from Authentication

#login

Methods included from Connection

#connection

Constructor Details

#initialize(options = {}) ⇒ API

Initializes a new ‘Growatt::API` instance.

This method copies configuration settings from the Growatt module singleton and allows for optional overrides through the ‘options` parameter.

Examples:

Creating an API instance with custom options:

api = Growatt::API.new(user_agent: "CustomClient/1.0")

Parameters:

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

    Optional configuration overrides.



29
30
31
32
33
34
# File 'lib/growatt/api.rb', line 29

def initialize(options = {})
  options = Growatt.options.merge(options)
  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#configHash

Retrieves the current API configuration as a hash.

Examples:

Getting the current configuration:

api.config # => { endpoint: "https://server.growatt.com/", user_agent: "Ruby Growatt API client ..." }

Returns:

  • (Hash)

    A hash containing the current API configuration.



43
44
45
46
47
48
49
# File 'lib/growatt/api.rb', line 43

def config
  conf = {}
  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send key
  end
  conf
end