Class: Senec::Cloud::Connection
- Inherits:
-
Object
- Object
- Senec::Cloud::Connection
- Defined in:
- lib/senec/cloud/connection.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#totp_uri ⇒ Object
readonly
Returns the value of attribute totp_uri.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #dashboard(system_id) ⇒ Object
-
#initialize(username:, password:, user_agent: DEFAULT_USER_AGENT, totp_uri: nil) ⇒ Connection
constructor
A new instance of Connection.
- #system_details(system_id) ⇒ Object
- #systems ⇒ Object
- #wallbox(system_id, wallbox_id) ⇒ Object
- #wallbox_search(system_id) ⇒ Object
Constructor Details
#initialize(username:, password:, user_agent: DEFAULT_USER_AGENT, totp_uri: nil) ⇒ Connection
Returns a new instance of Connection.
20 21 22 23 24 25 |
# File 'lib/senec/cloud/connection.rb', line 20 def initialize(username:, password:, user_agent: DEFAULT_USER_AGENT, totp_uri: nil) @username = username @password = password @user_agent = user_agent @totp_uri = totp_uri end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
27 28 29 |
# File 'lib/senec/cloud/connection.rb', line 27 def password @password end |
#totp_uri ⇒ Object (readonly)
Returns the value of attribute totp_uri.
27 28 29 |
# File 'lib/senec/cloud/connection.rb', line 27 def totp_uri @totp_uri end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
27 28 29 |
# File 'lib/senec/cloud/connection.rb', line 27 def user_agent @user_agent end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
27 28 29 |
# File 'lib/senec/cloud/connection.rb', line 27 def username @username end |
Instance Method Details
#authenticate! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/senec/cloud/connection.rb', line 29 def authenticate! code_verifier = SecureRandom.alphanumeric(43) digest = Digest::SHA256.digest(code_verifier) code_challenge = Base64.urlsafe_encode64(digest).delete('=') auth_url = oauth_client.auth_code.( redirect_uri: REDIRECT_URI, scope: SCOPE, code_challenge:, code_challenge_method: 'S256', ) # Manual HTTP needed for Keycloak cross-domain form handling form_type, form_url = fetch_login_form(auth_url) redirect_url = submit_credentials(form_type, form_url) = (redirect_url) self.oauth_token = oauth_client.auth_code.get_token( , redirect_uri: REDIRECT_URI, code_verifier:, ) end |
#authenticated? ⇒ Boolean
55 56 57 |
# File 'lib/senec/cloud/connection.rb', line 55 def authenticated? !!oauth_token end |
#dashboard(system_id) ⇒ Object
67 68 69 |
# File 'lib/senec/cloud/connection.rb', line 67 def dashboard(system_id) get "#{MEASUREMENTS_HOST}/v1/systems/#{system_id}/dashboard" end |
#system_details(system_id) ⇒ Object
63 64 65 |
# File 'lib/senec/cloud/connection.rb', line 63 def system_details(system_id) get "#{SYSTEMS_HOST}/systems/#{system_id}/details" end |
#systems ⇒ Object
59 60 61 |
# File 'lib/senec/cloud/connection.rb', line 59 def systems get "#{SYSTEMS_HOST}/v1/systems" end |
#wallbox(system_id, wallbox_id) ⇒ Object
71 72 73 |
# File 'lib/senec/cloud/connection.rb', line 71 def wallbox(system_id, wallbox_id) get "#{WALLBOX_HOST}/v1/systems/#{system_id}/wallboxes/#{wallbox_id}" end |
#wallbox_search(system_id) ⇒ Object
75 76 77 |
# File 'lib/senec/cloud/connection.rb', line 75 def wallbox_search(system_id) post "#{WALLBOX_HOST}/v1/systems/wallboxes/search", { systemIds: [system_id] } end |