Class: Ashby::Candidates

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

Overview

Ashby::Candidates provides access to candidate-related functionality in the Ashby API.

Includes support for:

- Fetching all candidates (with pagination)
- Searching by email or name
- Looking up by ID
- Adding notes to candidate profiles in plain text or HTML

Example:

Ashby::Candidates.all
Ashby::Candidates.find(email: '[email protected]')
Ashby::Candidates.find_by_id(id: 'cand_abc123')

client = Ashby::Candidates.new
client.create_candidate_note('cand_abc123', 'Reached out via email.')
client.create_formatted_candidate_note('cand_abc123', title: 'Initial Contact',
content: 'Spoke with Jane over Zoom.')

Constant Summary

Constants inherited from Client

Ashby::Client::API_URL

Class Method Summary collapse

Methods inherited from Client

build_url, headers, paginated_post, post

Class Method Details

.allObject

Fetches all candidates with pagination support



24
25
26
# File 'lib/ashby/candidates.rb', line 24

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

.create_candidate_note(candidate_id, note_content, send_notifications: false) ⇒ Object

Creates a note on a candidates profile



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ashby/candidates.rb', line 50

def self.create_candidate_note(candidate_id, note_content, send_notifications: false)
  payload = {
    candidateId: candidate_id,
    note: note_content,
    sendNotifications: send_notifications
  }

  response = post('candidate.createNote', payload)
  raise "Failed to create note: #{response['error']}" unless response['success']

  response['results']
end

.find(email: nil, name: nil) ⇒ Object

Finds a candidate by their email or name

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
# File 'lib/ashby/candidates.rb', line 29

def self.find(email: nil, name: nil)
  payload = {}
  payload[:email] = email if email
  payload[:name] = name if name

  raise ArgumentError, 'You must provide at least an email or a name' if payload.empty?

  response = post('candidate.search', payload)
  response['results']
end

.find_by_id(id: nil) ⇒ Object

Finds a candidate by their Ashby ID

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/ashby/candidates.rb', line 41

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

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