Hey there, fellow code wrangler! Ready to supercharge your recruitment process with some Ruby magic? Let's dive into building a Recruitee API integration that'll make your HR team love you. Recruitee's API is a powerhouse for managing candidates, job postings, and more. We'll get you up and running in no time.
Before we jump in, make sure you've got:
httparty
in this guide)Let's kick things off:
mkdir recruitee_integration cd recruitee_integration bundle init
Now, crack open that Gemfile and add:
gem 'httparty'
Run bundle install
, and we're off to the races!
Recruitee uses API tokens for authentication. It's simple stuff:
require 'httparty' class RecruiteeClient include HTTParty base_uri 'https://api.recruitee.com/c/YOUR_COMPANY_ID' def initialize(api_token) @options = { headers: { 'Authorization' => "Bearer #{api_token}" } } end end
Replace YOUR_COMPANY_ID
with your actual company ID. Easy peasy!
Let's fetch some candidates:
def get_candidates self.class.get('/candidates', @options) end
Creating a candidate? No sweat:
def create_candidate(data) self.class.post('/candidates', @options.merge(body: data.to_json)) end
Recruitee speaks JSON. Let's listen:
response = get_candidates if response.success? candidates = JSON.parse(response.body) # Do something awesome with your candidates else puts "Oops! #{response.code}: #{response.message}" end
Pagination? We got you:
def get_all_candidates page = 1 all_candidates = [] loop do response = self.class.get('/candidates', @options.merge(query: { page: page })) break unless response.success? candidates = JSON.parse(response.body) break if candidates.empty? all_candidates.concat(candidates) page += 1 end all_candidates end
Let's put it all together:
class RecruiteeClient include HTTParty base_uri 'https://api.recruitee.com/c/YOUR_COMPANY_ID' def initialize(api_token) @options = { headers: { 'Authorization' => "Bearer #{api_token}" } } end def get_candidates self.class.get('/candidates', @options) end def create_candidate(data) self.class.post('/candidates', @options.merge(body: data.to_json)) end # Add more methods as needed end
Don't forget to test! Here's a quick RSpec example:
require 'rspec' require_relative 'recruitee_client' RSpec.describe RecruiteeClient do let(:client) { RecruiteeClient.new('your_api_token') } it 'fetches candidates successfully' do response = client.get_candidates expect(response.code).to eq(200) end # Add more tests as needed end
And there you have it! You're now armed with a slick Recruitee API integration. Remember, this is just the beginning – there's a whole world of recruitment automation waiting for you. Happy coding, and may your candidate pipeline always be full!
Need more? Check out the Recruitee API docs for the full scoop. Now go forth and recruit like a boss!