Class: Pangea::Internal::Transport::BaseClient Abstract Private
- Inherits:
-
Object
- Object
- Pangea::Internal::Transport::BaseClient
- Defined in:
- lib/pangea/internal/transport/base_client.rb
Overview
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.
Direct Known Subclasses
Constant Summary collapse
- PLATFORM_HEADERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ "user-agent" => "pangea-ruby/#{Pangea::VERSION}" }
Instance Attribute Summary collapse
Class Method Summary collapse
- .reap_connection!(status, stream:) ⇒ Object private
- .validate!(req) ⇒ Object private
Instance Method Summary collapse
-
#initialize(base_url:, headers: {}, initial_retry_delay: 0.0, max_retries: 0, timeout: 0.0) ⇒ BaseClient
constructor
private
A new instance of BaseClient.
-
#request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: Pangea::Internal::Type::Unknown, options: {}) ⇒ Object
private
Execute the request specified by ‘req`.
Constructor Details
#initialize(base_url:, headers: {}, initial_retry_delay: 0.0, max_retries: 0, timeout: 0.0) ⇒ BaseClient
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 BaseClient.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pangea/internal/transport/base_client.rb', line 66 def initialize( base_url:, headers: {}, initial_retry_delay: 0.0, max_retries: 0, timeout: 0.0 ) @requester = Pangea::Internal::Transport::PooledNetRequester.new @base_url = Pangea::Internal::Util.parse_uri(base_url) @headers = Pangea::Internal::Util.normalized_headers( self.class::PLATFORM_HEADERS, { "accept" => "application/json", "content-type" => "application/json" }, headers ) @initial_retry_delay = initial_retry_delay @max_retries = max_retries @timeout = timeout end |
Instance Attribute Details
#requester ⇒ Pangea::Internal::Transport::PooledNetRequester
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.
57 58 59 |
# File 'lib/pangea/internal/transport/base_client.rb', line 57 def requester @requester end |
Class Method Details
.reap_connection!(status, stream:) ⇒ Object
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.
25 26 27 28 29 30 31 32 33 |
# File 'lib/pangea/internal/transport/base_client.rb', line 25 def reap_connection!(status, stream:) case status in (..199) | (300..499) stream&.each { next } in Pangea::Errors::APIConnectionError | (500..) Pangea::Internal::Util.close_fused!(stream) else end end |
.validate!(req) ⇒ Object
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pangea/internal/transport/base_client.rb', line 40 def validate!(req) keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :structure, :model, :options] case req in Hash req.each_key do |k| unless keys.include?(k) raise ArgumentError.new("Request `req` keys must be one of #{keys}, got #{k.inspect}") end end else raise ArgumentError.new("Request `req` must be a Hash or RequestOptions, got #{req.inspect}") end end |
Instance Method Details
#request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: Pangea::Internal::Type::Unknown, options: {}) ⇒ Object
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.
Execute the request specified by ‘req`. This is the method that all resource methods call into.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/pangea/internal/transport/base_client.rb', line 317 def request(req) self.class.validate!(req) model = req.fetch(:model) { Pangea::Internal::Type::Unknown } opts = req[:options].to_h Pangea::RequestOptions.validate!(opts) request = build_request(req.except(:options), opts) _url = request.fetch(:url) _status, response, stream = send_request( request, redirect_count: 0, retry_count: 0, send_retry_header: false ) decoded = Pangea::Internal::Util.decode_content(response, stream: stream) case req in {structure: Class => pr} pr.new(response_data: decoded, model: model) in {page: Class => page} page.new(client: self, req: req, headers: response, page_data: decoded) else unwrapped = Pangea::Internal::Util.dig(decoded, req[:unwrap]) Pangea::Internal::Type::Converter.coerce(model, unwrapped) end end |