Skip to content

Commit

Permalink
Merge pull request #5 from JobBrander/adding_params
Browse files Browse the repository at this point in the history
Adding params
  • Loading branch information
karllhughes committed Sep 28, 2015
2 parents 4a73378 + f82d37d commit fa5153e
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 48 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-govt` will be documented in this file

## 0.6.0 - 2015-09-28

### Added
- Support for all setter methods outlined in the [Government Jobs API](http://search.digitalgov.gov/developer/jobs.html)
- Readme documentation for all supported methods

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing

## 0.5.0 - 2015-08-14

### Added
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ as the provider.
$client = new JobBrander\Jobs\Client\Provider\Govt();

// Search for 200 job listings for 'project manager' in Chicago, IL
$jobs = $client->setKeyword('project manager') // Attempts to extract as much "signal" as possible from the input text. Handles word variants, so a search on "nursing jobs" will find a job titled "nurse practitioner" and "RN." When parts of the query parameter are used to search against the position title, the results are ordered by relevance. When no query parameter is specified, they are ordered by date with the most recent listed first.
->setCount(100) // Specifies how many results are returned (up to 100 at a time)
->setFrom(10) // Specifies the starting record
$jobs = $client
// API parameters
->setQuery() // Attempts to extract as much "signal" as possible from the input text. Handles word variants, so a search on "nursing jobs" will find a job titled "nurse practitioner" and "RN." When parts of the query parameter are used to search against the position title, the results are ordered by relevance. When no query parameter is specified, they are ordered by date with the most recent listed first.
->setOrganizationIds() // A comma-separated string specifying which federal, state, or local agencies to use as a filter.
->setHl() // No highlighting is included by default. Use 'hl=1' to highlight terms in the position title that match terms in the user's search.
->setSize() // Specifies how many results are returned (up to 100 at a time).
->setFrom() // Specifies the starting record.
->setTags() // A comma-separated string specifying the level of government. Current tags are federal, state, county, and city.
->setLatLon() // Comma-separated pair denoting the position of the searcher looking for a job. For example, 'lat_lon=37.783333,-122.416667' is the value for San Francisco, CA.
// Jobbrander parameters
->setKeyword('project manager') // See "setQuery()" method above
->setCount(100) // See "setSize()" method above
->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
116 changes: 88 additions & 28 deletions src/Govt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,65 @@

class Govt extends AbstractProvider
{
/**
* Map of setter methods to query parameters
*
* @var array
*/
protected $queryMap = [
'setCount' => 'size',
'setFrom' => 'from',
'setHl' => 'hl',
'setKeyword' => 'query',
'setLatLon' => 'lat_lon',
'setOrganizationIds' => 'organization_ids',
'setQuery' => 'query',
'setSize' => 'size',
'setTags' => 'tags',
];

/**
* Current api query parameters
*
* @var array
*/
protected $queryParams = [
'from' => null,
'hl' => null,
'lat_lon' => null,
'organization_ids' => null,
'query' => null,
'size' => null,
'tags' => null,
];

/**
* Create new Govt 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 @@ -103,12 +162,20 @@ public function getFormat()
}

/**
* Get listings path
* Get page
*
* @return string
*/
public function getListingsPath()
public function getFrom()
{
if ($this->page) {
$from = ($this->page - 1) * $this->count;

if ($from) {
return $from;
}
}

return null;
}

Expand All @@ -129,20 +196,12 @@ public function getKeyword()
}

/**
* Get page
* Get listings path
*
* @return string
*/
public function getFrom()
public function getListingsPath()
{
if ($this->page) {
$from = ($this->page - 1) * $this->count;

if ($from) {
return $from;
}
}

return null;
}

Expand All @@ -153,22 +212,7 @@ public function getFrom()
*/
public function getQueryString()
{
$query_params = [
'query' => 'getKeyword',
'from' => 'getFrom',
'size' => '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 @@ -191,4 +235,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;
}
}
9 changes: 4 additions & 5 deletions tests/src/GovtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ public function testUrlNotIncludesSizeWhenNotProvided()

public function testUrlIncludesFromWhenProvided()
{
$page = rand(5, 15);
$count = rand(10, 100);
$param = 'from='.(($page - 1) * $count);
$from = rand(10, 100);
$param = 'from='.$from;

$url = $this->client->setPage($page)->setCount($count)->getUrl();
$url = $this->client->setFrom($from)->getUrl();

$this->assertContains($param, $url);
}
Expand All @@ -97,7 +96,7 @@ public function testUrlNotIncludesFromWhenNotProvided()
{
$param = 'from=';

$url = $this->client->setPage(null)->getUrl();
$url = $this->client->setFrom(null)->getUrl();

$this->assertNotContains($param, $url);
}
Expand Down

0 comments on commit fa5153e

Please sign in to comment.