Class: Ashby::Offers

Inherits:
Client show all
Defined in:
lib/ashby/offers.rb

Overview

Ashby::Offers provides access to offer-related endpoints in the Ashby API.

Supports fetching all offers with pagination and retrieving a specific offer by ID.

Example:

Ashby::Offers.all
Ashby::Offers.find(id: 'offer_xyz789')

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

.allObject

Fetches all offers with pagination support



14
15
16
# File 'lib/ashby/offers.rb', line 14

def self.all
  paginated_post('offer.list')
end

.find(id: nil) ⇒ Object

Finds an offer by its Ashby ID

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/ashby/offers.rb', line 19

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

  payload = { id: id }
  response = post('offer.info', payload)
  response['results']
end

.most_recent_offer_by_application_id(application_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


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

def self.most_recent_offer_by_application_id(application_id: nil)
  raise ArgumentError, 'Application ID is required' if application_id.to_s.strip.empty?

  payload = { applicationId: application_id }
  response = post('offer.list', payload)
  response['results'].max_by { |o| o['latestVersion']['createdAt'] }
end

.offers_by_application_id(application_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
# File 'lib/ashby/offers.rb', line 27

def self.offers_by_application_id(application_id: nil)
  raise ArgumentError, 'Application ID is required' if application_id.to_s.strip.empty?

  payload = { applicationId: application_id }
  response = post('offer.list', payload)
  response['results']
end