Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Harvest API Client for Harvest V2 API.

License

Notifications You must be signed in to change notification settings

freshheads/harvest-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Harvest API Client

Build Status

This library provides an API client for the Harvest V2 API. Plain PHP classes are used to map the data from the API. JMS Serializer is used for the serialization/deserializtion of this model classes.

It is also perfectly possible to use this Client without using the endpoints and models.

Requirements

Harvest API Client works with PHP 7.1.3 and up. This library depends on the HTTPPlug, see http://docs.php-http.org/en/latest/httplug/introduction.html.

Installation

Harvest API Client can easily be installed using Composer. You must have a php-http/client-implementation compatible client (+ adapter) installed to be able to make requests. You can run the following command, to install Guzzle6 and it's php-http adapter.

composer require 'freshheads/harvest-api-client' 'php-http/guzzle6-adapter'

You can replace php-http/guzzle6-adapter with any other compatible client implementation.

Usage

Instantiate the client and replace the configuration with your personal credentials:

// Use the composer autoloader to load dependencies
require_once 'vendor/autoload.php';

use FH\HarvestApiClient\Client\ClientFactory;

// API Client configuration
$clientConfiguration =
    'access_token' => 'YourAccessToken',
    // Your harvest account ID
    'account_id'    => 12345678,
    // Harvest asks you to customize the user agent header, so that they can contact you in case you're doing something wrong
    'user_agent'   => 'My Application ([email protected])'
];

// In this example we made use of the Guzzle6 as HTTPClient in combination with an HTTPPlug compatible adapter.
$client = ClientFactory::create([], null, null, $clientConfiguration);

// Make some calls directly via the client
$response = $client->get('/clients', ['page' => 1]);

Endpoints

To use the harvest entity specific Endpoints, you need to install jms/serializer:

composer require 'jms/serializer' 'symfony/yaml'

The serializer needs to know where to find the serialization configuration of the models. The configuration is located in src/Model/configuration. An example is given below:

// Code is based on the example above.

// Creates the serializer and configures it with the serialization configuration
$serializer = SerializerBuilder::create()
      ->addMetadataDir(__DIR__ . '/vendor/freshheads/harvest-api-client/src/Model/configuration')
      ->build();

$harvestClientEndpoint = new ClientEndpoint($client, $serializer);

// List harvest clients (returns an array of Client objects).
$harvestClients = $harvestClientEndpoint->list();

About

Harvest API Client for Harvest V2 API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages