Skip to content

Commit

Permalink
Add shorter aliases for HTTP actions: HTTP.get, HTTP.post, `HTTP.…
Browse files Browse the repository at this point in the history
…put`, `HTTP.delete` (#367)
  • Loading branch information
jimtng authored Dec 14, 2024
1 parent 563213a commit 275f8d5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/openhab/core/actions/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 275f8d5

Please sign in to comment.