Class: YuiRestClient::Http::WidgetController

Inherits:
Object
  • Object
show all
Defined in:
lib/yui_rest_client/http/widget_controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:) ⇒ WidgetController

Returns a new instance of WidgetController.



6
7
8
9
10
11
# 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

Instance Method Details

#find(filter) ⇒ Response

Find a widget using the filter.

Parameters:

  • filter (Hash)

    identifiers to find a widget

Returns:



16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Response

Perform an action on the widget.

Parameters:

  • filter (Hash)

    identifiers to find a widget

  • action (Hash)

    what to do with the widget

Returns:



31
32
33
34
35
36
37
38
39
40
41
# 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