From 481c8aebe6088d926ef7a47801278c6f5273c6b6 Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 28 Sep 2015 16:57:47 -0500 Subject: [PATCH 1/3] Updating readme --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a789ed..9fccbda 100644 --- a/README.md +++ b/README.md @@ -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(); ``` From 6f4a56c46a687124f909182c52fc1b80490776df Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 28 Sep 2015 17:00:29 -0500 Subject: [PATCH 2/3] Updating composer and travis --- .travis.yml | 14 ++++---------- CHANGELOG.md | 18 ++++++++++++++++++ composer.json | 5 +++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3037852..f20c368 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index f86c59d..848e95b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 929a735..e585b32 100644 --- a/composer.json +++ b/composer.json @@ -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": { From f82d37dc7a1e72bccab06d7e0ead18f3df694e9a Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 28 Sep 2015 17:11:57 -0500 Subject: [PATCH 3/3] Refactoring, updating tests --- src/Govt.php | 116 +++++++++++++++++++++++++++++++---------- tests/src/GovtTest.php | 9 ++-- 2 files changed, 92 insertions(+), 33 deletions(-) diff --git a/src/Govt.php b/src/Govt.php index 4dcc594..6a8d3a5 100644 --- a/src/Govt.php +++ b/src/Govt.php @@ -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 * @@ -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; } @@ -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; } @@ -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); } /** @@ -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; + } } diff --git a/tests/src/GovtTest.php b/tests/src/GovtTest.php index abde217..8a7edb4 100644 --- a/tests/src/GovtTest.php +++ b/tests/src/GovtTest.php @@ -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); } @@ -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); }