Class: PeopleGroup::Connectors::Greenhouse
- Inherits:
-
Object
- Object
- PeopleGroup::Connectors::Greenhouse
- Defined in:
- lib/peoplegroup/connectors/greenhouse.rb
Constant Summary collapse
- MAX_RETRIES =
3
Instance Method Summary collapse
- #add_sync_note_to_candidate(candidate_id) ⇒ Object
- #application(application_id) ⇒ Object
- #candidate(candidate_id) ⇒ Object
- #candidates(id = nil, options = {}) ⇒ Object
- #current_offer_for_application(application_id) ⇒ Object
- #has_active_application?(work_email) ⇒ Boolean
- #hired_candidates(updated_since) ⇒ Object
-
#initialize(use_users_api_key: false) ⇒ Greenhouse
constructor
A new instance of Greenhouse.
- #offer_for_application(application_id) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(use_users_api_key: false) ⇒ Greenhouse
Returns a new instance of Greenhouse.
10 11 12 13 |
# 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 |
Instance Method Details
#add_sync_note_to_candidate(candidate_id) ⇒ Object
49 50 51 52 53 54 55 56 |
# 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) ⇒ Object
79 80 81 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 79 def application(application_id) @client.applications(application_id) end |
#candidate(candidate_id) ⇒ Object
45 46 47 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 45 def candidate(candidate_id) @client.candidates(candidate_id) end |
#candidates(id = nil, options = {}) ⇒ Object
58 59 60 61 62 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 58 def candidates(id = nil, = {}) Utils.retry_on_error(errors: [GreenhouseIo::Error, Net::OpenTimeout]) do @client.candidates(id, ) end end |
#current_offer_for_application(application_id) ⇒ Object
19 20 21 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 19 def current_offer_for_application(application_id) @client.current_offer_for_application(application_id) end |
#has_active_application?(work_email) ⇒ Boolean
83 84 85 86 87 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 83 def has_active_application?(work_email) candidates(nil, { email: work_email })&.[]('applications')&.any? { |application| application['status'] == 'active' } rescue RestClient::NotFound nil # return nil if candidate could not be found end |
#hired_candidates(updated_since) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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, RestClient::InternalServerError], 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) ⇒ Object
15 16 17 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 15 def offer_for_application(application_id) @client.offers_for_application(application_id) end |
#users ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/peoplegroup/connectors/greenhouse.rb', line 64 def users page = 1 users = [] loop do results = @client.users(nil, page: page) break if results.empty? users += results page += 1 end users end |