Class: Sunscout::SolarLog::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sunscout/solar_log/client.rb

Overview

Low-level binding to the SolarLog HTTP API

Examples:

Basic usage

require 'sunscout'
c = Sunscout::SolarLog::Client.new('http://10.60.1.10')
data = c.get_data()
puts "Current power output: #{ data[:power_ac] }W"

Proxying via SSH host

require 'sunscout'
require 'net/ssh/gateway'
gateway = Net::SSH::Gateway.new('jump.example.com', 'johndoe', password: 'hidden')
c = Sunscout::SolarLog::Client.new('http://192.168.1.10', ssh_gateway: gateway)

Instance Method Summary collapse

Constructor Details

#initialize(host, opts = {}) ⇒ Client

Initialize a new instance of the class.

Parameters:

  • host (String)

    URI of the SolarLog web interface.

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

    Additional options

Options Hash (opts):

  • :ssh_gateway (Net::SSH::Gateway)

    SSH gateway through which to proxy the request.



29
30
31
32
33
# File 'lib/sunscout/solar_log/client.rb', line 29

def initialize(host, opts = {})
  @host = host

  @ssh_gateway = opts.fetch(:ssh_gateway, nil)
end

Instance Method Details

#get_dataHash<Symbol, String|Integer>

Retrieve data from the HTTP API.

Returns:

  • (Hash<Symbol, String|Integer>)

    Hash containing retrieved data



37
38
39
40
41
42
43
# File 'lib/sunscout/solar_log/client.rb', line 37

def get_data
  if @ssh_gateway
    get_data_ssh
  else
    get_data_direct
  end
end