Skip to content

Commit 151e8dc

Browse files
committed
Updated files for release 1.8.3
1 parent 3aef002 commit 151e8dc

33 files changed

+675
-111
lines changed

.gitignore

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
.idea
2-
xolphin-api-php.iml
3-
vendor
4-
test.php
5-
composer.lock
6-
/sample.pdf
7-
/cert.crt
1+
vendor/
2+
.idea/

CHANGELOG.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
# Change Log
2-
All notable changes to this project will be documented in this file.
1+
# Changelog
2+
All notable changes to the wrapper will be documented in this file.
3+
4+
## [1.8.3]
5+
### Added
6+
- Added support for SSLCheck
7+
- Added support for Invoices
8+
- Added support for scheduling validation calls
9+
10+
### Updated
11+
- Updated Client with remaining request count
12+
- Added sa_email and referenceOrderNr to Request (Pull request #12)
13+
- Deprecated sendComodoSAEmail, replaced by sendSectigoSAEmail
314

415
## [1.6.2]
516
### Updated
@@ -10,7 +21,7 @@ All notable changes to this project will be documented in this file.
1021
- Error handling in Client (pull request #5)
1122
- Correct extra domain and price information for MDC in support/products
1223

13-
## [1.6.0] - 2017-07-06
24+
## [1.6.0]
1425
### Added
1526
- Compatability with Xolphin REST Api v1.6.0
1627
- Support for the new Comodo DCV method

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xolphin/xolphin-api-php",
3-
"version": "1.6.1",
3+
"version": "1.8.3",
44
"description": "Xolphin API module for PHP",
55
"license": "MIT",
66
"keywords": [
@@ -14,16 +14,21 @@
1414
"email": "info@xolphin.nl"
1515
},
1616
{
17-
"name": "Roman Ragimoff",
18-
"email": "roma.ragimoff@gmail.com"
17+
"name": "Ivo Geersen",
18+
"email": "ivo@xolphin.nl"
19+
},
20+
{
21+
"name": "Bart van Kalmthout",
22+
"email": "bart@xolphin.nl"
1923
}
2024
],
2125
"support": {
2226
"email": "api@xolphin.com"
2327
},
2428
"require": {
2529
"php": ">=5.6.0",
26-
"guzzlehttp/guzzle": "~6"
30+
"guzzlehttp/guzzle": "~6",
31+
"ext-json": "*"
2732
},
2833
"require-dev": {
2934
"phpunit/phpunit": "^5.3"

readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ require 'vendor/autoload.php';
3030
$client = new Xolphin\Client('<username>', '<password>');
3131
```
3232

33+
### Rate Limiting
34+
35+
#### Current limit
36+
```php
37+
$limit = $client->getLimit();
38+
echo $limit . "\n";
39+
```
40+
41+
#### Requests remaining for limit
42+
```php
43+
$requestsRemaining = $client->getRequestsRemaining();
44+
echo $requestsRemaining . "\n";
45+
```
46+
3347
### Requests
3448

3549
#### Get list of requests

src/Client.php

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33
namespace Xolphin;
44

55
use GuzzleHttp\Exception\RequestException;
6+
use Psr\Http\Message\StreamInterface;
67
use Xolphin\Endpoint\Certificate;
8+
use Xolphin\Endpoint\Invoice;
79
use Xolphin\Endpoint\Request;
810
use Xolphin\Endpoint\Support;
11+
use Xolphin\Exception\XolphinRequestException;
912

1013
class Client {
1114
const BASE_URI = 'https://api.xolphin.com/v%d/';
1215
const BASE_URI_TEST = 'https://test-api.xolphin.com/v%d/';
1316
const API_VERSION = 1;
14-
const VERSION = '1.6.0';
17+
const VERSION = '1.8.3';
1518

1619
private $username = '';
1720
private $password = '';
1821
private $guzzle;
1922

23+
/** @var int */
24+
private $limit;
25+
26+
/** @var int */
27+
private $requestsRemaining;
28+
2029
/**
2130
* Client constructor.
2231
* @param string $username
@@ -27,6 +36,9 @@ function __construct($username, $password, $test=false) {
2736
$this->username = $username;
2837
$this->password = $password;
2938

39+
$this->limit = 1;
40+
$this->requestsRemaining = 1;
41+
3042
$options = [
3143
'base_uri' => sprintf(($test ? Client::BASE_URI_TEST : Client::BASE_URI), Client::API_VERSION),
3244
'auth' => [$this->username, $this->password],
@@ -42,6 +54,22 @@ function __construct($username, $password, $test=false) {
4254
$this->guzzle = new \GuzzleHttp\Client($options);
4355
}
4456

57+
/**
58+
* @return int
59+
*/
60+
public function getLimit()
61+
{
62+
return $this->limit;
63+
}
64+
65+
/**
66+
* @return int
67+
*/
68+
public function getRequestsRemaining()
69+
{
70+
return $this->requestsRemaining;
71+
}
72+
4573
/**
4674
* @param string $method
4775
* @param array $data
@@ -51,18 +79,10 @@ function __construct($username, $password, $test=false) {
5179
public function get($method, $data = []) {
5280
try {
5381
$result = $this->guzzle->get($method, ['query' => $data]);
82+
$this->updateLimitAndRemaining($result->getHeader('X-RateLimit-Limit')[0], $result->getHeader('X-RateLimit-Remaining')[0]);
5483
return json_decode($result->getBody());
5584
} catch (RequestException $e) {
56-
$data = json_decode($e->getResponse()->getBody());
57-
if($data == NULL) {
58-
throw new \Exception($e->getResponse()->getBody());
59-
} else {
60-
if(isset($data->message) || isset($data->errors)) {
61-
throw new \Exception(json_encode($data), $e->getCode());
62-
} else {
63-
throw new \Exception($e->getMessage(), $e->getCode());
64-
}
65-
}
85+
throw XolphinRequestException::createFromRequestException($e);
6686
}
6787
}
6888

@@ -91,34 +111,35 @@ public function post($method, $data = []) {
91111
}
92112

93113
$result = $this->guzzle->post($method, ['multipart' => $mp]);
114+
$this->updateLimitAndRemaining($result->getHeader('X-RateLimit-Limit')[0], $result->getHeader('X-RateLimit-Remaining')[0]);
94115
return json_decode($result->getBody());
95116
} catch (RequestException $e) {
96-
$data = json_decode($e->getResponse()->getBody());
97-
if($data == NULL) {
98-
throw new \Exception($e->getResponse()->getBody());
99-
} else {
100-
throw new \Exception(json_encode($data), $e->getCode());
101-
}
117+
throw XolphinRequestException::createFromRequestException($e);
102118
}
103119
}
104120

121+
/**
122+
* @param $limit
123+
* @param $remaining
124+
*/
125+
public function updateLimitAndRemaining($limit, $remaining) {
126+
$this->limit = $limit;
127+
$this->requestsRemaining = $remaining;
128+
}
129+
105130
/**
106131
* @param string $method
107132
* @param array $data
108-
* @return \Psr\Http\Message\StreamInterface
133+
* @return StreamInterface
109134
* @throws \Exception
110135
*/
111136
public function download($method, $data = []) {
112137
try {
113138
$result = $this->guzzle->get($method, ['query' => $data]);
139+
$this->updateLimitAndRemaining($result->getHeader('X-RateLimit-Limit')[0], $result->getHeader('X-RateLimit-Remaining')[0]);
114140
return $result->getBody();
115141
} catch (RequestException $e) {
116-
try {
117-
$data = json_decode($e->getResponse()->getBody());
118-
throw new \Exception($data->message);
119-
} catch (\Exception $ex) {
120-
throw new \Exception($e->getResponse()->getBody());
121-
}
142+
throw XolphinRequestException::createFromRequestException($e);
122143
}
123144
}
124145

@@ -142,4 +163,11 @@ public function certificate() {
142163
public function support() {
143164
return new Support($this);
144165
}
166+
167+
/**
168+
* @return Invoice
169+
*/
170+
public function invoice() {
171+
return new Invoice($this);
172+
}
145173
}

src/Endpoint/Certificate.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace Xolphin\Endpoint;
44

5+
use Exception;
56
use Xolphin\Client;
67
use Xolphin\Requests\Reissue;
78
use Xolphin\Requests\Renew;
89
use Xolphin\Responses\Base;
9-
use Xolphin\Responses\Request as RequestResponse;
10+
use Xolphin\Responses\Request;
1011

1112
class Certificate {
1213
/**
@@ -24,6 +25,7 @@ function __construct($client) {
2425

2526
/**
2627
* @return \Xolphin\Responses\Certificate[]
28+
* @throws Exception
2729
*/
2830
public function all() {
2931
$certificates = [];
@@ -44,6 +46,7 @@ public function all() {
4446
/**
4547
* @param int $id
4648
* @return \Xolphin\Responses\Certificate
49+
* @throws Exception
4750
*/
4851
public function get($id) {
4952
return new \Xolphin\Responses\Certificate($this->client->get('certificates/' . $id));
@@ -53,6 +56,7 @@ public function get($id) {
5356
* @param int $id
5457
* @param string $format
5558
* @return mixed
59+
* @throws Exception
5660
*/
5761
public function download($id, $format = 'CRT') {
5862
return $this->client->download('certificates/' . $id . '/download', [
@@ -63,19 +67,21 @@ public function download($id, $format = 'CRT') {
6367
/**
6468
* @param int $id
6569
* @param Reissue $request
66-
* @return RequestResponse
70+
* @return Request
71+
* @throws Exception
6772
*/
6873
public function reissue($id, $request) {
69-
return new RequestResponse($this->client->post('certificates/' . $id . '/reissue', $request->getArray()));
74+
return new Request($this->client->post('certificates/' . $id . '/reissue', $request->getArray()));
7075
}
7176

7277
/**
7378
* @param int $id
7479
* @param Renew $request
75-
* @return RequestResponse
80+
* @return Request
81+
* @throws Exception
7682
*/
7783
public function renew($id, $request) {
78-
return new RequestResponse($this->client->post('certificates/' . $id . '/renew', $request->getArray()));
84+
return new Request($this->client->post('certificates/' . $id . '/renew', $request->getArray()));
7985
}
8086

8187
public function cancel($id, $reason, $revoke = FALSE) {

src/Endpoint/Invoice.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Xolphin\Endpoint;
4+
5+
use Exception;
6+
use Xolphin\Client;
7+
use Xolphin\Responses\Invoices;
8+
9+
class Invoice {
10+
/**
11+
* @var Client
12+
*/
13+
private $client;
14+
15+
/**
16+
* Requests constructor.
17+
* @param Client $client
18+
*/
19+
function __construct($client) {
20+
$this->client = $client;
21+
}
22+
23+
/**
24+
* @return \Xolphin\Responses\Invoice[]
25+
* @throws Exception
26+
*/
27+
public function all() {
28+
$invoices = [];
29+
30+
$result = new Invoices($this->client->get('invoices', ['page' => 1]));
31+
if(!$result->isError()) {
32+
$invoices = $result->invoices;
33+
while($result->page < $result->pages) {
34+
$result = new Invoices($this->client->get('invoices', ['page' => $result->page + 1]));
35+
if($result->isError()) break;
36+
$invoices = array_merge($invoices, $result->invoices);
37+
}
38+
}
39+
40+
return $invoices;
41+
}
42+
43+
/**
44+
* @param $id
45+
* @return \Xolphin\Responses\Invoice
46+
* @throws Exception
47+
*/
48+
public function get($id) {
49+
return new \Xolphin\Responses\Invoice($this->client->get('invoices/' . $id));
50+
}
51+
52+
/**
53+
* @param $id
54+
* @param string $format
55+
* @return mixed
56+
* @throws Exception
57+
*/
58+
public function download($id, $format = 'PDF') {
59+
return $this->client->get('invoices/' . $id . '/download?type=' . $format);
60+
}
61+
}

0 commit comments

Comments
 (0)