From c0e0aa37081cbb761b3980f295f98024bd95e013 Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Fri, 6 Jan 2017 11:44:18 -0600 Subject: [PATCH 1/5] Updating readme, composer --- .gitignore | 1 + CHANGELOG.md | 8 ++++++++ CONTRIBUTING.md | 2 +- LICENSE.md | 2 +- README.md | 40 ++++++++++++++-------------------------- composer.json | 14 +++++++------- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 32efe4a..fef1e7b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ phpunit.xml composer.lock vendor +.idea diff --git a/CHANGELOG.md b/CHANGELOG.md index be558ad..d8969c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Changelog All Notable changes to `jobs-muse` will be documented in this file +## 1.0.0 - 2017-01-06 + +### Added +- Support for v.2.0 of jobs-common package + +### Removed +- Old set_() methods in provider, moved to Query + ## 0.2.0 - 2015-10-15 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 404c6e6..e6eac69 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Contributions are **welcome** and will be fully **credited**. -We accept contributions via Pull Requests on [Github](https://github.com/jobbrander/jobs-muse). +We accept contributions via Pull Requests on [Github](https://github.com/jobapis/jobs-muse). ## Pull Requests diff --git a/LICENSE.md b/LICENSE.md index e3580ed..c100ed5 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The Apache 2.0 License -Copyright 2015 Karl Hughes +Copyright 2017 Karl Hughes > Licensed under the Apache License, Version 2.0 (the "License"); > you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 9f326ac..3dbba1a 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,30 @@ -# Muse Jobs Client +# TheMuse.com Jobs Client -[![Latest Version](https://img.shields.io/github/release/JobBrander/jobs-muse.svg?style=flat-square)](https://github.com/JobBrander/jobs-muse/releases) +[![Latest Version](https://img.shields.io/github/release/jobapis/jobs-muse.svg?style=flat-square)](https://github.com/jobapis/jobs-muse/releases) [![Software License](https://img.shields.io/badge/license-APACHE%202.0-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/travis/JobBrander/jobs-muse/master.svg?style=flat-square&1)](https://travis-ci.org/JobBrander/jobs-muse) -[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/JobBrander/jobs-muse.svg?style=flat-square)](https://scrutinizer-ci.com/g/JobBrander/jobs-muse/code-structure) -[![Quality Score](https://img.shields.io/scrutinizer/g/JobBrander/jobs-muse.svg?style=flat-square)](https://scrutinizer-ci.com/g/JobBrander/jobs-muse) -[![Total Downloads](https://img.shields.io/packagist/dt/jobbrander/jobs-muse.svg?style=flat-square)](https://packagist.org/packages/jobbrander/jobs-muse) +[![Build Status](https://img.shields.io/travis/jobapis/jobs-muse/master.svg?style=flat-square&1)](https://travis-ci.org/jobapis/jobs-muse) +[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/jobapis/jobs-muse.svg?style=flat-square)](https://scrutinizer-ci.com/g/jobapis/jobs-muse/code-structure) +[![Quality Score](https://img.shields.io/scrutinizer/g/jobapis/jobs-muse.svg?style=flat-square)](https://scrutinizer-ci.com/g/jobapis/jobs-muse) +[![Total Downloads](https://img.shields.io/packagist/dt/jobapis/jobs-muse.svg?style=flat-square)](https://packagist.org/packages/jobapis/jobs-muse) This package provides [Muse Jobs API](https://www.themuse.com/developers#job-listing) -support for the JobBrander's [Jobs Client](https://github.com/JobBrander/jobs-common). +support for the JobApis's [Jobs Client](https://github.com/jobapis/jobs-common). ## Installation To install, use composer: ``` -composer require jobbrander/jobs-muse +composer require jobapis/jobs-muse ``` ## Usage -Usage is the same as Job Branders's Jobs Client, using `\JobBrander\Jobs\Client\Provider\Muse` as the provider. - -```php -$client = new JobBrander\Jobs\Client\Provider\Muse(); - -// Search for job listings in Chicago, IL -$jobs = $client - ->setLocation('Chicago, IL') // A location from the Muse's list of location strings: https://www.themuse.com/developers#job-listing - ->setCategory('Education') // A string that restricts search results to jobs in the specified category. A list of valid categories is in the Muse's documentation - ->setLevel('Internship') // A string that restricts search results to jobs in the specified experience level. A list of valid levels is in the Muse's documentation - ->setCompany('Facebook') // A string that restricts search results to jobs at the specified company. - ->setDescending(true) // The sort order of the results (ascending or descending). Valid values are: true, false; The default is true. - ->setPage(2) // The requested page of result sets, numbered beginning from 1. Default is 1. If this number exceeds the value of the response property totalPages, the response will contain zero results. - ->getJobs(); +``` +Coming soon. ``` -The `getJobs` method will return a [Collection](https://github.com/JobBrander/jobs-common/blob/master/src/Collection.php) of [Job](https://github.com/JobBrander/jobs-common/blob/master/src/Job.php) objects. +The `getJobs` method will return a [Collection](https://github.com/jobapis/jobs-common/blob/master/src/Collection.php) of [Job](https://github.com/jobapis/jobs-common/blob/master/src/Job.php) objects. ## Testing @@ -46,14 +34,14 @@ $ ./vendor/bin/phpunit ## Contributing -Please see [CONTRIBUTING](https://github.com/jobbrander/jobs-muse/blob/master/CONTRIBUTING.md) for details. +Please see [CONTRIBUTING](https://github.com/jobapis/jobs-muse/blob/master/CONTRIBUTING.md) for details. ## Credits - [Karl Hughes](https://github.com/karllhughes) -- [All Contributors](https://github.com/jobbrander/jobs-muse/contributors) +- [All Contributors](https://github.com/jobapis/jobs-muse/contributors) ## License -The Apache 2.0. Please see [License File](https://github.com/jobbrander/jobs-muse/blob/master/LICENSE) for more information. +The Apache 2.0. Please see [License File](https://github.com/jobapis/jobs-muse/blob/master/LICENSE) for more information. diff --git a/composer.json b/composer.json index 64127c5..6a3edad 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "jobbrander/jobs-muse", + "name": "jobapis/jobs-muse", "type": "library", - "description": "Making it simple to integrate your application with Muse Jobs API.", + "description": "Making it simple to integrate your application with the Muse's Jobs API.", "keywords": [ "jobs", "api client", @@ -9,7 +9,7 @@ "muse", "themuse.com" ], - "homepage": "https://github.com/JobBrander/jobs-muse", + "homepage": "https://github.com/jobapis/jobs-muse", "license": "Apache-2.0", "authors": [ { @@ -19,8 +19,8 @@ } ], "require": { - "php": ">=5.5.0", - "jobbrander/jobs-common": "~1.0.3" + "php": ">=5.6.0", + "jobapis/jobs-common": "^2.0.2" }, "require-dev": { "phpunit/phpunit": "3.7.*", @@ -29,12 +29,12 @@ }, "autoload": { "psr-4": { - "JobBrander\\Jobs\\Client\\Providers\\": "src/" + "JobApis\\Jobs\\Client\\Providers\\": "src/" } }, "autoload-dev": { "psr-4": { - "JobBrander\\Jobs\\Client\\Providers\\Test\\": "tests/src/" + "JobApis\\Jobs\\Client\\Providers\\Test\\": "tests/src/" } } } From 1f0ca734987b7de9f263ad6f28cd4713053a079a Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Fri, 6 Jan 2017 12:06:20 -0600 Subject: [PATCH 2/5] Adding new query --- CHANGELOG.md | 3 +- README.md | 2 +- composer.json | 9 +- src/{Muse.php => Providers/MuseProvider.php} | 38 +------ src/Queries/MuseQuery.php | 106 ++++++++++++++++++ .../{MuseTest.php => MuseProviderTest.php} | 6 +- tests/src/MuseQueryTest.php | 79 +++++++++++++ 7 files changed, 197 insertions(+), 46 deletions(-) rename src/{Muse.php => Providers/MuseProvider.php} (89%) create mode 100644 src/Queries/MuseQuery.php rename tests/src/{MuseTest.php => MuseProviderTest.php} (97%) create mode 100644 tests/src/MuseQueryTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d8969c4..89e56f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ All Notable changes to `jobs-muse` will be documented in this file ## 1.0.0 - 2017-01-06 ### Added -- Support for v.2.0 of jobs-common package +- Support for v.2.0 of jobs-common package. +- Support for v.2 of the Muse API. ### Removed - Old set_() methods in provider, moved to Query diff --git a/README.md b/README.md index 3dbba1a..29d73c3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Quality Score](https://img.shields.io/scrutinizer/g/jobapis/jobs-muse.svg?style=flat-square)](https://scrutinizer-ci.com/g/jobapis/jobs-muse) [![Total Downloads](https://img.shields.io/packagist/dt/jobapis/jobs-muse.svg?style=flat-square)](https://packagist.org/packages/jobapis/jobs-muse) -This package provides [Muse Jobs API](https://www.themuse.com/developers#job-listing) +This package provides [Muse Jobs API](https://www.themuse.com/developers) support for the JobApis's [Jobs Client](https://github.com/jobapis/jobs-common). ## Installation diff --git a/composer.json b/composer.json index 6a3edad..d2a32f2 100644 --- a/composer.json +++ b/composer.json @@ -23,18 +23,19 @@ "jobapis/jobs-common": "^2.0.2" }, "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": { - "JobApis\\Jobs\\Client\\Providers\\": "src/" + "JobApis\\Jobs\\Client\\": "src/" } }, "autoload-dev": { "psr-4": { - "JobApis\\Jobs\\Client\\Providers\\Test\\": "tests/src/" + "JobApis\\Jobs\\Client\\Test\\": "tests/src/" } } } diff --git a/src/Muse.php b/src/Providers/MuseProvider.php similarity index 89% rename from src/Muse.php rename to src/Providers/MuseProvider.php index bf9e7b3..d665d76 100644 --- a/src/Muse.php +++ b/src/Providers/MuseProvider.php @@ -3,43 +3,8 @@ use JobBrander\Jobs\Client\Job; use JobBrander\Jobs\Client\Collection; -class Muse extends AbstractProvider +class MuseProvider extends AbstractProvider { - /** - * Job Category - * - * @var string - */ - public $category; - - /** - * Company - * - * @var string - */ - public $company; - - /** - * Descending string ('true' or 'false') - * - * @var string - */ - public $descending; - - /** - * Job Level - * - * @var string - */ - public $level; - - /** - * Job Location - * - * @var string - */ - public $location; - /** * Returns the standardized job object * @@ -154,7 +119,6 @@ public function createJobArray($item) public function getCategory() { if (is_array($this->category)) { - // print_r($this->category); exit; } return $this->category; } diff --git a/src/Queries/MuseQuery.php b/src/Queries/MuseQuery.php new file mode 100644 index 0000000..bf496cd --- /dev/null +++ b/src/Queries/MuseQuery.php @@ -0,0 +1,106 @@ +category; + } + + /** + * Default parameters + * + * @var array + */ + protected function defaultAttributes() + { + return [ + 'page' => 1, + ]; + } +} diff --git a/tests/src/MuseTest.php b/tests/src/MuseProviderTest.php similarity index 97% rename from tests/src/MuseTest.php rename to tests/src/MuseProviderTest.php index 5ea6998..10ac6a5 100644 --- a/tests/src/MuseTest.php +++ b/tests/src/MuseProviderTest.php @@ -1,9 +1,9 @@ client = new Muse(); + $this->client = new MuseProvider(); } public function testItWillUseJsonFormat() diff --git a/tests/src/MuseQueryTest.php b/tests/src/MuseQueryTest.php new file mode 100644 index 0000000..7fc1721 --- /dev/null +++ b/tests/src/MuseQueryTest.php @@ -0,0 +1,79 @@ +query = new MuseQuery(); + } + + public function testItAddsDefaultAttributes() + { + $this->assertEquals('1', $this->query->get('page')); + } + + public function testItCanGetBaseUrl() + { + $this->assertEquals( + 'https://api-v2.themuse.com/jobs', + $this->query->getBaseUrl() + ); + } + + public function testItCanGetKeyword() + { + $keyword = uniqid(); + $this->query->set('category', $keyword); + $this->assertEquals($keyword, $this->query->getKeyword()); + } + + public function testItCanAddAttributesToUrl() + { + $keyword = uniqid(); + $this->query->set('category', $keyword); + $url = $this->query->getUrl(); + $this->assertContains('category=', $url); + $this->assertContains('page=', $url); + } + + /** + * @expectedException OutOfRangeException + */ + public function testItThrowsExceptionWhenSettingInvalidAttribute() + { + $this->query->set(uniqid(), uniqid()); + } + + /** + * @expectedException OutOfRangeException + */ + public function testItThrowsExceptionWhenGettingInvalidAttribute() + { + $this->query->get(uniqid()); + } + + public function testItSetsAndGetsValidAttributes() + { + $attributes = [ + 'api_key' => uniqid(), + 'company' => uniqid(), + 'location' => uniqid(), + ]; + + foreach ($attributes as $key => $value) { + $this->query->set($key, $value); + } + + foreach ($attributes as $key => $value) { + $this->assertEquals($value, $this->query->get($key)); + } + } +} From 8366a80a4af7ca4cc11aac188f7bed2617158d95 Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Fri, 6 Jan 2017 13:08:28 -0600 Subject: [PATCH 3/5] Updating provider/test --- src/Providers/MuseProvider.php | 212 +++++++++------------ tests/src/MuseProviderTest.php | 338 ++++++++++++--------------------- 2 files changed, 209 insertions(+), 341 deletions(-) diff --git a/src/Providers/MuseProvider.php b/src/Providers/MuseProvider.php index d665d76..97929b4 100644 --- a/src/Providers/MuseProvider.php +++ b/src/Providers/MuseProvider.php @@ -1,186 +1,144 @@ - $payload['title'], - 'name' => $payload['title'], - 'description' => $payload['full_description'], - 'url' => 'https://www.themuse.com'.$payload['apply_link'], + 'title' => $payload['name'], + 'name' => $payload['name'], + 'description' => $payload['contents'], + 'url' => $payload['refs']['landing_page'], 'sourceId' => $payload['id'], - 'location' => $payload['locations'], ]); - $job->setCompany($payload['company_name']) - ->setCompanyLogo($payload['company_f1_image']) - ->setDatePostedAsString($payload['creation_date']) - ->setOccupationalCategory($payload['categories']) - ->setExperienceRequirements($payload['level_displays']); + // categories array + $this->setCategories($job, $payload['categories']); + + // company array + $this->setCompany($job, $payload['company']); + + // levels array + $this->setLevels($job, $payload['levels']); + + // locations array + $this->setLocation($job, $payload['locations']); return $job; } /** - * Get descending results + * Job response object default keys that should be set * - * @return string + * @return string */ - public function getDescending() + public function getDefaultResponseFields() { - if (isset($this->descending)) { - return $this->descending; - } - return 'true'; + return [ + 'levels', // array + 'locations', // array + 'tags', // array + 'categories', // array + 'publication_date', + 'short_name', + 'refs', // array + 'contents', + 'type', + 'model_type', + 'company', // array + 'id', + 'name', + ]; } /** - * Get data format + * Get listings path * - * @return string + * @return string */ - public function getFormat() + public function getListingsPath() { - return 'json'; + return 'results'; } /** - * Create and get collection of jobs from given listings + * Sets the categories on the job using the categories array * - * @param array $listings + * @param Job $job + * @param array $categories * - * @return Collection + * @return MuseProvider */ - protected function getJobsCollectionFromListings(array $listings = array()) - { - $collection = new Collection; - array_map(function ($item) use ($collection) { - $jobs = $this->createJobArray($item); - foreach ($jobs as $item) { - $job = $this->createJobObject($item); - $job->setSource($this->getSource()); - $collection->add($job); - } - }, $listings); - return $collection; - } - - public function createJobArray($item) + protected function setCategories(Job $job, $categories = []) { - $jobs = []; - if (isset($item['locations']) && count($item['locations']) > 1) { - foreach ($item['locations'] as $location) { - $item['location'] = $location; - $jobs[] = $item; - } - } else { - $item['location'] = $item['locations'][0]; - $jobs[] = $item; + $occupationalCats = []; + foreach ($categories as $category) { + $occupationalCats[] = $category['name']; } - return $jobs; + if ($occupationalCats) { + $job->setOccupationalCategory(implode(', ', $occupationalCats)); + } + return $this; } /** - * Get category or categories + * Sets the company on the job using the company array + * + * @param Job $job + * @param array $company * - * @return string + * @return MuseProvider */ - public function getCategory() + protected function setCompany(Job $job, $company = []) { - if (is_array($this->category)) { + if ($company && isset($company['name'])) { + $job->setCompany($company['name']); } - return $this->category; + return $this; } /** - * Get listings path + * Sets the experience levels on the job using the levels array * - * @return string - */ - public function getListingsPath() - { - return 'results'; - } - - /** - * Get query string for client based on properties + * @param Job $job + * @param array $levels * - * @return string + * @return MuseProvider */ - public function getQueryString() + protected function setLevels(Job $job, $levels = []) { - $query_params = [ - 'descending' => 'getDescending', - 'page' => 'getPage', - 'job_category[]' => 'getCategory', - 'job_level[]' => 'getLevel', - 'job_location[]' => 'getLocation', - 'company[]' => 'getCompany', - ]; - - $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; - } - }); - - $query = http_build_query($query_string, null, '&'); - return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $query); + $requirements = []; + foreach ($levels as $level) { + $requirements[] = $level['name']; + } + if ($requirements) { + $job->setExperienceRequirements(implode(', ', $requirements)); + } + return $this; } /** - * Get url + * Sets the location on the job using the first location in the array * - * @return string - */ - public function getUrl() - { - $query_string = $this->getQueryString(); - - return 'https://api-v1.themuse.com/jobs?'.$query_string; - } - - /** - * Get http verb + * @param Job $job + * @param array $locations * - * @return string + * @return MuseProvider */ - public function getVerb() + protected function setLocation(Job $job, $locations = []) { - return 'GET'; + if (isset($locations[0]) && isset($locations[0]['name'])) { + $job->setLocation($locations[0]['name']); + } + return $this; } } diff --git a/tests/src/MuseProviderTest.php b/tests/src/MuseProviderTest.php index 10ac6a5..602e44f 100644 --- a/tests/src/MuseProviderTest.php +++ b/tests/src/MuseProviderTest.php @@ -1,263 +1,173 @@ -client = new MuseProvider(); - } - - public function testItWillUseJsonFormat() - { - $format = $this->client->getFormat(); - - $this->assertEquals('json', $format); - } - - public function testItWillUseGetHttpVerb() - { - $verb = $this->client->getVerb(); - - $this->assertEquals('GET', $verb); - } - - public function testListingPath() - { - $path = $this->client->getListingsPath(); - - $this->assertEquals('results', $path); - } - - public function testUrlIncludesPageWhenProvided() - { - $page = uniqid(); - $param = 'page='.$page; - - $url = $this->client->setPage($page)->getUrl(); - - $this->assertContains($param, $url); - } - - public function testUrlNotIncludesPageWhenNotProvided() - { - $param = 'page='; - - $url = $this->client->setPage(null)->getUrl(); - - $this->assertNotContains($param, $url); - } + $this->query = m::mock('JobApis\Jobs\Client\Queries\MuseQuery'); - public function testUrlIncludesDescendingWhenProvided() - { - $descending = uniqid(); - $param = 'descending='.$descending; - - $url = $this->client->setDescending($descending)->getUrl(); - - $this->assertContains($param, $url); - } - - public function testUrlIncludesDescendingWhenNotProvided() - { - $param = 'descending='; - - $url = $this->client->setDescending(null)->getUrl(); - - $this->assertContains($param, $url); + $this->client = new MuseProvider($this->query); } - public function testUrlIncludesCategoryWhenProvided() + public function testItCanGetDefaultResponseFields() { - $string = uniqid().' '.uniqid(); - $param = urlencode('job_category[]').'='.urlencode($string); - - $url = $this->client->setCategory($string)->getUrl(); - - $this->assertContains($param, $url); - } - - public function testUrlIncludesMultipleCategoriesWhenProvided() - { - $params = []; - $array = [ - 0 => uniqid().' '.uniqid(), - 1 => uniqid().' '.uniqid(), - 2 => uniqid().' '.uniqid(), + $fields = [ + 'levels', // array + 'locations', // array + 'tags', // array + 'categories', // array + 'publication_date', + 'short_name', + 'refs', // array + 'contents', + 'type', + 'model_type', + 'company', // array + 'id', + 'name', ]; - foreach ($array as $key => $category) { - $params[] = urlencode('job_category[]').'='.urlencode($array[$key]); - } - - $url = $this->client->setCategory($array)->getUrl(); - - foreach ($params as $param) { - $this->assertContains($param, $url); - } + $this->assertEquals($fields, $this->client->getDefaultResponseFields()); } - public function testUrlNotIncludesCategoryWhenNotProvided() + public function testItCanGetListingsPath() { - $param = urlencode('job_category[]').'='; - - $url = $this->client->getUrl(); - - $this->assertNotContains($param, $url); + $this->assertEquals('results', $this->client->getListingsPath()); } - public function testUrlIncludesCompanyWhenProvided() + public function testItCanCreateJobObjectFromPayload() { - $string = uniqid().' '.uniqid(); - $param = urlencode('company[]').'='.urlencode($string); - - $url = $this->client->setCompany($string)->getUrl(); - - $this->assertContains($param, $url); - } - - public function testUrlNotIncludesCompanyWhenNotProvided() - { - $param = urlencode('company[]').'='; - - $url = $this->client->getUrl(); - - $this->assertNotContains($param, $url); - } - - public function testUrlIncludesLevelWhenProvided() - { - $string = uniqid().' '.uniqid(); - $param = urlencode('job_level[]').'='.urlencode($string); - - $url = $this->client->setLevel($string)->getUrl(); - - $this->assertContains($param, $url); - } - - public function testUrlNotIncludesLevelWhenNotProvided() - { - $param = urlencode('job_level[]').'='; + $payload = $this->createJobArray(); - $url = $this->client->getUrl(); + $results = $this->client->createJobObject($payload); - $this->assertNotContains($param, $url); + $this->assertInstanceOf(Job::class, $results); + $this->assertEquals($payload['name'], $results->getTitle()); + $this->assertEquals($payload['contents'], $results->getDescription()); + $this->assertEquals($payload['refs']['landing_page'], $results->getUrl()); } - public function testUrlIncludesLocationWhenProvided() + /** + * Integration test for the client's getJobs() method. + */ + public function testItCanGetJobs() { - $location = uniqid().' '.uniqid(); - $param = urlencode('job_location[]').'='.urlencode($location); - - $url = $this->client->setLocation($location)->getUrl(); + $options = [ + 'category' => uniqid(), + 'location' => uniqid(), + 'api_key' => uniqid(), + ]; - $this->assertContains($param, $url); - } + $guzzle = m::mock('GuzzleHttp\Client'); - public function testUrlNotIncludesLocationWhenNotProvided() - { - $param = urlencode('job_location[]').'='; + $query = new MuseQuery($options); - $url = $this->client->getUrl(); + $client = new MuseProvider($query); - $this->assertNotContains($param, $url); - } + $client->setClient($guzzle); - public function testItCanCreateJobFromPayload() - { - $payload = $this->createJobArray(); + $response = m::mock('GuzzleHttp\Message\Response'); - $results = $this->client->createJobObject($payload); + $jobs = json_encode(['results' => [ + $this->createJobArray(), + $this->createJobArray(), + $this->createJobArray(), + ]]); - $this->assertEquals($payload['title'], $results->title); - $this->assertEquals($payload['company_name'], $results->company); - $this->assertEquals('https://www.themuse.com'.$payload['apply_link'], $results->url); - $this->assertEquals($payload['id'], $results->sourceId); - } - - public function testItCanCreateJobArrayFromPayloadWithMultipleLocations() - { - $locations_count = rand(2,20); - $payload = $this->createJobArrayWithMultipleLocations($locations_count); + $guzzle->shouldReceive('get') + ->with($query->getUrl(), []) + ->once() + ->andReturn($response); + $response->shouldReceive('getBody') + ->once() + ->andReturn($jobs); - $results = $this->client->createJobArray($payload); + $results = $client->getJobs(); - $this->assertCount($locations_count, $results); + $this->assertInstanceOf(Collection::class, $results); + $this->assertCount(3, $results); } - public function testItCanConnect() + /** + * Integration test with actual API call to the provider. + */ + public function testItCanGetJobsFromApi() { - $provider = $this->getProviderAttributes(); - - for ($i = 0; $i < $provider['jobs_count']; $i++) { - $payload['results'][] = $this->createJobArray(); + if (!getenv('API_KEY')) { + $this->markTestSkipped('API_KEY not set. Real API call will not be made.'); } - $responseBody = json_encode($payload); + $query = new MuseQuery([ + 'api_key' => getenv('API_KEY'), + ]); - $job = m::mock($this->jobClass); - $job->shouldReceive('setSource')->with($provider['source']) - ->times($provider['jobs_count'])->andReturnSelf(); + $client = new MuseProvider($query); - $response = m::mock('GuzzleHttp\Message\Response'); - $response->shouldReceive('getBody')->once()->andReturn($responseBody); + $results = $client->getJobs(); - $http = m::mock('GuzzleHttp\Client'); - $http->shouldReceive(strtolower($this->client->getVerb())) - ->with($this->client->getUrl(), $this->client->getHttpClientOptions()) - ->once() - ->andReturn($response); - $this->client->setClient($http); + $this->assertInstanceOf('JobApis\Jobs\Client\Collection', $results); - $results = $this->client->getJobs(); - - $this->assertInstanceOf($this->collectionClass, $results); - $this->assertCount($provider['jobs_count'], $results); + foreach($results as $job) { + $this->assertNotNull($job->name); + } } private function createJobArray() { return [ - 'id' => uniqid(), - 'title' => uniqid(), - 'company_name' => uniqid(), - 'apply_link' => uniqid(), - 'locations' => [uniqid()], - 'creation_date' => '2015-08-'.rand(1,30), - ]; - } - - private function createJobArrayWithMultipleLocations($count) { - $cc = 0; - - while ($cc < $count) { - $locations[] = uniqid(); - $cc++; - } - - return [ - 'id' => uniqid(), - 'title' => uniqid(), - 'company_name' => uniqid(), - 'apply_link' => uniqid(), - 'locations' => $locations, - 'creation_date' => '2015-08-'.rand(1,30), - ]; - } - - private function getProviderAttributes($attributes = []) - { - $defaults = [ - 'path' => uniqid(), - 'format' => 'json', - 'source' => uniqid(), - 'params' => [uniqid()], - 'jobs_count' => rand(2,10), + 'levels' => + array ( + 0 => + array ( + 'short_name' => 'entry', + 'name' => 'Entry Level', + ), + ), + 'locations' => + array ( + 0 => + array ( + 'name' => 'Sao Paolo, Brazil', + ), + ), + 'tags' => + array ( + 0 => + array ( + 'short_name' => 'fortune-1000-companies', + 'name' => 'Fortune 1000', + ), + ), + 'categories' => + [ + ["name" => "Sales & Business Development"], + ], + 'publication_date' => '2016-12-18T16:06:13.351729Z', + 'short_name' => 'litigation-counsel-lead-latam-f744ac', + 'refs' => + array ( + 'landing_page' => 'https://www.themuse.com/jobs/facebook/litigation-counsel-lead-latam-f744ac', + ), + 'contents' => '

