Class: BrightData::HTTP
- Inherits:
-
Object
- Object
- BrightData::HTTP
- Defined in:
- lib/brightdata/http.rb
Overview
Thin Net::HTTP wrapper. Single point of egress for the gem.
Optional request tracing lives in LiveTrace, kept out of this class so the request path stays a small, readable Net::HTTP shim.
Constant Summary collapse
- BASE_URL =
Returns default Bright Data API base URL.
"https://api.brightdata.com"- DEFAULT_TIMEOUT =
Must be greater than Bright Data’s ‘/scrape` 60-second API cap.
90
Instance Method Summary collapse
-
#get(path:, query: {}) ⇒ Hash, ...
GET a path.
-
#initialize(api_token:, base_url: BASE_URL, open_timeout: 10, read_timeout: DEFAULT_TIMEOUT, logger: nil) ⇒ HTTP
constructor
A new instance of HTTP.
-
#post(path:, query: {}, body: nil) ⇒ Hash, ...
POST a JSON body.
Constructor Details
#initialize(api_token:, base_url: BASE_URL, open_timeout: 10, read_timeout: DEFAULT_TIMEOUT, logger: nil) ⇒ HTTP
Returns a new instance of HTTP.
27 28 29 30 31 32 33 34 35 |
# File 'lib/brightdata/http.rb', line 27 def initialize(api_token:, base_url: BASE_URL, open_timeout: 10, read_timeout: DEFAULT_TIMEOUT, logger: nil) raise ConfigurationError, "api_token is required" if api_token.nil? || api_token.empty? @api_token = api_token @base_url = base_url @open_timeout = open_timeout @read_timeout = read_timeout @logger = logger end |
Instance Method Details
#get(path:, query: {}) ⇒ Hash, ...
GET a path.
54 55 56 |
# File 'lib/brightdata/http.rb', line 54 def get(path:, query: {}) request(method: :get, path:, query:) end |
#post(path:, query: {}, body: nil) ⇒ Hash, ...
POST a JSON body.
44 45 46 |
# File 'lib/brightdata/http.rb', line 44 def post(path:, query: {}, body: nil) request(method: :post, path:, query:, body:) end |