Class: Zenrows::ApiClient
- Inherits:
-
Object
- Object
- Zenrows::ApiClient
- Defined in:
- lib/zenrows/api_client.rb
Overview
REST API client for ZenRows Universal Scraper API
Unlike the proxy-based Client, ApiClient calls the ZenRows API directly. This enables features not available in proxy mode: autoparse, css_extractor, response_type (markdown), and outputs.
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
readonly
API endpoint URL.
-
#api_key ⇒ String
readonly
ZenRows API key.
-
#config ⇒ Configuration
readonly
Configuration instance.
Instance Method Summary collapse
-
#get(url, **options) ⇒ ApiResponse
Make GET request through ZenRows API.
-
#initialize(api_key: nil, api_endpoint: nil) ⇒ ApiClient
constructor
Initialize API client.
-
#post(url, body: nil, **options) ⇒ ApiResponse
Make POST request through ZenRows API.
Constructor Details
#initialize(api_key: nil, api_endpoint: nil) ⇒ ApiClient
Initialize API client
45 46 47 48 49 50 |
# File 'lib/zenrows/api_client.rb', line 45 def initialize(api_key: nil, api_endpoint: nil) @config = Zenrows.configuration @api_key = api_key || @config.api_key @api_endpoint = api_endpoint || @config.api_endpoint @config.validate! unless api_key end |
Instance Attribute Details
#api_endpoint ⇒ String (readonly)
Returns API endpoint URL.
36 37 38 |
# File 'lib/zenrows/api_client.rb', line 36 def api_endpoint @api_endpoint end |
#api_key ⇒ String (readonly)
Returns ZenRows API key.
33 34 35 |
# File 'lib/zenrows/api_client.rb', line 33 def api_key @api_key end |
#config ⇒ Configuration (readonly)
Returns Configuration instance.
39 40 41 |
# File 'lib/zenrows/api_client.rb', line 39 def config @config end |
Instance Method Details
#get(url, **options) ⇒ ApiResponse
Make GET request through ZenRows API
78 79 80 81 82 |
# File 'lib/zenrows/api_client.rb', line 78 def get(url, **) params = build_params(url, ) http_response = build_http_client.get(api_endpoint, params: params) handle_response(http_response, ) end |
#post(url, body: nil, **options) ⇒ ApiResponse
Make POST request through ZenRows API
90 91 92 93 94 |
# File 'lib/zenrows/api_client.rb', line 90 def post(url, body: nil, **) params = build_params(url, ) http_response = build_http_client.post(api_endpoint, params: params, body: body) handle_response(http_response, ) end |