Class: PeopleGroup::Connectors::Greenhouse

Inherits:
Object
  • Object
show all
Defined in:
lib/peoplegroup/connectors/greenhouse.rb

Constant Summary collapse

MAX_RETRIES =

Maximum amount of retries for requests.

3
RETRY_ERRORS =

Error to retry on.

[
  GreenhouseIo::Error,
  Net::OpenTimeout,
  RestClient::InternalServerError
].freeze
RETRY_DELAY =

Time to delay inbetween retries.

3

Instance Method Summary collapse

Constructor Details

#initialize(use_users_api_key: false) ⇒ PeopleGroup::Connectors::Greenhouse

Create a new Greenhouse client instance.

Examples:

client = PeopleGroup::Connectors::Greenhouse.new

Parameters:

  • use_users_api_key (Boolean) (defaults to: false)

    Whether to use the users API key or the default one.



26
27
28
29
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 26

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

Instance Method Details

#add_sync_note_to_candidate(candidate_id) ⇒ Boolean

Add a note to the candidates profile in Greenhouse.

Parameters:

  • candidate_id (String|Integer)

    the candidates ID that is being synced.

Returns:

  • (Boolean)

    whether or not the request was successful.



88
89
90
91
92
93
94
95
96
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 88

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'
  }

  retry_on_error { @client.create_candidate_note(candidate_id, note, ENV['GREENHOUSE_AUTHOR_ID']) }
end

#application(application_id) ⇒ Hash

Find an application by id.

Examples:

greenhouse = PeopleGroup::Connectors::Greenhouse.new
greenhouse.application(12345)

Parameters:

  • application_id (String|Integer)

    The ID of the application to fetch.

Returns:

  • (Hash)

    The application data.

See Also:



136
137
138
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 136

def application(application_id)
  retry_on_error { @client.applications(application_id) }
end

#candidate(candidate_id) ⇒ Hash

Search for a canidate by their candidate id.

Parameters:

  • candidate_id (String|Integer)

    the candidates id.

Returns:

  • (Hash)

    the candidates details.

See Also:



81
82
83
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 81

def candidate(candidate_id)
  retry_on_error { @client.candidates(candidate_id) }
end

#candidates(id = nil, options = {}) ⇒ Array<Hash>

List candidates by the specified options.

Examples:

greenhouse = PeopleGroup::Connectors::Greenhouse.new
greenhouse.candidates(nil, { email: '[email protected]' })
greenhouse.candiates(12345)

Parameters:

  • id (String|Integer) (defaults to: nil)

    The ID of the candidate to fetch.

  • options (Hash) (defaults to: {})

    The options to filter the candidates by.

Returns:

  • (Array<Hash>)

    candidates matching the specified filter.

See Also:



107
108
109
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 107

def candidates(id = nil, options = {})
  retry_on_error { @client.candidates(id, options) }
end

#current_offer_for_application(application_id) ⇒ Hash

Get the current offer of an application.

Examples:

client = PeopleGroup::Connectors::Greenhouse.new
client.current_offer_for_application(123)
#=> { "id" => 123, "status" => "accepted", "application_id" => 456, ... }

Parameters:

  • application_id (Integer|String)

    The id of the application to get the offer for.

Returns:

  • (Hash)

    The current offer for the application.

See Also:



48
49
50
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 48

def current_offer_for_application(application_id)
  @client.current_offer_for_application(application_id)
end

#has_active_application?(work_email) ⇒ Boolean

Check if the individual has any active applications.

Parameters:

  • work_email (String)

    the individuals email address.

Returns:

  • (Boolean)

    true if the individual has any active applications, false if not.



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 143

def has_active_application?(work_email)
  # Find the canidate by email.
  candidate = candidates(nil, { email: work_email })

  # Return false unless they could be found or have no applications.
  return false unless candidate && candidate['applications'].size.positive?

  # Check all applications for any with a status of 'active'
  candidate['applications'].any? { |application| application['status'] == 'active' }
rescue RestClient::NotFound
  false # return false if candidate could not be found
end

#hired_candidates(updated_since) ⇒ Array<Hash>

Check for hired candidates based on when they have been updated.

Parameters:

  • updated_since (String|DateTime)

    YYYY-MM-DD format with optional time stamp.

Returns:

  • (Array<Hash>)

    The hired candidates.

See Also:

  • #hired_non_active


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 56

def hired_candidates(updated_since)
  page = 1
  candidates = []

  loop do
    results = Utils.retry_on_error(on_error: -> { p [updated_since, page] }) 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) ⇒ Array<Hash> Also known as: offers_for_application

List all offers for an application.

Parameters:

  • application_id (Integer|String)

    The id of the application to get the offers for.

Returns:

  • (Array<Hash>)

    The offers for the application.

See Also:



35
36
37
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 35

def offer_for_application(application_id)
  retry_on_error { @client.offers_for_application(application_id) }
end

#usersArray<Hash>

Paginate through a list of users in Greenhouse.

Returns:

  • (Array<Hash>)

    The users in Greenhouse.

See Also:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 114

def users
  page = 1
  users = []

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

    users += results
    page += 1
  end

  users
end