Class: Zenrows::Backends::NetHttpClient Private

Inherits:
Object
  • Object
show all
Defined in:
lib/zenrows/backends/net_http.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.

Wrapper around Net::HTTP that mimics http.rb interface

Since:

  • 0.1.0

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(proxy_config:, headers:, timeouts:, ssl_context:) ⇒ NetHttpClient

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 NetHttpClient.

Parameters:

  • Proxy configuration

  • Default headers

  • Timeout configuration

  • SSL context

Since:

  • 0.1.0

API:

  • private



60
61
62
63
64
65
# File 'lib/zenrows/backends/net_http.rb', line 60

def initialize(proxy_config:, headers:, timeouts:, ssl_context:)
  @proxy_config = proxy_config
  @headers = headers
  @timeouts = timeouts
  @ssl_context = ssl_context
end

Instance Method Details

#get(url, **options) ⇒ NetHttpResponse

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.

Make GET request

Parameters:

  • Target URL

  • Request options

Returns:

  • Response wrapper

Since:

  • 0.1.0

API:

  • private



72
73
74
75
# File 'lib/zenrows/backends/net_http.rb', line 72

def get(url, **options)
  uri = URI.parse(url)
  request(uri, Net::HTTP::Get.new(uri), options)
end

#post(url, body: nil, **options) ⇒ NetHttpResponse

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.

Make POST request

Parameters:

  • Target URL

  • (defaults to: nil)

    Request body

  • Request options

Returns:

  • Response wrapper

Since:

  • 0.1.0

API:

  • private



83
84
85
86
87
88
# File 'lib/zenrows/backends/net_http.rb', line 83

def post(url, body: nil, **options)
  uri = URI.parse(url)
  req = Net::HTTP::Post.new(uri)
  req.body = body if body
  request(uri, req, options)
end