Skip to content

Commit

Permalink
Merge pull request #4 from JobBrander/adding_params
Browse files Browse the repository at this point in the history
Adding params supported by dice api
  • Loading branch information
karllhughes committed Sep 28, 2015
2 parents 9fcd537 + ac25607 commit e6502fe
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 34 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ php:
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source --dev
- travis_retry pyrus install pear/PHP_CodeSniffer
- travis_retry phpenv rehash

script:
- phpcs --standard=psr2 src/
- phpunit --coverage-text --coverage-clover=coverage.clover
- ./vendor/bin/phpcs --standard=psr2 src/
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

matrix:
allow_failures:
- php: 7.0
- php: hhvm
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Changelog
All Notable changes to `jobs-dice` will be documented in this file

## 0.3.0 - 2015-09-28

### Added
- Support for all setter methods outlined in the [Dice API](http://www.dice.com/common/content/util/apidoc/jobsearch.html)
- Readme documentation for all supported methods

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing

## 0.2.4 - 2015-08-12

### Added
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ Usage is the same as Job Branders's Jobs Client, using `\JobBrander\Jobs\Client\
```php
$client = new JobBrander\Jobs\Client\Provider\Dice();

// Search for 200 job listings for 'project manager' in Chicago, IL
$jobs = $client->setKeyword('project manager') // The search text/keywords for the jobs entire body
->setCity('Chicago') // The job's United States Post Office ZipCode of the city is the center with a 40 mile search radius
->setState('IL') // Specify the job's United States Post Office state code
$jobs = $client
// API parameters
->setDirect() // (optional) if the value of this parameter is "1" then jobs returned will be direct hire
->setAreacode() // (optional) specify the jobs area code
->setCountry() // (optional) specify the jobs ISO 3166 country code
->setState() // (optional) specify the jobs United States Post Office state code
->setSkill() // (optional) specify search text for the jobs skill property
->setCity() // (optional) specify the jobs United States Post Office ZipCode as the center of 40 mile radius
->setText() // (optional) specify search text for the jobs entire body
->setIp() // (optional) specify an IP address that will be used to look up a geocode which will be used in the search
->setAge() // (optional) specify a posting age (a.k.a. days back)
->setDiceid() // (optional) specify a Dice customer ID to find only jobs from that company
->setPage() // (optional) specify a page number of the results to be displayed (1 based)
->setPgcnt() // (optional) specify the number of results per page
->setSort() // (optional) specify a sort paremeter; sort=1 sorts by posted age, sort=2 sorts by job title, sort=3 sorts by company, sort=4 sorts by location
->setSd() // (optional) sort direction; sd=a sort order is ASCENDING sd=d sort order is DESCENDING
// JobBrander parameters
->setKeyword('project manager') // The search text/keywords for the jobs entire body
->setCount(200) // Specify the number of results per page
->getJobs();
```
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"jobbrander/jobs-common": "~1.0.3"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"phpunit/phpunit": ">=4.6",
"phpunit/php-code-coverage": "~2.0",
"mockery/mockery": ">=0.9.4"
"mockery/mockery": ">=0.9.4",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": {
Expand Down
108 changes: 90 additions & 18 deletions src/Dice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,79 @@

class Dice extends AbstractProvider
{
/**
* Map of setter methods to query parameters
*
* @var array
*/
protected $queryMap = [
'setAge' => 'age',
'setAreacode' => 'areacode',
'setCity' => 'city',
'setCount' => 'pgcnt',
'setCountry' => 'country',
'setDiceid' => 'diceid',
'setDirect' => 'direct',
'setIp' => 'ip',
'setKeyword' => 'text',
'setPage' => 'page',
'setPgcnt' => 'pgcnt',
'setSd' => 'sd',
'setSkill' => 'skill',
'setSort' => 'sort',
'setState' => 'state',
'setText' => 'text',
];

/**
* Current api query parameters
*
* @var array
*/
protected $queryParams = [
'age' => null,
'areacode' => null,
'city' => null,
'country' => null,
'diceid' => null,
'direct' => null,
'ip' => null,
'page' => null,
'pgcnt' => null,
'sd' => null,
'skill' => null,
'sort' => null,
'state' => null,
'text' => null,
];

/**
* Create new Dice jobs client.
*
* @param array $parameters
*/
public function __construct($parameters = [])
{
parent::__construct($parameters);
array_walk($parameters, [$this, 'updateQuery']);
}

/**
* Magic method to handle get and set methods for properties
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
if (isset($this->queryMap[$method], $parameters[0])) {
$this->updateQuery($parameters[0], $this->queryMap[$method]);
}
return parent::__call($method, $parameters);
}

/**
* Returns the standardized job object
*
Expand Down Expand Up @@ -72,24 +145,7 @@ public function getListingsPath()
*/
public function getQueryString()
{
$query_params = [
'text' => 'getKeyword',
'state' => 'getState',
'city' => 'getCity',
'page' => 'getPage',
'pgcnt' => 'getCount',
];

$query_string = [];

array_walk($query_params, function ($value, $key) use (&$query_string) {
$computed_value = $this->$value();
if (!is_null($computed_value)) {
$query_string[$key] = $computed_value;
}
});

return http_build_query($query_string);
return http_build_query($this->queryParams);
}

/**
Expand All @@ -113,4 +169,20 @@ public function getVerb()
{
return 'GET';
}

/**
* Attempts to update current query parameters.
*
* @param string $value
* @param string $key
*
* @return Careerbuilder
*/
protected function updateQuery($value, $key)
{
if (array_key_exists($key, $this->queryParams)) {
$this->queryParams[$key] = $value;
}
return $this;
}
}

0 comments on commit e6502fe

Please sign in to comment.