Skip to content

Commit fa5153e

Browse files
committed
Merge pull request #5 from JobBrander/adding_params
Adding params
2 parents 4a73378 + f82d37d commit fa5153e

File tree

6 files changed

+129
-48
lines changed

6 files changed

+129
-48
lines changed

.travis.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ php:
99
before_script:
1010
- travis_retry composer self-update
1111
- travis_retry composer install --no-interaction --prefer-source --dev
12-
- travis_retry pyrus install pear/PHP_CodeSniffer
1312
- travis_retry phpenv rehash
1413

1514
script:
16-
- phpcs --standard=psr2 src/
17-
- phpunit --coverage-text --coverage-clover=coverage.clover
15+
- ./vendor/bin/phpcs --standard=psr2 src/
16+
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
1817

1918
after_script:
20-
- wget https://scrutinizer-ci.com/ocular.phar
21-
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
22-
23-
matrix:
24-
allow_failures:
25-
- php: 7.0
26-
- php: hhvm
19+
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
20+
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# Changelog
22
All Notable changes to `jobs-govt` will be documented in this file
33

4+
## 0.6.0 - 2015-09-28
5+
6+
### Added
7+
- Support for all setter methods outlined in the [Government Jobs API](http://search.digitalgov.gov/developer/jobs.html)
8+
- Readme documentation for all supported methods
9+
10+
### Deprecated
11+
- Nothing
12+
13+
### Fixed
14+
- Nothing
15+
16+
### Removed
17+
- Nothing
18+
19+
### Security
20+
- Nothing
21+
422
## 0.5.0 - 2015-08-14
523

624
### Added

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ as the provider.
2727
$client = new JobBrander\Jobs\Client\Provider\Govt();
2828

2929
// Search for 200 job listings for 'project manager' in Chicago, IL
30-
$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.
31-
->setCount(100) // Specifies how many results are returned (up to 100 at a time)
32-
->setFrom(10) // Specifies the starting record
30+
$jobs = $client
31+
// API parameters
32+
->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.
33+
->setOrganizationIds() // A comma-separated string specifying which federal, state, or local agencies to use as a filter.
34+
->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.
35+
->setSize() // Specifies how many results are returned (up to 100 at a time).
36+
->setFrom() // Specifies the starting record.
37+
->setTags() // A comma-separated string specifying the level of government. Current tags are federal, state, county, and city.
38+
->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.
39+
// Jobbrander parameters
40+
->setKeyword('project manager') // See "setQuery()" method above
41+
->setCount(100) // See "setSize()" method above
3342
->getJobs();
3443
```
3544

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
"jobbrander/jobs-common": "~1.0.3"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "3.7.*",
30+
"phpunit/phpunit": ">=4.6",
3131
"phpunit/php-code-coverage": "~2.0",
32-
"mockery/mockery": ">=0.9.4"
32+
"mockery/mockery": ">=0.9.4",
33+
"squizlabs/php_codesniffer": "~2.0"
3334
},
3435
"autoload": {
3536
"psr-4": {

src/Govt.php

Lines changed: 88 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,65 @@
55

66
class Govt extends AbstractProvider
77
{
8+
/**
9+
* Map of setter methods to query parameters
10+
*
11+
* @var array
12+
*/
13+
protected $queryMap = [
14+
'setCount' => 'size',
15+
'setFrom' => 'from',
16+
'setHl' => 'hl',
17+
'setKeyword' => 'query',
18+
'setLatLon' => 'lat_lon',
19+
'setOrganizationIds' => 'organization_ids',
20+
'setQuery' => 'query',
21+
'setSize' => 'size',
22+
'setTags' => 'tags',
23+
];
24+
25+
/**
26+
* Current api query parameters
27+
*
28+
* @var array
29+
*/
30+
protected $queryParams = [
31+
'from' => null,
32+
'hl' => null,
33+
'lat_lon' => null,
34+
'organization_ids' => null,
35+
'query' => null,
36+
'size' => null,
37+
'tags' => null,
38+
];
39+
40+
/**
41+
* Create new Govt jobs client.
42+
*
43+
* @param array $parameters
44+
*/
45+
public function __construct($parameters = [])
46+
{
47+
parent::__construct($parameters);
48+
array_walk($parameters, [$this, 'updateQuery']);
49+
}
50+
51+
/**
52+
* Magic method to handle get and set methods for properties
53+
*
54+
* @param string $method
55+
* @param array $parameters
56+
*
57+
* @return mixed
58+
*/
59+
public function __call($method, $parameters)
60+
{
61+
if (isset($this->queryMap[$method], $parameters[0])) {
62+
$this->updateQuery($parameters[0], $this->queryMap[$method]);
63+
}
64+
return parent::__call($method, $parameters);
65+
}
66+
867
/**
968
* Returns the standardized job object
1069
*
@@ -103,12 +162,20 @@ public function getFormat()
103162
}
104163

105164
/**
106-
* Get listings path
165+
* Get page
107166
*
108167
* @return string
109168
*/
110-
public function getListingsPath()
169+
public function getFrom()
111170
{
171+
if ($this->page) {
172+
$from = ($this->page - 1) * $this->count;
173+
174+
if ($from) {
175+
return $from;
176+
}
177+
}
178+
112179
return null;
113180
}
114181

@@ -129,20 +196,12 @@ public function getKeyword()
129196
}
130197

131198
/**
132-
* Get page
199+
* Get listings path
133200
*
134201
* @return string
135202
*/
136-
public function getFrom()
203+
public function getListingsPath()
137204
{
138-
if ($this->page) {
139-
$from = ($this->page - 1) * $this->count;
140-
141-
if ($from) {
142-
return $from;
143-
}
144-
}
145-
146205
return null;
147206
}
148207

@@ -153,22 +212,7 @@ public function getFrom()
153212
*/
154213
public function getQueryString()
155214
{
156-
$query_params = [
157-
'query' => 'getKeyword',
158-
'from' => 'getFrom',
159-
'size' => 'getCount',
160-
];
161-
162-
$query_string = [];
163-
164-
array_walk($query_params, function ($value, $key) use (&$query_string) {
165-
$computed_value = $this->$value();
166-
if (!is_null($computed_value)) {
167-
$query_string[$key] = $computed_value;
168-
}
169-
});
170-
171-
return http_build_query($query_string);
215+
return http_build_query($this->queryParams);
172216
}
173217

174218
/**
@@ -191,4 +235,20 @@ public function getVerb()
191235
{
192236
return 'GET';
193237
}
238+
239+
/**
240+
* Attempts to update current query parameters.
241+
*
242+
* @param string $value
243+
* @param string $key
244+
*
245+
* @return Careerbuilder
246+
*/
247+
protected function updateQuery($value, $key)
248+
{
249+
if (array_key_exists($key, $this->queryParams)) {
250+
$this->queryParams[$key] = $value;
251+
}
252+
return $this;
253+
}
194254
}

tests/src/GovtTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ public function testUrlNotIncludesSizeWhenNotProvided()
8484

8585
public function testUrlIncludesFromWhenProvided()
8686
{
87-
$page = rand(5, 15);
88-
$count = rand(10, 100);
89-
$param = 'from='.(($page - 1) * $count);
87+
$from = rand(10, 100);
88+
$param = 'from='.$from;
9089

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

9392
$this->assertContains($param, $url);
9493
}
@@ -97,7 +96,7 @@ public function testUrlNotIncludesFromWhenNotProvided()
9796
{
9897
$param = 'from=';
9998

100-
$url = $this->client->setPage(null)->getUrl();
99+
$url = $this->client->setFrom(null)->getUrl();
101100

102101
$this->assertNotContains($param, $url);
103102
}

0 commit comments

Comments
 (0)