Skip to content

Commit 1860d7f

Browse files
authored
Merge branch 'master' into master
2 parents 937fd6e + c0d6b27 commit 1860d7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3000
-214
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UKFast API PHP client
1+
UKFast API PHP SDK
22
=====================
33
[![Build Status](https://travis-ci.org/ukfast/sdk-php.svg?branch=master)](https://travis-ci.org/ukfast/sdk-php)
44
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
@@ -19,6 +19,8 @@ The recommended way to install this package is through [composer](https://getcom
1919
composer require ukfast/sdk
2020
```
2121

22+
Alternativly you can download one of our [tagged releases](https://github.com/ukfast/sdk-php/releases) for manual installation, we dont recommend cloning the master branch for use in production environments as we cannot guarentee its stability.
23+
2224
This package does currently support PHP 5.6+, but we recommend moving to 7.1+ as soon as possible.
2325

2426

@@ -43,12 +45,14 @@ foreach ($page->getItems() as $request) {
4345
}
4446
```
4547

48+
We have a [collection of examples](/examples/) of common functionality for each service to help you get started.
49+
4650

4751
Contributing
4852
------------
4953

5054
We welcome contributions that will benefit other users,
51-
please see [CONTRIBUTING](CONTRIBUTING.md) for details on how to get involved.
55+
please see [CONTRIBUTING](CONTRIBUTING.md) for details on how you can get involved.
5256

5357

5458
License

examples/safedns/zoneRecords.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$zoneName = $argv[1];
1414
$zone = $safedns->zones()->getByName($zoneName);
1515

16-
foreach ($safedns->records()->getAllByZoneName($zone->name) as $record) {
16+
foreach ($safedns->records()->getByZoneName($zone->name) as $record) {
1717
echo "# {$record->id} {$record->name} {$record->type} {$record->content} \n";
1818
}
1919

src/Account/Client.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,20 @@ public function credits()
3131
{
3232
return (new CreditClient($this->httpClient))->auth($this->token);
3333
}
34+
35+
/**
36+
* @return BaseClient
37+
*/
38+
public function invoices()
39+
{
40+
return (new InvoiceClient($this->httpClient))->auth($this->token);
41+
}
42+
43+
/**
44+
* @return BaseClient
45+
*/
46+
public function invoiceQueries()
47+
{
48+
return (new InvoiceQueryClient($this->httpClient))->auth($this->token);
49+
}
3450
}

src/Account/Entities/Company.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class Company
2424
*/
2525
public $isDemoAccount;
2626

27+
/**
28+
* @var string
29+
*/
30+
public $name;
31+
2732
/**
2833
* Company constructor.
2934
* @param null $item
@@ -39,5 +44,7 @@ public function __construct($item = null)
3944

4045
$this->primaryContactId = $item->primary_contact_id;
4146
$this->isDemoAccount = $item->is_demo_account;
47+
48+
$this->name = $item->name;
4249
}
4350
}

src/Account/Entities/Invoice.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Account\Entities;
4+
5+
use DateTime;
6+
7+
class Invoice
8+
{
9+
/**
10+
* @var int
11+
*/
12+
public $id;
13+
14+
/**
15+
* @var \Datetime
16+
*/
17+
public $date;
18+
19+
/**
20+
* @var bool
21+
*/
22+
public $paid;
23+
24+
/**
25+
* @var float
26+
*/
27+
public $net;
28+
29+
/**
30+
* @var float
31+
*/
32+
public $vat;
33+
34+
/**
35+
* @var float
36+
*/
37+
public $gross;
38+
39+
/**
40+
* Invoice constructor.
41+
*
42+
* @param null $item
43+
*/
44+
public function __construct($item = null)
45+
{
46+
if (empty($item)) {
47+
return;
48+
}
49+
50+
$this->id = $item->id;
51+
$this->date = DateTime::createFromFormat('Y-m-d', $item->date);
52+
$this->paid = $item->paid;
53+
$this->net = $item->net;
54+
$this->vat = $item->vat;
55+
$this->gross = $item->gross;
56+
}
57+
}

src/Account/Entities/InvoiceQuery.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Account\Entities;
4+
5+
use DateTime;
6+
7+
class InvoiceQuery
8+
{
9+
/**
10+
* @var int
11+
*/
12+
public $id;
13+
14+
/**
15+
* @var int
16+
*/
17+
public $contactId;
18+
19+
/**
20+
* @var int
21+
*/
22+
public $amount;
23+
24+
/**
25+
* @var string
26+
*/
27+
public $whatWasExpected;
28+
29+
/**
30+
* @var string
31+
*/
32+
public $whatWasReceived;
33+
34+
/**
35+
* @var string
36+
*/
37+
public $proposedSolution;
38+
39+
/**
40+
* @var array
41+
*/
42+
public $invoiceIds;
43+
44+
/**
45+
* @var string
46+
*/
47+
public $contactMethod;
48+
49+
/**
50+
* @var string
51+
*/
52+
public $resolution;
53+
54+
/**
55+
* @var \DateTime
56+
*/
57+
public $resolutionDate;
58+
59+
/**
60+
* @var string
61+
*/
62+
public $status;
63+
64+
/**
65+
* InvoiceQuery constructor.
66+
*
67+
* @param null $item
68+
*/
69+
public function __construct($item = null)
70+
{
71+
if (empty($item)) {
72+
return;
73+
}
74+
75+
$resolutionDate = ($item->resolution_date != null)
76+
? DateTime::createFromFormat(DateTime::ISO8601, $item->resolution_date)
77+
: null;
78+
79+
$this->id = $item->id;
80+
$this->contactId = $item->contact_id;
81+
$this->amount = $item->amount;
82+
$this->whatWasExpected = $item->what_was_expected;
83+
$this->whatWasReceived = $item->what_was_received;
84+
$this->proposedSolution = $item->proposed_solution;
85+
$this->invoiceIds = $item->invoice_ids;
86+
$this->contactMethod = $item->contact_method;
87+
$this->resolution = $item->resolution;
88+
$this->resolutionDate = $resolutionDate;
89+
$this->status = $item->status;
90+
}
91+
}

src/Account/InvoiceClient.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Account;
4+
5+
use UKFast\SDK\Account\Entities\Invoice;
6+
use UKFast\SDK\Client as BaseClient;
7+
use UKFast\SDK\Page;
8+
use UKFast\SDK\SelfResponse;
9+
10+
class InvoiceClient extends BaseClient
11+
{
12+
protected $basePath = 'account/';
13+
14+
/**
15+
* Gets a paginated response of all Invoices
16+
*
17+
* @param int $page
18+
* @param int $perPage
19+
* @param array $filters
20+
* @return Page
21+
* @throws \GuzzleHttp\Exception\GuzzleException
22+
*/
23+
public function getPage($page = 1, $perPage = 15, $filters = [])
24+
{
25+
$page = $this->paginatedRequest('v1/invoices', $page, $perPage, $filters);
26+
$page->serializeWith(function ($item) {
27+
return new Invoice($item);
28+
});
29+
30+
return $page;
31+
}
32+
33+
/**
34+
* Gets an individual invoice
35+
*
36+
* @param string $id
37+
* @return Invoice
38+
* @throws \GuzzleHttp\Exception\GuzzleException
39+
*/
40+
public function getById($id)
41+
{
42+
$response = $this->request("GET", "v1/invoices/$id");
43+
$body = $this->decodeJson($response->getBody()->getContents());
44+
return new Invoice($body->data);
45+
}
46+
}

src/Account/InvoiceQueryClient.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Account;
4+
5+
use UKFast\SDK\Account\Entities\InvoiceQuery;
6+
use UKFast\SDK\Client as BaseClient;
7+
use UKFast\SDK\Page;
8+
use UKFast\SDK\SelfResponse;
9+
10+
class InvoiceQueryClient extends BaseClient
11+
{
12+
protected $basePath = 'account/';
13+
14+
/**
15+
* Gets a paginated response of all invoice queries
16+
*
17+
* @param int $page
18+
* @param int $perPage
19+
* @param array $filters
20+
* @return Page
21+
* @throws \GuzzleHttp\Exception\GuzzleException
22+
*/
23+
public function getPage($page = 1, $perPage = 15, $filters = [])
24+
{
25+
$page = $this->paginatedRequest('v1/invoice-queries', $page, $perPage, $filters);
26+
$page->serializeWith(function ($item) {
27+
return new InvoiceQuery($item);
28+
});
29+
30+
return $page;
31+
}
32+
33+
/**
34+
* Gets an individual invoice query
35+
*
36+
* @param string $id
37+
* @return InvoiceQuery
38+
* @throws \GuzzleHttp\Exception\GuzzleException
39+
*/
40+
public function getById($id)
41+
{
42+
$response = $this->request("GET", "v1/invoice-queries/$id");
43+
$body = $this->decodeJson($response->getBody()->getContents());
44+
return new InvoiceQuery($body->data);
45+
}
46+
47+
/**
48+
* @param $invoiceQuery
49+
* @return SelfResponse
50+
* @throws \GuzzleHttp\Exception\GuzzleException
51+
*/
52+
public function create($invoiceQuery)
53+
{
54+
$response = $this->post("v1/invoice-queries", $this->invoiceQueryToJson($invoiceQuery));
55+
$response = $this->decodeJson($response->getBody()->getContents());
56+
57+
return (new SelfResponse($response))
58+
->setClient($this)
59+
->serializeWith(function ($response) {
60+
return $this->serializeInvoiceQuery($response->data);
61+
});
62+
}
63+
64+
/**
65+
* Converts a response stdClass into an InvoiceQuery object
66+
*
67+
* @param \stdClass
68+
* @return \UKFast\SDK\Account\Entities\InvoiceQuery
69+
*/
70+
protected function serializeInvoiceQuery($item)
71+
{
72+
$invoiceQuery = new Entities\InvoiceQuery($item);
73+
74+
return $invoiceQuery;
75+
}
76+
77+
protected function invoiceQueryToJson($invoiceQuery)
78+
{
79+
$payload = [
80+
'contact_id' => $invoiceQuery->contactId,
81+
'amount' => $invoiceQuery->amount,
82+
'what_was_expected' => $invoiceQuery->whatWasExpected,
83+
'what_was_received' => $invoiceQuery->whatWasReceived,
84+
'proposed_solution' => $invoiceQuery->proposedSolution,
85+
'invoice_ids' => $invoiceQuery->invoiceIds,
86+
'contact_method' => $invoiceQuery->contactMethod
87+
];
88+
89+
return json_encode($payload);
90+
}
91+
}

0 commit comments

Comments
 (0)