benborla / jobadder-api-client
JobAdder API Client
Requires
- php: >=8.1.0
- jane-php/open-api-runtime: ^7.0
- psr/http-message: ^1.0
- psr/log: ^3.0
- symfony/serializer: ^6.0.0
Requires (Dev)
- phpunit/php-invoker: ^3.1.1
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-12-20 17:47:11 UTC
README
A PHP API client for JobAdder, produced via jane-openapi
Installation
composer require varspool/jobadder-api-client
Usage
The namespace is BenBorla\JobAdder
. The main client is BenBorla\JobAdder\Client
. The Client class provides access to
a set of API resources:
$contacts = $client->contacts()->findContacts(['limit' => 3]); $ads = $client->jobAds()->getJobAds();
You can also access the resources directly from the BenBorla\JobAdder\V2\Resource
namespace.
Instantiating a Client
The Client (and any Resource objects you create yourself) need to be given a configured HTTP client to be able to
communicate with JobAdder. This HTTP client should implement the HttpClient
or the HttpAsyncClient
from
HTTPlug. There are HTTPPlug adapters for most popular
HTTP clients in PHP (e.g. Guzzle)
Here's how you might use a Guzzle 6 client with this library:
-
Install the Guzzle adapter:
composer require php-http/guzzle6-adapter
-
Pass the Guzzle client into the JobAdder client via an adapter:
use GuzzleHttp\Client as GuzzleClient; use BenBorla\JobAdder\Client as JobAdderClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $guzzle = new GuzzleClient($options); $http = new GuzzleAdapter($guzzle); $jobadder = new JobAdderClient($http);
OAuth and the Authorization header
Because the client is injected, you can configure things like the base URI (you should probably use the api
part of the
OAuth response from JobAdder), and the Authorization header:
// Get these both from the OAuth token response $api = 'https://localapi.jobadder.com/v2'; $token = 'abcdef01234567890'; $guzzle = new GuzzleClient([ 'base_uri' => $api, 'headers' => [ 'Authorization' => 'Bearer ' . $token ] ]);
Note that this client doesn't deal with the OAuth flow; it can take over once you have a valid access token.