Skip to content

Commit

Permalink
Merge pull request #31 from grnhse/GREEN-25883_inclusion_urls
Browse files Browse the repository at this point in the history
Adds demographic inclusion urls
  • Loading branch information
tdphillipsjr authored Oct 7, 2020
2 parents 645a3c4 + 8e07022 commit c322c56
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ composer.phar
coverage
package.xml
*.tgz
.phpunit.result.cache

# You should be keeping these in a global gitignore, see for example
# https://help.github.com/articles/ignoring-files#global-gitignore
.DS_Store
.idea
.idea
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ This package of tools is provided by Greenhouse for customers who use PHP. Ther

# Requirements
1. PHP Version
a. 5.6 or greater for V1.
b. 7.3 or greater for V2.
- 5.6 or greater for V1.
- 7.3 or greater for V2.
2. [Composer](https://getcomposer.org/). You should be using Composer to manage this package.

Due to the EOL on PHP 5 and Guzzle 6, this package was upgraded to require PHP 7.3. We will no longer be supporting V1.
Due to the EOL on PHP 5 and Guzzle 6, this package was upgraded to require PHP 7.3. We will no longer be supporting V1. Going forward, new features will be added exclusively to the 2.0 branch. You should update to 2.0 as soon as reasonably possible.

# Installing
This is available on Packagist. Install via Composer. Add the following to your requirements:
Expand All @@ -22,6 +22,11 @@ This is available on Packagist. Install via Composer. Add the following to you
"grnhse/greenhouse-tools-php": "~2.0"
```

# New In 2.1
In order to support Greenhouse's new Inclusion URLs, we dropped a requirement that an $id be included for some URLs. Previously, a URL like `getActivityFeedForUser()` would throw a Greenhouse Exception with a message that id was required. Now, that method will just translate to `user/activity_feed` and return a 404 Not Found response. We did this in order to support Greenhouse's new Inclusion URLs. In the previous version `getQuestionsSetsForDemographics()`, [(found here)](https://developers.greenhouse.io/harvest.html#get-list-demographic-question-sets), would have thrown an "id required" exception instead of correctly routing to `demographics/question_sets`.

# New in 2.0
Support for PHP 5.6, 7.0, 7.1, and 7.2 were dropped in order to support the latest version of Guzzle.

# Greenhouse Service
The Greenhouse Service is a parent service that returns the other Greenhouse Services. By using this service, you have access to all the other services. The Greenhouse service takes an array that optionally includes your job board URL Token [(found here in Greenhouse)](https://app.greenhouse.io/configure/dev_center/config/) and your Job Board API Credentials [(found here in Greenhouse)](https://app.greenhouse.io/configure/dev_center/credentials). Create a Greenhouse Service object like this:
Expand Down Expand Up @@ -161,6 +166,17 @@ Some method calls and URLs do not fit this format, but the methods were named as
* `getTrackingLinks`: [Return a specific traking link for the supplied token.](https://developers.greenhouse.io/harvest.html#get-tracking-link-data-for-token): Note for this link, the token will be provided in the 'id' argument. `$harvestService->getTrackingLink(array('id' => '<token>'));`
* `patchEnableUser`: [Enable a disabled user from accessing Greenhouse.](https://developers.greenhouse.io/harvest.html#patch-enable-user)
* `patchDisableUser`: [Disable a user from accessing Greenhouse.](https://developers.greenhouse.io/harvest.html#patch-disable-user)
* `getQuestionSetsForDemographics`: [List all demographic question sets.](https://developers.greenhouse.io/harvest.html#get-list-demographic-question-sets)
* `getQuestionSetsForDemographics(['id' => 12345])`: [Fetch demographic question set with the id 12345](https://developers.greenhouse.io/harvest.html#get-retrieve-demographic-question-set)
* `getQuestionsForDemographics`: [List all demographic questions.](https://developers.greenhouse.io/harvest.html#get-list-demographic-questions)
* `getQuestionsForDemographics(['id' => 12345])`: [List demographic question with id 12345.](https://developers.greenhouse.io/harvest.html#get-retrieve-demographic-question)
* `getQuestionsForQuestionSetsForDemographics(['id' => 12345])`: [Fetch all demographic questions for question set with id 12345](https://developers.greenhouse.io/harvest.html#get-list-demographic-questions-for-demographic-question-set)
* `getAnswerOptionsForDemographics`: [List all demographic answer options.](https://developers.greenhouse.io/harvest.html#get-list-demographic-answer-options)
* `getAnswerOptionsForDemographics(['id' => 12345])`: [List demographic answer option with id 12345.](https://developers.greenhouse.io/harvest.html#get-retrieve-demographic-answer-option)
* `getAnswerOptionsForQuestionsForDemographics(['id' => 12345])`: [Fetch all answer option for demographic question with id 12345](https://developers.greenhouse.io/harvest.html#get-list-demographic-questions-for-demographic-question-set)
* `getAnswersForDemographics`: [List all demographic answers.](https://developers.greenhouse.io/harvest.html#get-list-demographic-answers)
* `getAnswersForDemographics(['id' => 12345])`: [List demographic answer with id 12345.](https://developers.greenhouse.io/harvest.html#get-retrieve-demographic-answer)
* `getDemographicAnswersForApplications(['id' => 12345])`: [List demographics answers for the application with id 12345](https://developers.greenhouse.io/harvest.html#get-list-demographic-answers-for-application)

You should use the parameters array to supply any URL parameters and headers required by the harvest methods. For any items that require a JSON body, this will also be supplied in the parameter array.

Expand Down
70 changes: 70 additions & 0 deletions src/Services/HarvestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,76 @@ public function deleteHiringTeamForJob($parameters=array())
$this->_trimUrlAndSendRequest();
}

public function getQuestionSetsForDemographics($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getQuestionSetsForDemographics', $parameters);
if (array_key_exists('id', $parameters) && $parameters['id']) {
$this->_harvest['url'] = 'demographics/question_sets/' . $parameters['id'];
} else {
$this->_harvest['url'] = 'demographics/question_sets';
}

return $this->sendRequest();
}

public function getQuestionsForQuestionSetsForDemographics($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getQuestionsForQuestionSetsForDemographics', $parameters);
$this->_harvest['url'] = 'demographics/question_sets/' . $parameters['id'] . '/questions';

return $this->sendRequest();
}

public function getAnswerOptionsForQuestionsForDemographics($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getAnswerOptionsForQuestionsForDemographics', $parameters);
$this->_harvest['url'] = 'demographics/questions/' . $parameters['id'] . '/answer_options';

return $this->sendRequest();
}

public function getQuestionsForDemographics($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getQuestionsForDemographics', $parameters);
if (array_key_exists('id', $parameters) && $parameters['id']) {
$this->_harvest['url'] = 'demographics/questions/' . $parameters['id'];
} else {
$this->_harvest['url'] = 'demographics/questions';
}

return $this->sendRequest();
}

public function getAnswerOptionsForDemographics($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getAnswerOptionsForDemographics', $parameters);
if (array_key_exists('id', $parameters) && $parameters['id']) {
$this->_harvest['url'] = 'demographics/answer_options/' . $parameters['id'];
} else {
$this->_harvest['url'] = 'demographics/answer_options';
}

return $this->sendRequest();
}

public function getAnswersForDemographics($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getAnswersForDemographics', $parameters);
if (array_key_exists('id', $parameters) && $parameters['id']) {
$this->_harvest['url'] = 'demographics/answers/' . $parameters['id'];
} else {
$this->_harvest['url'] = 'demographics/answers';
}

return $this->sendRequest();
}

public function getDemographicAnswersForApplications($parameters=array())
{
$this->_harvest = $this->_harvestHelper->parse('getDemographicsForAnswersForApplications', $parameters);
return $this->sendRequest();
}

private function _trimUrlAndSendRequest()
{
$this->_harvest['url'] = substr($this->_harvest['url'], 0, -1);
Expand Down
13 changes: 10 additions & 3 deletions src/Tools/HarvestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ public function methodToEndpoint($methodText, $parameters)

// Double object, expect the format object/id/object
} else if (sizeof($objects) == 2) {
if (!$id) throw new GreenhouseServiceException("Harvest Service: method call $methodText must include an id parameter");
$url = $this->_decamelizeAndPluralize($objects[1]) . "/$id/" . $this->_decamelizeAndPluralize($objects[0]);
$url = $this->_decamelizeAndPluralize($objects[1]) .
$this->_getDivider($id) .
$this->_decamelizeAndPluralize($objects[0]);
$url = $secondId ? $url . '/' . $secondId : $url;

// Triple object, expect the format object/id/object/object
} else if (sizeof($objects) == 3) {
if (!$id) throw new GreenhouseServiceException("Harvest Service: method call $methodText must include an id parameter");
$url = $this->_decamelizeAndPluralize($objects[2]) . "/$id/" .
$url = $this->_decamelizeAndPluralize($objects[2]) .
$this->_getDivider($id) .
$this->_decamelizeAndPluralize($objects[0]) . '/' .
$this->_decamelizeAndPluralize($objects[1]);
} else {
Expand All @@ -79,6 +81,11 @@ public function addQueryString($url, $parameters=array())
return $url;
}
}

private function _getDivider($id)
{
return $id ? "/$id/" : '/';
}

private function _decamelizeAndPluralize($string)
{
Expand Down
Loading

0 comments on commit c322c56

Please sign in to comment.