Class: PeopleGroup::Connectors::Greenhouse
- Inherits:
-
Object
- Object
- PeopleGroup::Connectors::Greenhouse
- 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
-
#add_sync_note_to_candidate(candidate_id) ⇒ Boolean
Add a note to the candidates profile in Greenhouse.
-
#application(application_id) ⇒ Hash
Find an application by id.
-
#candidate(candidate_id) ⇒ Hash
Search for a canidate by their candidate id.
-
#candidates(id = nil, options = {}) ⇒ Array<Hash>
List candidates by the specified options.
-
#current_offer_for_application(application_id) ⇒ Hash
Get the current offer of an application.
-
#has_active_application?(work_email) ⇒ Boolean
Check if the individual has any active applications.
-
#hired_candidates(updated_since) ⇒ Array<Hash>
Check for hired candidates based on when they have been updated.
-
#initialize(use_users_api_key: false) ⇒ PeopleGroup::Connectors::Greenhouse
constructor
Create a new Greenhouse client instance.
- #jobs(id = nil, options = {}) ⇒ Object
-
#offer_for_application(application_id) ⇒ Array<Hash>
(also: #offers_for_application)
List all offers for an application.
- #scorecards(id = nil, options = {}) ⇒ Array<Hash>
-
#users ⇒ Array<Hash>
Paginate through a list of users in Greenhouse.
Constructor Details
#initialize(use_users_api_key: false) ⇒ PeopleGroup::Connectors::Greenhouse
Create a new Greenhouse client instance.
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.
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.
166 167 168 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 166 def application(application_id) retry_on_error { @client.applications(application_id) } end |
#candidate(candidate_id) ⇒ Hash
Search for a canidate by their candidate id.
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.
107 108 109 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 107 def candidates(id = nil, = {}) retry_on_error { @client.candidates(id, ) } end |
#current_offer_for_application(application_id) ⇒ Hash
Get the current offer of an application.
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.
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 173 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.
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 |
#jobs(id = nil, options = {}) ⇒ Object
155 156 157 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 155 def jobs(id = nil, = {}) retry_on_error { @client.jobs(id, ) } end |
#offer_for_application(application_id) ⇒ Array<Hash> Also known as: offers_for_application
List all offers for an application.
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 |
#scorecards(id = nil, options = {}) ⇒ Array<Hash>
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 120 def scorecards(id = nil, = {}) [:skip_count] ||= true [:page] ||= 1 scorecards = [] loop do results = retry_on_error { @client.all_scorecards(id, **) } break if results.empty? scorecards += results [:page] += 1 end scorecards end |
#users ⇒ Array<Hash>
Paginate through a list of users in Greenhouse.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 139 def users page = 1 users = [] loop do results = @client.users(nil, page: page) break if results.empty? users += results page += 1 end users end |