Class: OpenHAB::Core::Actions::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/actions/http.rb

Overview

See Also:

Class Method Summary collapse

Class Method Details

.send_http_delete_request(url, headers: {}, timeout: nil) ⇒ String?

Sends an HTTP DELETE request and returns the result as a String.

Parameters:

  • url (String)
  • headers (Hash<String, String>) (defaults to: {})
  • timeout (Duration, int, nil) (defaults to: nil)

    Timeout (in milliseconds, if given as an Integer)

Returns:

  • (String)

    the response body

  • (nil)

    if an error occurred



70
71
72
73
74
75
# File 'lib/openhab/core/actions/http.rb', line 70

def send_http_delete_request(url, headers: {}, timeout: nil)
  timeout ||= 1_000
  timeout = timeout.to_millis if timeout.is_a?(Duration)

  sendHttpDeleteRequest(url, headers, timeout)
end

.send_http_get_request(url, headers: {}, timeout: nil) ⇒ String?

Sends an HTTP GET request and returns the result as a String.

Parameters:

  • url (String)
  • headers (Hash<String, String>) (defaults to: {})
  • timeout (Duration, int, nil) (defaults to: nil)

    Timeout (in milliseconds, if given as an Integer)

Returns:

  • (String)

    the response body

  • (nil)

    if an error occurred



18
19
20
21
22
23
# File 'lib/openhab/core/actions/http.rb', line 18

def send_http_get_request(url, headers: {}, timeout: nil)
  timeout ||= 5_000
  timeout = timeout.to_millis if timeout.is_a?(Duration)

  sendHttpGetRequest(url, headers, timeout)
end

.send_http_post_request(url, content_type = nil, content = nil, headers: {}, timeout: nil) ⇒ String?

Sends an HTTP POST request and returns the result as a String.

Parameters:

  • url (String)
  • content_type (String) (defaults to: nil)
  • content (String) (defaults to: nil)
  • headers (Hash<String, String>) (defaults to: {})
  • timeout (Duration, int, nil) (defaults to: nil)

    Timeout (in milliseconds, if given as an Integer)

Returns:

  • (String)

    the response body

  • (nil)

    if an error occurred



54
55
56
57
58
59
# File 'lib/openhab/core/actions/http.rb', line 54

def send_http_post_request(url, content_type = nil, content = nil, headers: {}, timeout: nil)
  timeout ||= 1_000
  timeout = timeout.to_millis if timeout.is_a?(Duration)

  sendHttpPostRequest(url, content_type, content, headers, timeout)
end

.send_http_put_request(url, content_type = nil, content = nil, headers: {}, timeout: nil) ⇒ String?

Sends an HTTP PUT request and returns the result as a String.

Parameters:

  • url (String)
  • content_type (String) (defaults to: nil)
  • content (String) (defaults to: nil)
  • headers (Hash<String, String>) (defaults to: {})
  • timeout (Duration, int, nil) (defaults to: nil)

    Timeout (in milliseconds, if given as an Integer)

Returns:

  • (String)

    the response body

  • (nil)

    if an error occurred



36
37
38
39
40
41
# File 'lib/openhab/core/actions/http.rb', line 36

def send_http_put_request(url, content_type = nil, content = nil, headers: {}, timeout: nil)
  timeout ||= 1_000
  timeout = timeout.to_millis if timeout.is_a?(Duration)

  sendHttpPutRequest(url, content_type, content, headers, timeout)
end