Class: Pinnacle::Internal::Http::RawClient Private
- Inherits:
-
Object
- Object
- Pinnacle::Internal::Http::RawClient
- Defined in:
- lib/pinnacle/internal/http/raw_client.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
private
The base URL for requests.
Instance Method Summary collapse
-
#build_http_request(url:, method:, headers: {}, body: nil) ⇒ HTTP::Request
private
The HTTP request.
-
#build_url(request) ⇒ URI::Generic
private
The URL.
-
#connect(url) ⇒ Net::HTTP
private
The HTTP connection.
-
#encode_query(query) ⇒ String?
private
The encoded query.
-
#initialize(base_url:, max_retries: 2, timeout: 60.0, headers: {}) ⇒ RawClient
constructor
private
A new instance of RawClient.
- #inspect ⇒ String private
-
#send(request) ⇒ HTTP::Response
private
The HTTP response.
Constructor Details
#initialize(base_url:, max_retries: 2, timeout: 60.0, headers: {}) ⇒ RawClient
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RawClient.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 15 def initialize(base_url:, max_retries: 2, timeout: 60.0, headers: {}) @base_url = base_url @max_retries = max_retries @timeout = timeout @default_headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "rcs", "X-Fern-SDK-Version": "0.0.1" }.merge(headers) end |
Instance Attribute Details
#base_url ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The base URL for requests.
9 10 11 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 9 def base_url @base_url end |
Instance Method Details
#build_http_request(url:, method:, headers: {}, body: nil) ⇒ HTTP::Request
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The HTTP request.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 69 def build_http_request(url:, method:, headers: {}, body: nil) request = Net::HTTPGenericRequest.new( method, !body.nil?, method != "HEAD", url ) request_headers = @default_headers.merge(headers) request_headers.each { |name, value| request[name] = value } request.body = body if body request end |
#build_url(request) ⇒ URI::Generic
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The URL.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 49 def build_url(request) # If the path is already an absolute URL, use it directly if request.path.start_with?("http://", "https://") url = request.path url = "#{url}?#{encode_query(request.query)}" if request.query&.any? return URI.parse(url) end path = request.path.start_with?("/") ? request.path[1..] : request.path base = request.base_url || @base_url url = "#{base.chomp("/")}/#{path}" url = "#{url}?#{encode_query(request.query)}" if request.query&.any? URI.parse(url) end |
#connect(url) ⇒ Net::HTTP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The HTTP connection.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 92 def connect(url) is_https = (url.scheme == "https") port = if url.port url.port elsif is_https Net::HTTP.https_default_port else Net::HTTP.http_default_port end http = Net::HTTP.new(url.host, port) http.use_ssl = is_https http.max_retries = @max_retries http end |
#encode_query(query) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The encoded query.
86 87 88 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 86 def encode_query(query) query.to_h.empty? ? nil : URI.encode_www_form(query) end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 110 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} @base_url=#{@base_url.inspect}>" end |
#send(request) ⇒ HTTP::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The HTTP response.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pinnacle/internal/http/raw_client.rb', line 28 def send(request) url = build_url(request) http_request = build_http_request( url:, method: request.method, headers: request.encode_headers, body: request.encode_body ) conn = connect(url) conn.open_timeout = @timeout conn.read_timeout = @timeout conn.write_timeout = @timeout conn.continue_timeout = @timeout conn.request(http_request) end |