Skip to content

Commit

Permalink
Merge pull request #3 from JobBrander/setters
Browse files Browse the repository at this point in the history
Setters
  • Loading branch information
karllhughes committed Oct 12, 2015
2 parents f192344 + dd81c2b commit c3752a9
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 110 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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Changelog
All Notable changes to `jobs-juju` will be documented in this file

## 1.0.0 - 2015-10-10

### Added
- Support for all setter methods outlined in the [Juju API](http://www.juju.com/publisher/spec/)
- Readme documentation for all supported methods

### Deprecated
- Nothing

### Fixed
- Sorting methods alphabetically
- Travis-ci support for PHP 7.0 and HHVM

### Removed
- setCity and setState methods not supported by official API

### Security
- Nothing

## 0.1.1 - 2015-08-14

### Added
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,30 @@ Usage is the same as Job Branders's Jobs Client, using `\JobBrander\Jobs\Client\

```php
$client = new JobBrander\Jobs\Client\Provider\Juju([
'partnerId' => 'XXXXX',
'partnerid' => 'XXXXX',
]);

// Search for 200 job listings for 'project manager' in Chicago, IL
$jobs = $client->setKeyword('project manager') // The query. This is in the same format as a basic search. Try their search or advanced search for possible formats.
->setCity('Chicago') // Combined with state to form location. The location can be a state, county, city, or zip code. Using multiple locations in one query is not supported.
->setState('IL')
// Search for 20 job listings for 'project manager' in Chicago, IL
$jobs = $client
// Setter methods supported by JuJu API
->setPartnerid('') // (Required) Your assigned Publisher ID. This is given to you when signing up.
->setIpaddress('') // (Required) The IP Address of the end-user
->setUseragent('') // (Required) The User-Agent of the end-user
->setK('') // (K, L, or C Required)
->setL('') // (K, L, or C Required)
->setC('') // (K, L, or C Required)
->setR('') // The radius, in miles, around the search location. The default is 20 and the maximum is 100.
->setOrder('') // The order in which to return results. Choices are: relevance, date, distance. The default is relevance.
->setDays('') // The number of days back to search. Default is 90.
->setJpp('') // The number of jobs per page to return with each request. The maximum is 20, which is also the default.
->setPage('') // The page of results to return. Page numbers start at 1, the default.
->setChannel('') // The channel name used to track performance for multiple sites. See the section on channels.
->setHighlight('') // By default, results will be highlighted with HTML bolding. Set this flag to 0 to turn highlighting off.
->setStartindex('') // If you are using API results as backfill on one page of results, use this flag to 'skip' jobs from the top of further API results, because you've already shown them in backfill. The minimum (and default) is 1, which indicates that results should start on the first job. Simple paging should be implemented with the page and jpp parameters. If you are unsure, you probably want to use page and jpp.
->setSession('') // This parameter should be uniquely associated with a particular user. It can be an anonymized persistent or session cookie for web requests, or an anonymized contact id for email. Juju currently uses this internally for testing new algorithms. If you cannot or do not wish to provide this parameter, it's fine to omit it.
// Additional setter methods
->setKeyword('project manager') // The query. This is in the same format as a basic search. Try their search or advanced search for possible formats.
->setLocation('Chicago, IL')
->setCount(20) // The number of jobs per page to return with each request. The maximum is 20, which is also the default.
->getJobs();
```
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,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
156 changes: 89 additions & 67 deletions src/Juju.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,87 @@
class Juju extends AbstractProvider
{
/**
* Highlight
* Map of setter methods to query parameters
*
* @var string
* @var array
*/
protected $highlight;
protected $queryMap = [
'setPartnerid' => 'partnerid',
'setIpaddress' => 'ipaddress',
'setUseragent' => 'useragent',
'setK' => 'k',
'setL' => 'l',
'setC' => 'c',
'setR' => 'r',
'setOrder' => 'order',
'setDays' => 'days',
'setJpp' => 'jpp',
'setPage' => 'page',
'setChannel' => 'channel',
'setHighlight' => 'highlight',
'setStartindex' => 'startindex',
'setSession' => 'session',
'setKeyword' => 'k',
'setLocation' => 'l',
'setCount' => 'jpp',
];

/**
* Client IP Address
* Current api query parameters
*
* @var string
* @var array
*/
protected $ipAddress;
protected $queryParams = [
'partnerid' => null,
'ipaddress' => null,
'useragent' => null,
'k' => null,
'l' => null,
'c' => null,
'r' => null,
'order' => null,
'days' => null,
'jpp' => null,
'page' => null,
'channel' => null,
'highlight' => null,
'startindex' => null,
'session' => null,
];

/**
* Partner ID
* Create new J2c jobs client.
*
* @var string
* @param array $parameters
*/
protected $partnerId;
public function __construct($parameters = [])
{
parent::__construct($parameters);
array_walk($parameters, [$this, 'updateQuery']);
// Set default parameters
if (!isset($this->ipaddress)) {
$this->updateQuery($this->getIpAddress(), 'ipaddress');
}
if (!isset($this->useragent)) {
$this->updateQuery($this->getUserAgent(), 'useragent');
}
}

/**
* User Agent
* Magic method to handle get and set methods for properties
*
* @param string $method
* @param array $parameters
*
* @var string
* @return mixed
*/
protected $userAgent;
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 @@ -86,30 +141,6 @@ public function getFormat()
return 'xml';
}

/**
* Get listings path
*
* @return string
*/
public function getListingsPath()
{
return 'channel.item';
}

/**
* Get Highlight
*
* @return string
*/
public function getHighlight()
{
if (isset($this->highlight)) {
return $this->highlight;
} else {
return '0';
}
}

/**
* Get IP Address
*
Expand All @@ -125,19 +156,13 @@ public function getIpAddress()
}

/**
* Get combined location
* Get listings path
*
* @return string
* @return string
*/
public function getLocation()
public function getListingsPath()
{
$location = ($this->city ? $this->city.', ' : null).($this->state ?: null);

if ($location) {
return $location;
}

return null;
return 'channel.item';
}

/**
Expand All @@ -147,26 +172,7 @@ public function getLocation()
*/
public function getQueryString()
{
$query_params = [
'partnerid' => 'getPartnerId',
'ipaddress' => 'getIpAddress',
'useragent' => 'getUserAgent',
'k' => 'getKeyword',
'l' => 'getLocation',
'jpp' => 'getCount',
'page' => 'getPage',
'highlight' => 'getHighlight',
];

$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 @@ -178,7 +184,7 @@ public function getUrl()
{
$query_string = $this->getQueryString();

return 'http://api.juju.com/jobs'.$query_string;
return 'http://api.juju.com/jobs?'.$query_string;
}

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

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

0 comments on commit c3752a9

Please sign in to comment.