-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cherry-pick-ce-commit-ff78e335d2fbee8d30d390…
…1bc42b2d3e69c428e4
- Loading branch information
Showing
23 changed files
with
757 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
integrations/lib/multiwoven/integrations/core/http_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Multiwoven | ||
module Integrations::Core | ||
module HttpHelper | ||
def build_request(method, uri, payload, headers) | ||
request_class = case method.upcase | ||
when Constants::HTTP_GET then Net::HTTP::Get | ||
when Constants::HTTP_POST then Net::HTTP::Post | ||
when Constants::HTTP_PUT then Net::HTTP::Put | ||
when Constants::HTTP_PATCH then Net::HTTP::Patch | ||
when Constants::HTTP_DELETE then Net::HTTP::Delete | ||
else raise ArgumentError, "Unsupported HTTP method: #{method}" | ||
end | ||
|
||
request = request_class.new(uri) | ||
headers.each { |key, value| request[key] = value } | ||
request.body = payload.to_json if payload && %w[POST PUT PATCH].include?(method.upcase) | ||
request | ||
end | ||
|
||
def configure_http(uri, config) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = (uri.scheme == "https") | ||
|
||
if config[:timeout] | ||
timeout_value = config[:timeout].to_f | ||
http.open_timeout = timeout_value | ||
http.read_timeout = timeout_value | ||
end | ||
|
||
http | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
integrations/lib/multiwoven/integrations/core/streaming_http_client.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Multiwoven | ||
module Integrations::Core | ||
class StreamingHttpClient | ||
extend HttpHelper | ||
class << self | ||
def request(url, method, payload: nil, headers: {}, config: {}) | ||
uri = URI(url) | ||
http = configure_http(uri, config) | ||
request = build_request(method, uri, payload, headers) | ||
http.request(request) do |response| | ||
response.read_body do |chunk| | ||
yield chunk if block_given? # Pass each response chunk | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.