Skip to content

Commit

Permalink
Merge pull request #10 from jobapis/ziprecruiter
Browse files Browse the repository at this point in the history
Adding Ziprecruiter, minor improvements
  • Loading branch information
karllhughes committed Oct 14, 2016
2 parents 2580382 + ee5f590 commit 68e8e64
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 145 deletions.
8 changes: 5 additions & 3 deletions app/Console/Commands/EmailJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EmailJobs extends Command
*
* @var string
*/
protected $signature = 'jobs:email';
protected $signature = 'jobs:email {--email=}';

/**
* The console command description.
Expand Down Expand Up @@ -46,9 +46,11 @@ public function __construct(UserRepository $users)
*/
public function handle()
{
foreach ($this->users->getConfirmed() as $user) {
$count = 0;
foreach ($this->users->getConfirmed($this->option('email')) as $user) {
$this->dispatch(new CollectJobsForUser($user));
$count++;
}
return $this->info("User job searches queued for collection.");
return $this->info("{$count} user job searches queued for collection.");
}
}
59 changes: 38 additions & 21 deletions app/Jobs/CollectJobsForUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,6 @@ public function handle(JobsMulti $jobsClient)
return $jobs;
}

/**
* Sort jobs by date posted, desc
*
* @param array $jobs
*
* @return array
*/
protected function sortJobs($jobs = [])
{
// Sort by date
usort($jobs, function ($item1, $item2) {
return $item2->datePosted <=> $item1->datePosted;
});
// Filter any older than max age
$jobs = array_filter($jobs, function ($job) {
return $job->datePosted > new \DateTime(self::MAX_DAYS_OLD.' days ago');
});
// Truncate to the max number of results
return array_slice($jobs, 0, self::MAX_JOBS);
}

/**
* Convert the array of collections to one large array
*
Expand All @@ -104,6 +83,7 @@ protected function getJobsFromCollections($collectionsArray = [])
array_walk_recursive(
$collectionsArray,
function (Collection $collection) use (&$jobs) {
$this->logErrorsFromCollection($collection);
$jobListings = array_slice(
$collection->all(),
0,
Expand All @@ -116,4 +96,41 @@ function (Collection $collection) use (&$jobs) {
);
return $jobs;
}

/**
* Logs all the errors attached to a collection
*
* @param array $jobsByProvider
*
* @return void
*/
protected function logErrorsFromCollection(Collection $collection)
{
if ($collection->getErrors()) {
foreach ($collection->getErrors() as $error) {
Log::error($error);
}
}
}

/**
* Sort jobs by date posted, desc
*
* @param array $jobs
*
* @return array
*/
protected function sortJobs($jobs = [])
{
// Sort by date
usort($jobs, function ($item1, $item2) {
return $item2->datePosted <=> $item1->datePosted;
});
// Filter any older than max age
$jobs = array_filter($jobs, function ($job) {
return $job->datePosted > new \DateTime(self::MAX_DAYS_OLD.' days ago');
});
// Truncate to the max number of results
return array_slice($jobs, 0, self::MAX_JOBS);
}
}
12 changes: 9 additions & 3 deletions app/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ public function getById($id = null, $options = [])
}

/**
* Retrieves all active user accounts
* Retrieves all active user accounts, or accounts for a single email if specified.
*
* @param $email null | string
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getConfirmed()
public function getConfirmed($email = null)
{
return $this->users->confirmed()->get();
$query = $this->users->confirmed();
if ($email) {
$query = $query->where('email', $email);
}
return $query->get();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog
All Notable changes to `jobs-to-mail` will be documented in this file.

## 0.4.0 - 2016-10-14

### Added
- Support for [Ziprecruiter](https://github.com/jobapis/jobs-ziprecruiter) job board.
- Automatically run migrations after composer install.
- Logging errors from collections.
- Model factories for database seed operations.
- Command line argument to run collection job for single email.

## Fixed
- Bug in Careerbuilder API via Jobs-Multi upgrade.
- Removing HTML highlighting characters from Juju job results.

## 0.3.0 - 2016-10-06

### Added
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"php": ">=7.0.0",
"laravel/framework": "5.3.*",
"s-ichikawa/laravel-sendgrid-driver": "^1.1",
"jobapis/jobs-multi": "^0.4.1"
"jobapis/jobs-multi": "^0.5.2"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down Expand Up @@ -43,7 +43,8 @@
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
"php artisan optimize",
"php artisan migrate --force"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
Expand Down
Loading

0 comments on commit 68e8e64

Please sign in to comment.