Description with HTML...

', + 'type' => 'external', + 'model_type' => 'jobs', + 'company' => + array ( + 'short_name' => 'facebook', + 'name' => 'Facebook', + 'id' => 659, + ), + 'id' => 115888, + 'name' => 'Litigation Counsel Lead, LATAM', ]; - return array_replace($defaults, $attributes); } } From cf7b15eb7381ab42334a05c8fa401828466fb39b Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Fri, 6 Jan 2017 13:12:49 -0600 Subject: [PATCH 4/5] Updating readme usage --- README.md | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29d73c3..c060bc5 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,45 @@ composer require jobapis/jobs-muse ``` ## Usage +Create a Query object and add all the parameters you'd like via the constructor. + +```php +// Add parameters to the query via the constructor +$query = new JobApis\Jobs\Client\Queries\MuseQuery([ + 'api_key' => YOUR_API_ID // Optional: include your api key +]); +``` + +Or via the "set" method. All of the parameters documented in Indeed's documentation can be added. + +```php +// Add parameters via the set() method +$query->set('category', 'Engineering'); +``` + +You can even chain them if you'd like. +```php +// Add parameters via the set() method +$query->set('location', 'Chicago, IL') + ->set('company', 'Google'); ``` -Coming soon. + +Then inject the query object into the provider. + +```php +// Instantiating provider with a query object +$client = new JobApis\Jobs\Client\Provider\MuseProvider($query); +``` + +And call the "getJobs" method to retrieve results. + +```php +// Get a Collection of Jobs +$jobs = $client->getJobs(); ``` -The `getJobs` method will return a [Collection](https://github.com/jobapis/jobs-common/blob/master/src/Collection.php) of [Job](https://github.com/jobapis/jobs-common/blob/master/src/Job.php) objects. +This will return a [Collection](https://github.com/jobapis/jobs-common/blob/master/src/Collection.php) of [Job](https://github.com/jobapis/jobs-common/blob/master/src/Job.php) objects. ## Testing From c74b991be6ee36d5e9ef8cdd4cf6ce4c249f3682 Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Fri, 6 Jan 2017 13:21:26 -0600 Subject: [PATCH 5/5] Updating travis/composer versions --- .travis.yml | 14 ++++---------- composer.json | 2 +- 2 files changed, 5 insertions(+), 11 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/composer.json b/composer.json index d2a32f2..abe0ea1 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": ">=5.6.0", + "php": ">=5.5.0", "jobapis/jobs-common": "^2.0.2" }, "require-dev": {