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

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_config (Hash)

    Proxy configuration

  • headers (Hash)

    Default headers

  • timeouts (Hash)

    Timeout configuration

  • ssl_context (OpenSSL::SSL::SSLContext)

    SSL context

Since:

  • 0.1.0



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:

  • url (String)

    Target URL

  • options (Hash)

    Request options

Returns:

Since:

  • 0.1.0



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:

  • url (String)

    Target URL

  • body (String, nil) (defaults to: nil)

    Request body

  • options (Hash)

    Request options

Returns:

Since:

  • 0.1.0



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