Back

Step by Step Guide to Building a Recruitee API Integration in Ruby

Aug 17, 20245 minute read

Introduction

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.

Prerequisites

Before we jump in, make sure you've got:

  • Ruby 2.7+ (because who doesn't love the latest and greatest?)
  • Your favorite HTTP client gem (we'll use httparty in this guide)
  • Recruitee API credentials (grab 'em from your account settings)

Setting up the project

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!

Authentication

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!

Basic API Requests

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

Handling Responses

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

Advanced Features

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

Building a Wrapper Class

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

Testing

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

Best Practices

  • Respect rate limits: Recruitee's not shy about throttling overeager clients.
  • Cache when you can: Your database is your friend for frequently accessed data.

Conclusion

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!