class YuiRestClient::App

Attributes

host[R]
port[R]

Public Class Methods

new(host:, port:) click to toggle source

Used to initialize main entry point of YuiRestClient and set host and port for the application under control. @param host [String] host address (e.g. 'localhost', '192.168.0.1') @param port [String] port opened for communication (e.g. '9999')

# File lib/yui_rest_client/app.rb, line 11
def initialize(host:, port:)
  @host = host
  @port = port
  @widget_controller = Http::WidgetController.new(host: host, port: port)
  @version_controller = Http::VersionController.new(host: host, port: port)
end

Public Instance Methods

bargraph(filter) click to toggle source

Initializes new instance of Bargraph with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Bargraph] new instance of Table @example

app.bargraph(id: 'id', label: 'label', class: 'YBarGraph')
# File lib/yui_rest_client/app.rb, line 34
def bargraph(filter)
  Widgets::Bargraph.new(@widget_controller, FilterExtractor.new(filter))
end
button(filter) click to toggle source

Initializes new instance of Button with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Button] new instance of Button @example

app.button(id: 'id', label: 'label', class: 'YPushButton')
# File lib/yui_rest_client/app.rb, line 44
def button(filter)
  Widgets::Button.new(@widget_controller, FilterExtractor.new(filter))
end
check_api_version() click to toggle source

Validates if server side REST API is compatible with client inside @return true if version is compatible, false if not or any error while

receiving version from the server
# File lib/yui_rest_client/app.rb, line 233
def check_api_version
  YuiRestClient.logger.info("Client API version: #{API_VERSION}")
  server_api_v = server_api_version
  raise Error::YuiRestClientError if server_api_v.nil?

  YuiRestClient.logger.info("Server API version: #{server_api_v}")
  server_api_v <= client_api_version
end
checkbox(filter) click to toggle source

Initializes new instance of Checkbox with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Checkbox] new instance of Checkbox @example

app.checkbox(id: 'id', label: 'label', class: 'YCheckBox')
# File lib/yui_rest_client/app.rb, line 54
def checkbox(filter)
  Widgets::Checkbox.new(@widget_controller, FilterExtractor.new(filter))
end
client_api_version() click to toggle source

Returns client side libyui REST API version @return libyui client REST API version

# File lib/yui_rest_client/app.rb, line 220
def client_api_version
  API_VERSION
end
combobox(filter) click to toggle source

Initializes new instance of Combobox with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Combobox] new instance of Combobox @example

app.combobox(id: 'id', label: 'label', class: 'YComboBox')
# File lib/yui_rest_client/app.rb, line 64
def combobox(filter)
  Widgets::Combobox.new(@widget_controller, FilterExtractor.new(filter))
end
connect() click to toggle source

wait until the specified port is open or until the timeout is reached @raise YuiRestClient::Error::TimeoutError if the port is not opened in time

# File lib/yui_rest_client/app.rb, line 20
def connect
  Wait.until(timeout: YuiRestClient.timeout, interval: YuiRestClient.interval) do
    YuiRestClient.logger.debug("Waiting for #{@host}:#{@port}...")
    port_open?
  end
  self
end
datefield(filter) click to toggle source

Initializes new instance of Datefield with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Datefield] new instance of Datefield @example

app.datefield(id: 'id', label: 'label', class: 'YDateField')
# File lib/yui_rest_client/app.rb, line 74
def datefield(filter)
  Widgets::Datefield.new(@widget_controller, FilterExtractor.new(filter))
end
label(filter) click to toggle source

Initializes new instance of Label with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Label] new instance of Label @example

app.label(id: 'id', label: 'label', class: 'YLabel')
# File lib/yui_rest_client/app.rb, line 84
def label(filter)
  Widgets::Label.new(@widget_controller, FilterExtractor.new(filter))
end
menucollection(filter) click to toggle source

Initializes new instance of Menucollection with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Menucollection] new instance of Menucollection @example

app.menucollection(id: 'id', label: 'label', class: 'YMenuButton')
multilinebox(filter) click to toggle source

Initializes new instance of Multilinebox with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Multilinebox] new instance of Multilinebox @example

app.multilinebox(id: 'id', label: 'label', class: 'YMultiLineEdit')
# File lib/yui_rest_client/app.rb, line 104
def multilinebox(filter)
  Widgets::Multilinebox.new(@widget_controller, FilterExtractor.new(filter))
end
numberbox(filter) click to toggle source

Initializes new instance of Numberbox with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Numberbox] new instance of Numberbox @example

app.numberbox(id: 'id', label: 'label', class: 'YIntField')
# File lib/yui_rest_client/app.rb, line 114
def numberbox(filter)
  Widgets::Numberbox.new(@widget_controller, FilterExtractor.new(filter))
end
progressbar(filter) click to toggle source

Initializes new instance of Progressbar with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Progressbar] new instance of Progressbar @example

app.progressbar(id: 'id', label: 'label', class: 'YProgressBar')
# File lib/yui_rest_client/app.rb, line 124
def progressbar(filter)
  Widgets::Progressbar.new(@widget_controller, FilterExtractor.new(filter))
end
radiobutton(filter) click to toggle source

Initializes new instance of Radiobutton with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Radiobutton] new instance of Radiobutton @example

app.radiobutton(id: 'id', label: 'label', class: 'YRadioButton')
# File lib/yui_rest_client/app.rb, line 134
def radiobutton(filter)
  Widgets::Radiobutton.new(@widget_controller, FilterExtractor.new(filter))
end
richtext(filter) click to toggle source

Initializes new instance of Richtext with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Richtext] new instance of Richtext @example

app.richtext(id: 'id', label: 'label', class: 'YRichText')
# File lib/yui_rest_client/app.rb, line 144
def richtext(filter)
  Widgets::Richtext.new(@widget_controller, FilterExtractor.new(filter))
end
selectionbox(filter) click to toggle source

Initializes new instance of Selectionbox with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Selectionbox] new instance of Selectionbox @example

app.selectionbox(id: 'id', label: 'label', class: 'YSelectionBox')
# File lib/yui_rest_client/app.rb, line 154
def selectionbox(filter)
  Widgets::Selectionbox.new(@widget_controller, FilterExtractor.new(filter))
end
server_api_version() click to toggle source

Returns server side libyui REST API version @return libyui server REST API version

# File lib/yui_rest_client/app.rb, line 226
def server_api_version
  @version_controller.api_version
end
tab(filter) click to toggle source

Initializes new instance of Tab with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Tab] new instance of Tab @example

app.tab(id: 'id', label: 'label', class: 'YDumbTab')
# File lib/yui_rest_client/app.rb, line 164
def tab(filter)
  Widgets::Tab.new(@widget_controller, FilterExtractor.new(filter))
end
table(filter) click to toggle source

Initializes new instance of Table with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Table] new instance of Table @example

app.table(id: 'id', label: 'label', class: 'YTable')
# File lib/yui_rest_client/app.rb, line 174
def table(filter)
  Widgets::Table.new(@widget_controller, FilterExtractor.new(filter))
end
textbox(filter) click to toggle source

Initializes new instance of Textbox with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Textbox] new instance of Textbox @example

app.textbox(id: 'id', label: 'label', class: 'YInputField')
# File lib/yui_rest_client/app.rb, line 194
def textbox(filter)
  Widgets::Textbox.new(@widget_controller, FilterExtractor.new(filter))
end
timefield(filter) click to toggle source

Initializes new instance of time field with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Timefield] new instance of Table @example

app.timefield(id: 'id', label: 'label', class: 'YTimeField')
# File lib/yui_rest_client/app.rb, line 184
def timefield(filter)
  Widgets::Timefield.new(@widget_controller, FilterExtractor.new(filter))
end
tree(filter) click to toggle source

Initializes new instance of Tree with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Tree] new instance of Tree @example

app.tree(id: 'id', label: 'label', class: 'YTree')
# File lib/yui_rest_client/app.rb, line 204
def tree(filter)
  Widgets::Tree.new(@widget_controller, FilterExtractor.new(filter))
end
wizard(filter) click to toggle source

Initializes new instance of Wizard with the filter provided. Does not make request to libyui-rest-api. @param filter [Hash] filter to find a widget @return [Widgets::Wizard] new instance of Wizard @example

app.wizard(id: 'id', label: 'label', class: 'YWizard')
# File lib/yui_rest_client/app.rb, line 214
def wizard(filter)
  Widgets::Wizard.new(@widget_controller, FilterExtractor.new(filter))
end

Private Instance Methods

port_open?(seconds = 1) click to toggle source

is the target port open? @return [Boolean] true if the port is open, false otherwise

# File lib/yui_rest_client/app.rb, line 246
def port_open?(seconds = 1)
  Timeout.timeout(seconds) do
    TCPSocket.new(@host, @port).close
    true
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
    false
  end
rescue Timeout::Error
  false
end