class SyncSign::Hub

Object that represents a SyncSign hub.

Attributes

addr[R]

@return [String] the IP address or hostname of the hub.

apikey[R]

@return [String] the API key of the hub.

name[R]

@return [String] the friendly name of the hub.

sn[R]

@return [String] the serial number of the hub.

Public Class Methods

new(service: nil, sn: nil, name: nil) click to toggle source

Initialize a new hub object (normally only called from Service#hubs)

# File lib/syncsign/hub.rb, line 16
def initialize(service: nil, sn: nil, name: nil)
  @sn = sn
  @name = name
  @service = service
  load_hub_info
end

Public Instance Methods

direct_rendering_capable?() click to toggle source
# File lib/syncsign/hub.rb, line 30
def direct_rendering_capable?
  return @addr && @apikey
end
nodes() click to toggle source

Retrieve a collection of all Node objects serviced by this hub.

# File lib/syncsign/hub.rb, line 25
def nodes
  SyncSign::Node::parse_collection(service: @service, nodeinfo: @service.api_call(path: "/devices/#{@sn}/nodes"))
end

Private Instance Methods

load_hub_info() click to toggle source

Load info about a hub from the config file (IP address and API key)

# File lib/syncsign/hub.rb, line 38
def load_hub_info
  cfg_locations = [
    "./signhubs.cfg",
    "#{File::dirname($0)}/signhubs.cfg",
    "/etc/signhubs.cfg"
  ]
  cfgfile = cfg_locations.find { |file| File.exist?(file) }
  return unless cfgfile

  File.open(cfgfile) do |f|
    f.each_line do |line|
      next if line[0] == "#"

      hubinfo = line.split(/\s+/)
      if(@sn == hubinfo[0]) then
        @addr = hubinfo[1]
        @apikey = hubinfo[2]
        return true
      end
    end
  end
end