Class: ScreenshotFreeAPI::Client
- Inherits:
-
Object
- Object
- ScreenshotFreeAPI::Client
- Defined in:
- lib/screenshotfreeapi/client.rb
Overview
Main entry point for the ScreenshotFreeAPI Ruby SDK.
Instantiate once (e.g., in a Rails initializer) and reuse across requests. All resource objects share the same underlying HttpClient instance.
Quick start:
client = ScreenshotFreeAPI::Client.new(api_key: ENV["SCREENSHOTFREEAPI_KEY"])
result = client.capture("https://stripe.com", format: "png")
puts result["screenshots"].first["url"]
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#billing ⇒ Object
readonly
Returns the value of attribute billing.
-
#integrations ⇒ Object
readonly
Returns the value of attribute integrations.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#monitors ⇒ Object
readonly
Returns the value of attribute monitors.
-
#screenshots ⇒ Object
readonly
Returns the value of attribute screenshots.
-
#workspaces ⇒ Object
readonly
Returns the value of attribute workspaces.
Instance Method Summary collapse
-
#capture(url, poll_interval: 2, timeout: 120, **opts) {|status| ... } ⇒ Hash
Convenience method: capture a URL and wait for the result.
-
#health ⇒ Hash
Check API health (no authentication required).
-
#initialize(api_key:, base_url: HttpClient::DEFAULT_BASE_URL, timeout: HttpClient::DEFAULT_TIMEOUT, max_retries: HttpClient::DEFAULT_RETRIES) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key:, base_url: HttpClient::DEFAULT_BASE_URL, timeout: HttpClient::DEFAULT_TIMEOUT, max_retries: HttpClient::DEFAULT_RETRIES) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/screenshotfreeapi/client.rb', line 22 def initialize( api_key:, base_url: HttpClient::DEFAULT_BASE_URL, timeout: HttpClient::DEFAULT_TIMEOUT, max_retries: HttpClient::DEFAULT_RETRIES ) @http = HttpClient.new( api_key: api_key, base_url: base_url, timeout: timeout, max_retries: max_retries ) @screenshots = Resources::Screenshots.new(@http) @jobs = Resources::Jobs.new(@http) @auth = Resources::Auth.new(@http) @billing = Resources::Billing.new(@http) @workspaces = Resources::Workspaces.new(@http) @monitors = Resources::Monitors.new(@http) @integrations = Resources::Integrations.new(@http) end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def auth @auth end |
#billing ⇒ Object (readonly)
Returns the value of attribute billing.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def billing @billing end |
#integrations ⇒ Object (readonly)
Returns the value of attribute integrations.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def integrations @integrations end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def jobs @jobs end |
#monitors ⇒ Object (readonly)
Returns the value of attribute monitors.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def monitors @monitors end |
#screenshots ⇒ Object (readonly)
Returns the value of attribute screenshots.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def screenshots @screenshots end |
#workspaces ⇒ Object (readonly)
Returns the value of attribute workspaces.
16 17 18 |
# File 'lib/screenshotfreeapi/client.rb', line 16 def workspaces @workspaces end |
Instance Method Details
#capture(url, poll_interval: 2, timeout: 120, **opts) {|status| ... } ⇒ Hash
Convenience method: capture a URL and wait for the result.
Equivalent to ‘client.screenshots.web_and_wait({ url: url }.merge(opts))`.
55 56 57 58 |
# File 'lib/screenshotfreeapi/client.rb', line 55 def capture(url, poll_interval: 2, timeout: 120, **opts, &on_progress) = { url: url }.merge(opts) @screenshots.web_and_wait(, poll_interval: poll_interval, timeout: timeout, &on_progress) end |
#health ⇒ Hash
Check API health (no authentication required).
63 64 65 |
# File 'lib/screenshotfreeapi/client.rb', line 63 def health @http.request(:get, "/health", auth_header: "") end |