From 275f8d597c58205fbe2af777091d38f03b20a22f Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Sun, 15 Dec 2024 01:05:05 +1000 Subject: [PATCH] Add shorter aliases for HTTP actions: `HTTP.get`, `HTTP.post`, `HTTP.put`, `HTTP.delete` (#367) --- lib/openhab/core/actions/http.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/openhab/core/actions/http.rb b/lib/openhab/core/actions/http.rb index acdfd3a1bc..b1a731e257 100644 --- a/lib/openhab/core/actions/http.rb +++ b/lib/openhab/core/actions/http.rb @@ -12,7 +12,7 @@ module Actions # "User-Agent": "JRuby/1.2.3", # enclose in quotes if the key contains dashes # Accept: "application/json", # } - # response = HTTP.send_http_get_request("http://example.com/list", headers: headers) + # response = HTTP.get("http://example.com/list", headers: headers) # # @see https://www.openhab.org/docs/configuration/actions.html#http-actions HTTP Actions class HTTP @@ -33,6 +33,7 @@ def send_http_get_request(url, headers: {}, timeout: nil) sendHttpGetRequest(url, headers.transform_keys(&:to_s), timeout) end + alias_method :get, :send_http_get_request # # Sends an HTTP PUT request and returns the result as a String. @@ -52,6 +53,7 @@ def send_http_put_request(url, content_type = nil, content = nil, headers: {}, t sendHttpPutRequest(url, content_type, content, headers.transform_keys(&:to_s), timeout) end + alias_method :put, :send_http_put_request # # Sends an HTTP POST request and returns the result as a String. @@ -71,6 +73,7 @@ def send_http_post_request(url, content_type = nil, content = nil, headers: {}, sendHttpPostRequest(url, content_type, content, headers.transform_keys(&:to_s), timeout) end + alias_method :post, :send_http_post_request # # Sends an HTTP DELETE request and returns the result as a String. @@ -89,6 +92,7 @@ def send_http_delete_request(url, headers: {}, timeout: nil) sendHttpDeleteRequest(url, headers.transform_keys(&:to_s), timeout) end + alias_method :delete, :send_http_delete_request end end end