File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/app/Komma/CareersJobs/CareersApi.php
<?php
namespace App\Komma\CareersJobs;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
class CareersApi
{
/** @var string */
private $apiEndpoint;
/** @var Client */
private $careersApi;
/**
* Make the mailchimp client
* Mailchimp constructor.
*/
public function __construct()
{
// The last of the api will be used to asign the <dc> (Data Center)
$this->apiEndpoint = 'https://rentman1.recruitee.com/api/';
$this->careersApi = new Client([
'base_uri' => $this->apiEndpoint,
]);
}
/**
* Handles the request through the client.
* Will also trigger a Error on Warning level to notify us in Slack.
*
* @param string $method
* @param string $uri
* @param array $options
* @return mixed
*/
private function request(string $method, string $uri = '', array $options = [])
{
try {
$response = $this->careersApi->request($method, $uri, $options);
return json_decode($response->getBody()->getContents());
} catch (\Exception $exception) {
dd($exception);
Log::warning($exception);
return null;
}
}
/**
* Get information about all lists.
*
* @link https://mailchimp.com/developer/reference/lists/
*
* @return mixed
*/
public function getJobs()
{
$apiResponse = $this->request('get', 'offers');
return collect($apiResponse->offers);
}
public function getJob($careerId)
{
$jobs = $this->getJobs();
return $jobs->where('id', $careerId)->first();
}
}