Module: Growatt::Authentication

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

Overview

Deals with authentication flow and stores it within global configuration

Instance Method Summary collapse

Instance Method Details

#loginObject

Authorize to the Growatt portal

Raises:



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

def ()
  raise ConfigurationError, "Username/password not set" unless username || password
  _password = hash_password(self.password) #unless is_password_hashed

  _format = self.format
  self.format = 'x-www-form-urlencoded'
  response = post('newTwoLoginAPI.do', {'userName': self.username, 'password': _password})
  self.format = _format
  data = response.body['back']
  if data && data['success']
    @login_data = data
    data
  else
    raise AuthenticationError.new(data['error'])
  end
end