class PeopleGroup::Connectors::Greenhouse

Constants

MAX_RETRIES

Public Class Methods

new(use_users_api_key: false) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 10
def initialize(use_users_api_key: false)
  api_key = use_users_api_key ? ENV['GREENHOUSE_API_KEY_USERS'] : ENV['GREENHOUSE_API_KEY']
  @client = GreenhouseIo::Client.new(api_key)
end

Public Instance Methods

add_sync_note_to_candidate(candidate_id) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 49
def add_sync_note_to_candidate(candidate_id)
  note = {
    user_id: ENV['GREENHOUSE_AUTHOR_ID'],
    body: "This person was synced at #{Time.now} by the Employee Bot",
    visibility: 'public'
  }
  @client.create_candidate_note(candidate_id, note, ENV['GREENHOUSE_AUTHOR_ID'])
end
application(application_id) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 73
def application(application_id)
  @client.applications(application_id)
end
candidate(candidate_id) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 45
def candidate(candidate_id)
  @client.candidates(candidate_id)
end
current_offer_for_application(application_id) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 19
def current_offer_for_application(application_id)
  @client.current_offer_for_application(application_id)
end
hired_candidates(updated_since) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 23
def hired_candidates(updated_since)
  page = 1
  candidates = []
  on_error = -> { p [updated_since, page] }

  loop do
    results = Utils.retry_on_error(errors: [GreenhouseIo::Error], on_error: on_error) do
      @client.candidates(nil, updated_after: updated_since, page: page)
    end

    break if results.empty?

    results.each do |candidate|
      candidates << candidate if hired_non_active?(candidate)
    end

    page += 1
  end

  candidates
end
offer_for_application(application_id) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 15
def offer_for_application(application_id)
  @client.offers_for_application(application_id)
end
users() click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 58
def users
  page = 1
  users = []

  loop do
    results = @client.users(nil, page: page)
    break if results.empty?

    users += results
    page += 1
  end

  users
end

Private Instance Methods

hired_non_active?(candidate) click to toggle source
# File lib/peoplegroup/connectors/greenhouse.rb, line 79
def hired_non_active?(candidate)
  # If the candidate has any application that is active, we don't sync.
  return false if candidate['applications'].any? { |application| application['status'] == 'active' }

  # Check if candidate is hired for at least one of their applications
  candidate['applications'].any? { |application| application['status'] == 'hired' }
end