Skip to content

Commit

Permalink
Merge pull request #15 from vivait/fix/BRA-1811
Browse files Browse the repository at this point in the history
[BRA-1811] Remove Guzzle dependency
  • Loading branch information
leightonthomas authored Nov 16, 2018
2 parents ed37cf6 + 99abb8b commit c8e4206
Show file tree
Hide file tree
Showing 22 changed files with 1,078 additions and 1,042 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ before_script:
- sh .travis.install.sh

script:
- bin/phpspec run --format=pretty
- bin/phpunit
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
composer require vivait/docbuild-php
```

and then write an Adapter that's compatible with the [Adapter interface](src/Vivait/DocBuild/Http/Adapter.php).

## Usage

See Doc.Build's Api documentation for detailed information on its methods.

Creating an instance of of `DocBuild` will use the `GuzzleAdapter` by default.
You can create your own adapter by implementing `HttpAdapter`.

The class requires your client id and client secret.
The class requires your client id, client secret and a compatible [Adapter](src/Vivait/DocBuild/Http/Adapter.php).

```php
$docBuild = new DocBuild($clientId, $clientSecret);
// Instantiate your adapter
$client = new MyAdapter();

$docBuild = new DocBuild($clientId, $clientSecret, $client);

$docBuild->createDocument('ADocument', 'docx', '/path/to/file.docx');

Expand All @@ -26,23 +28,21 @@ $docBuild->convertToPdf('documentid', 'http://mycallback.url/api');

```

### Http Client
The guzzle library is used to interact the API. However, you can use your own
adapter implementing `Vivait\DocBuild\Http\HttpAdapter` and injecting it into
the constructor:

```php
$docBuild = new DocBuild($clientId, $clientSecret, $options, new CustomHttpAdapter());
```

### Caching
This library uses the `doctrine/cache` library to cache `access_token` between
requestes. By default it will use the `Doctrine\Common\Cache\FilesystemCache`,
requests. By default it will use the `Doctrine\Common\Cache\FilesystemCache`,
but this can be changed by injecting a cache that implements
`Doctrine\Common\Cache\Cache` into the constructor:

```php
$docBuild = new DocBuild($clientId, $clientSecret, $options, null, new ArrayCache());
$docBuild = new DocBuild(
$clientId,
$clientSecret,
GuzzleAdapter::createWithConfig([]),
$options,
null,
new ArrayCache()
);
```

### Manually refresh access_token
Expand All @@ -51,13 +51,15 @@ this behaviour can be changed by setting the following option, or passing this
options array into the constructor on instantiation.

```php
$docBuild->setOptions([
'token_refresh' => false, //Default: true
]);
$docBuild->setOptions(
[
'token_refresh' => false, // Default: true
]
);

try {
$docs = $docBuild->getDocuments();
} catch (TokenExpiredException $e) {
//Have another go
// Have another go
}
```
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
"prefer-stable": true,
"require": {
"php": ">=7.1",
"guzzlehttp/guzzle": "~5.0",
"symfony/options-resolver": "^2.2|^3.4",
"doctrine/cache": "~1.4"
"doctrine/cache": "~1.4",
"psr/http-message": "^1.0"
},
"require-dev": {
"mikey179/vfsStream": "^1.6",
"sebastian/comparator": "^1.2.4",
"phpspec/phpspec": "^5.1"
"phpunit/phpunit": "^7.4"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-0": {
"Vivait\\DocBuild\\": "src/"
"Vivait\\DocBuild\\": "src/",
"Tests\\Vivait\\DocBuild\\": "tests/"
}
}
}
23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="docbuild-php">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit c8e4206

Please sign in to comment.