Skip to content

Commit db40f4b

Browse files
committed
Pincode Serviceability API
1 parent e500bca commit db40f4b

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/Api.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace OpsWay\Clickpost;
66

@@ -37,7 +37,7 @@ class Api
3737
protected $endpointUrl;
3838

3939
/**
40-
* Api constructor.
40+
* Api constructor
4141
*
4242
* @param bool $production
4343
*/
@@ -51,7 +51,7 @@ public function __construct(bool $production = true)
5151
*/
5252
public function getClient(): Client
5353
{
54-
if (\is_null($this->client)) {
54+
if ($this->client === null) {
5555
$this->setClient(new Client($this->production, $this->getEndpointUrl()));
5656
}
5757
return $this->client;
@@ -184,13 +184,24 @@ public function cancel()
184184
return new Api\CancelOrder($this->getClient(), $this->getUsername(), $this->getApiKey());
185185
}
186186

187+
/**
188+
* @return Api\PincodeServiceability
189+
*
190+
* @throws \Exception
191+
*/
192+
public function pincodeServiceability()
193+
{
194+
$this->validateApi();
195+
return new Api\PincodeServiceability($this->getClient(), $this->getUsername(), $this->getApiKey());
196+
}
197+
187198
/**
188199
* @throws \Exception
189200
*/
190201
private function validateApi()
191202
{
192203
if (empty($this->getApiKey()) || empty($this->getUsername())) {
193-
throw new \Exception("API not fully configured", 422);
204+
throw new \Exception('API not fully configured', 422);
194205
}
195206
}
196207
}

src/Api/PincodeServiceability.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpsWay\Clickpost\Api;
6+
7+
class PincodeServiceability extends BaseApi
8+
{
9+
private const API_PATH = 'serviceability_api';
10+
11+
private const VERSION = 'v1';
12+
13+
/**
14+
* @param array $data
15+
*
16+
* @return object
17+
*
18+
* @throws \Exception
19+
*/
20+
public function get(array $data): object
21+
{
22+
$apiUrl = sprintf('%s/%s/', self::VERSION, self::API_PATH);
23+
$auth = new Auth($this->username, $this->apiKey);
24+
25+
return $this->client->post($apiUrl, $data, $auth);
26+
}
27+
}

0 commit comments

Comments
 (0)