Created
August 16, 2017 15:29
-
-
Save finomayato/7f2ee8621d7afef21bb786e65ae6c19d to your computer and use it in GitHub Desktop.
Client for interaction with Greenhouse API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| GREENHOUSE_API_KEY = '<api_key>' | |
| greenhouse_client = None | |
| class GreenhouseClient: | |
| activity_feed_url = ('https://harvest.greenhouse.io/v1/candidates/' + | |
| '{id}/activity_feed') | |
| applications_url = 'https://harvest.greenhouse.io/v1/applications' | |
| application_by_id_url = ('https://harvest.greenhouse.io/v1/applications' + | |
| '/{id}') | |
| candidates_url = 'https://harvest.greenhouse.io/v1/candidates' | |
| candidate_by_id_url = 'https://harvest.greenhouse.io/v1/candidates/{id}' | |
| departments_url = 'https://harvest.greenhouse.io/v1/departments' | |
| department_by_id_url = 'https://harvest.greenhouse.io/v1/departments/{id}' | |
| eeoc_url = 'https://harvest.greenhouse.io/v1/eeoc' | |
| emails_url = 'https://harvest.greenhouse.io/v1/email_templates' | |
| job_posts_url = 'https://harvest.greenhouse.io/v1/job_posts' | |
| job_posts_for_job_url = ('https://harvest.greenhouse.io/v1/jobs/{id}/' + | |
| 'job_posts') | |
| job_stages_url = 'https://harvest.greenhouse.io/v1/job_stages' | |
| job_stages_for_job_url = ('https://harvest.greenhouse.io/v1/jobs/{id}/' + | |
| 'stages') | |
| jobs_url = 'https://harvest.greenhouse.io/v1/jobs' | |
| offers_url = 'https://harvest.greenhouse.io/v1/offers' | |
| offices_url = 'https://harvest.greenhouse.io/v1/offices' | |
| rejection_reasons_url = ('https://harvest.greenhouse.io/v1/' + | |
| 'rejection_reasons') | |
| interviews_url = 'https://harvest.greenhouse.io/v1/scheduled_interviews' | |
| scorecards_url = 'https://harvest.greenhouse.io/v1/scorecards' | |
| sources_url = 'https://harvest.greenhouse.io/v1/sources' | |
| candidate_tags_url = 'https://harvest.greenhouse.io/v1/tags/candidate' | |
| users_url = 'https://harvest.greenhouse.io/v1/users' | |
| user_roles_url = 'https://harvest.greenhouse.io/v1/user_roles' | |
| def __init__(self): | |
| self.auth = (GREENHOUSE_API_KEY, '') | |
| def _get(self, url): | |
| next_page_exists = True | |
| while next_page_exists: | |
| response = requests.get(url, auth=self.auth) | |
| next_page = response.links.get('next') | |
| if next_page is not None: | |
| url = response.links['next']['url'] | |
| else: | |
| next_page_exists = False | |
| yield response.json() | |
| def get_activity_feed(self): | |
| return self._get(self.activity_feed_url) | |
| def get_applications(self): | |
| return self._get(self.applications_url) | |
| def get_candidates(self): | |
| return self._get(self.candidates_url) | |
| def get_departments(self): | |
| return self._get(self.departments_url) | |
| def get_eeoc(self): | |
| return self._get(self.eeoc_url) | |
| def get_email_templates(self): | |
| return self._get(self.emails_url) | |
| def get_job_posts(self): | |
| return self._get(self.job_posts_url) | |
| def get_job_stages(self): | |
| return self._get(self.job_stages_url) | |
| def get_jobs(self): | |
| return self._get(self.jobs_url) | |
| def get_offers(self): | |
| return self._get(self.offers_url) | |
| def get_offices(self): | |
| return self._get(self.offices_url) | |
| def get_rejection_reasons(self): | |
| return self._get(self.rejection_reasons_url) | |
| def get_scheduled_interviews(self): | |
| return self._get(self.get_scheduled_interviews) | |
| def get_scorecards(self): | |
| return self._get(self.scorecards_url) | |
| def get_sources(self): | |
| return self._get(self.sources_url) | |
| def get_tags(self): | |
| return self._get(self.candidate_tags_url) | |
| def get_users(self): | |
| return self._get(self.users_url) | |
| def get_user_roles(self): | |
| return self._get(self.user_roles_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment