Class: Ashby::Reports

Inherits:
Client
  • Object
show all
Defined in:
lib/ashby/reports.rb

Overview

Ashby::Reports provides access to report-related functionality in the Ashby API.

Supports running reports synchronously and generating them asynchronously. The synchronous endpoint has a 30-second timeout; for longer-running reports, use the asynchronous generate method.

Example:

Ashby::Reports.synchronous(id: 'report_abc123')

# Async generation - two-step process
result = Ashby::Reports.generate(id: 'report_abc123')
request_id = result['requestId']
# Poll until complete
result = Ashby::Reports.generate(id: 'report_abc123', request_id: request_id)

Constant Summary

Constants inherited from Client

Client::API_URL

Class Method Summary collapse

Methods inherited from Client

build_url, headers, paginated_post, post

Class Method Details

.generate(id: nil, request_id: nil) ⇒ Object

Generates a report asynchronously Two-step process:

  1. Call with only report_id to start generation (returns request_id)
  2. Poll with both report_id and request_id until status is 'complete' or 'failed'

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
# File 'lib/ashby/reports.rb', line 34

def self.generate(id: nil, request_id: nil)
  raise ArgumentError, 'Report ID is required' if id.to_s.strip.empty?

  payload = { reportId: id }
  payload[:requestId] = request_id unless request_id.to_s.strip.empty?

  response = post('report.generate', payload)
  response['results']
end

.synchronous(id: nil) ⇒ Object

Retrieves report data synchronously (30 second timeout) If a report times out, use generate instead

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'lib/ashby/reports.rb', line 22

def self.synchronous(id: nil)
  raise ArgumentError, 'Report ID is required' if id.to_s.strip.empty?

  payload = { reportId: id }
  response = post('report.synchronous', payload)
  response['results']
end