Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shorter aliases for HTTP actions: HTTP.get, HTTP.post, HTTP.put, HTTP.delete #367

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading