Class: Ashby::Jobs
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
Class Method Summary collapse
-
.all(payload = {}) ⇒ Object
Fetches all jobs with pagination support.
- .create(payload) ⇒ Object
-
.find(id, expand: '') ⇒ Object
Finds a job by its Ashby ID.
-
.search(req_id: nil, title: nil) ⇒ Object
Searches for jobs based on requisition ID or title.
- .set_status(job_id:, status:) ⇒ Object
-
.templates ⇒ Object
Fetches all job templates.
- .update(id: nil, payload: {}) ⇒ Object
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
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
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: .strip.empty? ? [] : [] } post('job.info', payload)['results'] end |
.search(req_id: nil, title: nil) ⇒ Object
Searches for jobs based on requisition ID or title
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
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 |
.templates ⇒ Object
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
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 |