matthiasnoback/leanpub-api-client

A PHP client for the Leanpub API

dev-master 2014-02-26 13:29 UTC

README

Scrutinizer Quality Score Code Coverage

This library contains a PHP implementation of a client that can be used to connect to the Leanpub API. It is not feature-complete, but the features that are implemented are implemented fully and they work correctly.

Installation

Using Composer, require the matthiasnoback/leanpub-api-client package.

This package uses the Guzzle HTTP client to connect to the Leanpub API.

Usage

use Matthias\LeanpubApi\LeanpubApiFactory;
use Guzzle\Http\Client;

// your personal API key
$apiKey = ...;

$apiClient = new GuzzleClient(new Client(), $apiKey);
$factory = new LeanpubApiFactory($apiClient);

$leanpubApi = $factory->create();

Get coupons

To get all coupons for a given book:

$bookSlug = 'a-year-with-symfony';

$coupons = $leanpubApi->listCoupons($bookSlug);

Get individual purchases per page

$page = 2;

$individualPurchases = $leanpubApi->listIndividualPurchases($bookSlug, $page);

Get all individual purchases

foreach ($leanpubApi->listAllIndividualPurchases($bookSlug) as $purchase) {
    // iterate over the individual purchases one by one
    ...
}

Create a coupon

use Matthias\LeanpubApi\Dto\CreateCoupon;

$code = '1234abcd';
$startDate = new \DateTime('2014-04-01');
$coupon = new CreateCoupon($code, $startDate);

// configure the DTO some more using its setters
// $coupon->setEndDate(new \DateTime('2015-04-01'));
// ...

$leanpubApi->createCoupon($bookSlug, $coupon);