Added customer all and get
This commit is contained in:
1 parent
4a2b1b6a44
commit
410906b2cd
7 files changed
+140
-7
No files matched your search
+11
-1
@@ -2,4 +2,14 @@
|
|||||||
|
|
||||||
namespace Mattitja\BokioApiLaravel;
|
namespace Mattitja\BokioApiLaravel;
|
||||||
|
|
||||||
class Bokio {}
|
use Mattitja\BokioApiLaravel\Resources\Customer;
|
||||||
|
|
||||||
|
class Bokio
|
||||||
|
{
|
||||||
|
public function __construct(protected BokioClient $client) {}
|
||||||
|
|
||||||
|
public function customers(): Customer
|
||||||
|
{
|
||||||
|
return new Customer($this->client);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -12,7 +12,7 @@ class BokioClient
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private string $accessToken,
|
private string $accessToken,
|
||||||
private string $companyId,
|
private string $companyId,
|
||||||
private string $baseUrl
|
private string $baseUrl = 'https://api.bokio.se'
|
||||||
) {
|
) {
|
||||||
$this->request = Http::acceptJson()
|
$this->request = Http::acceptJson()
|
||||||
->asJson()
|
->asJson()
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Mattitja\BokioApiLaravel\Resources;
|
||||||
|
|
||||||
|
use Mattitja\BokioApiLaravel\BokioClient;
|
||||||
|
|
||||||
|
class Customer
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected BokioClient $client
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all customers.
|
||||||
|
*/
|
||||||
|
public function all(int $page = 1, int $pageSize = 25): object
|
||||||
|
{
|
||||||
|
return $this->client->get('customers', [
|
||||||
|
'page' => $page,
|
||||||
|
'pageSize' => $pageSize,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(string $customerId): object
|
||||||
|
{
|
||||||
|
return $this->client->get('customers/'.$customerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Mattitja\BokioApiLaravel\BokioClient;
|
||||||
|
use Mattitja\BokioApiLaravel\Resources\Customer;
|
||||||
|
|
||||||
|
function loadFixture(string $path): array
|
||||||
|
{
|
||||||
|
$json = file_get_contents(__DIR__."/Responses/{$path}");
|
||||||
|
|
||||||
|
return json_decode($json, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
Http::fake(function ($request) {
|
||||||
|
if ($request->method() === 'GET' && preg_match('#/customers/\w+#', $request->url())) {
|
||||||
|
return Http::response(loadFixture('Customer/get.200.json'), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->method() === 'GET' && str_contains($request->url(), '/customers')) {
|
||||||
|
return Http::response(loadFixture('Customer/all.200.json'), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback
|
||||||
|
return Http::response([], 404);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->client = new BokioClient('fake-token', '123456');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can fetch a list of customers from Bokio', function () {
|
||||||
|
$response = (new Customer($this->client))->all();
|
||||||
|
|
||||||
|
expect($response->items)->toHaveCount(1);
|
||||||
|
expect($response->items[0]->name)->toBe('customer 1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can fetch a single customer from Bokio', function () {
|
||||||
|
$customerId = '55c899c5-82b2-47fa-9c51-e35fc9b26443';
|
||||||
|
$response = (new Customer($this->client))->get($customerId);
|
||||||
|
|
||||||
|
expect($response->id)->toBe($customerId);
|
||||||
|
expect($response->name)->toBe('customer 1');
|
||||||
|
});
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
it('can test', function () {
|
|
||||||
expect(true)->toBeTrue();
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"totalItems": 0,
|
||||||
|
"totalPages": 0,
|
||||||
|
"currentPage": 0,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": "55c899c5-82b2-47fa-9c51-e35fc9b26443",
|
||||||
|
"name": "customer 1",
|
||||||
|
"type": "company",
|
||||||
|
"vatNumber": "SE1234567890",
|
||||||
|
"orgNumber": "123456-7890",
|
||||||
|
"paymentTerms": "30",
|
||||||
|
"contactsDetails": [
|
||||||
|
{
|
||||||
|
"name": "John Doe",
|
||||||
|
"email": "john@email.com",
|
||||||
|
"phone": "0927-5631505",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"address": {
|
||||||
|
"line1": "Älvsborgsvägen 10",
|
||||||
|
"line2": null,
|
||||||
|
"city": "Göteborg",
|
||||||
|
"postalCode": "123 45",
|
||||||
|
"country": "SE"
|
||||||
|
},
|
||||||
|
"language": "sv"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"id": "55c899c5-82b2-47fa-9c51-e35fc9b26443",
|
||||||
|
"name": "customer 1",
|
||||||
|
"type": "company",
|
||||||
|
"vatNumber": "SE1234567890",
|
||||||
|
"orgNumber": "123456-7890",
|
||||||
|
"paymentTerms": "30",
|
||||||
|
"contactsDetails": [
|
||||||
|
{
|
||||||
|
"id": "240a4af0-edfd-47b1-b4ab-f30450eaac19",
|
||||||
|
"name": "John Doe",
|
||||||
|
"email": "john@email.com",
|
||||||
|
"phone": "0927-5631505",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"address": {
|
||||||
|
"line1": "Älvsborgsvägen 10",
|
||||||
|
"line2": null,
|
||||||
|
"city": "Göteborg",
|
||||||
|
"postalCode": "123 45",
|
||||||
|
"country": "SE"
|
||||||
|
},
|
||||||
|
"language": "sv"
|
||||||
|
}
|
||||||
Reference in new issue
Block a user