Class: Ashby::JobPostings

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

Overview

Ashby::JobPostings provides access to job posting-related functionality in the Ashby API.

Includes support for:

- Fetching all job postings (active only by default, can include inactive)
- Looking up a job posting by its Ashby ID

Example usage:

Ashby::JobPostings.all
Ashby::JobPostings.all(active_only: false)
Ashby::JobPostings.find_by_id(id: 'jp_abc456')

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

.all(active_only: true, job_board_id: nil) ⇒ Object

Fetches all job postings



17
18
19
20
21
22
23
# File 'lib/ashby/job_postings.rb', line 17

def self.all(active_only: true, job_board_id: nil)
  payload = { listedOnly: active_only }
  payload[:jobBoardId] = job_board_id if job_board_id

  response = post('jobPosting.list', payload)
  response['results']
end

.by_job_id(job_id: nil) ⇒ Object

Finds all Job Postings associated with a given Job ID

Raises:

  • (ArgumentError)


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

def self.by_job_id(job_id: nil)
  raise ArgumentError, 'Job ID is required' if job_id.to_s.strip.empty?

  payload = { id: job_id }
  response = post('job.info', payload)
  job_posting_ids = response.dig('results', 'jobPostingIds') || []

  job_posting_ids.map { |jp_id| find_by_id(id: jp_id) }
end

.find_by_id(id: nil) ⇒ Object

Finds a Job Posting by the Ashby ID

Raises:

  • (ArgumentError)


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

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

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