Class: Ashby::Jobs

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

Overview

Ashby::Jobs handles interactions with job-related endpoints in the Ashby API.

Supports fetching all jobs with pagination, finding a job by ID, and searching jobs based on requisition ID or title.

Example:

Ashby::Jobs.all
Ashby::Jobs.find('job_abc123')
Ashby::Jobs.search(req_id: 'REQ-001')

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(payload = {}) ⇒ Object

Fetches all jobs with pagination support



16
17
18
# File 'lib/ashby/jobs.rb', line 16

def self.all(payload = {})
  paginated_post('job.list', payload)
end

.create(payload) ⇒ Object

Raises:



47
48
49
50
51
52
53
# File 'lib/ashby/jobs.rb', line 47

def self.create(payload)
  required_fields = i[title teamId locationId]
  missing = required_fields.select { |f| payload[f].to_s.strip.empty? }
  raise ArgumentError, "Missing required fields: #{missing.join(', ')}" if missing.any?

  post('job.create', payload)['results']
end

.find(id, expand: '') ⇒ Object

Finds a job by its Ashby ID

Raises:



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

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

  payload = {
    id: id,
    expand: expand.strip.empty? ? [] : [expand]
  }
  post('job.info', payload)['results']
end

.search(req_id: nil, title: nil) ⇒ Object

Searches for jobs based on requisition ID or title

Raises:



32
33
34
35
36
37
38
39
40
# File 'lib/ashby/jobs.rb', line 32

def self.search(req_id: nil, title: nil)
  payload = {}
  payload[:requisitionId] = req_id.to_s if req_id
  payload[:title] = title if title

  raise ArgumentError, 'You must provide at least a job title or a requisition id' if payload.empty?

  post('job.search', payload)['results']
end

.set_status(job_id:, status:) ⇒ Object

Raises:



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ashby/jobs.rb', line 62

def self.set_status(job_id:, status:)
  valid_statuses = %w[Draft Open Closed Archived]
  raise ArgumentError, 'Job ID is required' if job_id.to_s.strip.empty?
  raise ArgumentError, "Invalid status: #{status}" unless valid_statuses.include?(status)

  payload = {
    jobId: job_id,
    status: status
  }

  post('job.setStatus', payload)['results']
end

.templatesObject

Fetches all job templates



43
44
45
# File 'lib/ashby/jobs.rb', line 43

def self.templates
  paginated_post('jobTemplate.list')
end

.update(id: nil, payload: {}) ⇒ Object

Raises:



55
56
57
58
59
60
# File 'lib/ashby/jobs.rb', line 55

def self.update(id: nil, payload: {})
  raise ArgumentError, 'You must provide a job id' if id.nil?

  payload[:jobId] = id
  post('job.update', payload)['results']
end