Git Product home page Git Product logo

harvest-api-client's Introduction

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 ^1.0@dev' '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 client ID
    'client_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/freshhads/harvest-api-client/src/Model/configuration')
      ->build();

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

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

harvest-api-client's People

Contributors

larsjanssen6 avatar valentin-meyer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.