class YuiRestClient::Http::WidgetController

Public Class Methods

new(host:, port:) click to toggle source
# File lib/yui_rest_client/http/widget_controller.rb, line 6
def initialize(host:, port:)
  @host = host
  @port = port
  @timeout = YuiRestClient.timeout
  @interval = YuiRestClient.interval
end

Public Instance Methods

find(filter) click to toggle source

Find a widget using the filter. @param filter [Hash] identifiers to find a widget @return [Response]

# File lib/yui_rest_client/http/widget_controller.rb, line 16
def find(filter)
  res = nil
  Wait.until(timeout: @timeout, interval: @interval) do
    uri = HttpClient.compose_uri(@host, @port, "/#{API_VERSION}/widgets", filter)
    res = HttpClient.http_get(uri)
    Response.new(res) if res.is_a?(Net::HTTPOK)
  end
rescue Error::TimeoutError
  rescue_errors(res)
end
send_action(filter, action) click to toggle source

Perform an action on the widget. @param filter [Hash] identifiers to find a widget @param action [Hash] what to do with the widget @return [Response]

# File lib/yui_rest_client/http/widget_controller.rb, line 31
def send_action(filter, action)
  res = nil
  Wait.until(timeout: @timeout, interval: @interval) do
    uri = HttpClient.compose_uri(@host, @port, "/#{API_VERSION}/widgets",
                                 filter.merge(action))
    res = HttpClient.http_post(uri)
    Response.new(res) if res.is_a?(Net::HTTPOK)
  end
rescue Error::TimeoutError
  rescue_errors(res)
end

Private Instance Methods

rescue_errors(response) click to toggle source
# File lib/yui_rest_client/http/widget_controller.rb, line 45
def rescue_errors(response)
  raise Error::WidgetNotFoundError if response.is_a?(Net::HTTPNotFound)

  raise Error::ItemNotFoundInWidgetError if response.is_a?(Net::HTTPUnprocessableEntity)

  raise Error::YuiRestClientError
end