Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Rename ListBrandsRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
njoguamos committed Jan 28, 2024
1 parent 18a5443 commit aca3ab8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ CASHAPP_CLIENT_ID=CS-CI_ACKIl7VOyOUwAg...

## Usage

### Responses

All response return by this package are are instance of `Saloon\Http\Response` which has the following keys methods.

| Method | Description |
|-----------------------|------------------------------------------------------------------------|
| `$response->ok()` | Determine if the response code was "OK". |
| `$response->body()` | Get the body of the response as string. |
| `$response->status()` | Get the status code of the response. |
| `$response->json()` | Get the JSON decoded body of the response as an array or scalar value. |
| `$response->xml()` | Convert the XML response into a SimpleXMLElement. |


### 1 Network API

#### 1.1 Brands
Expand All @@ -73,13 +86,13 @@ Get a list of brands matching the given query parameters. [API Reference](https:
use NjoguAmos\CashApp\CashApp;

# Defaults
$brands = CashApp::listBrands();
$response = CashApp::getBrands();

# With params
$brands = CashApp::listBrands(limit: 20);
$response = CashApp::getBrands(limit: 20);
```

A successful response will be formatted as follows.
A successful response body `$response->body()` will be formatted as follows.

```json
{
Expand Down
9 changes: 5 additions & 4 deletions src/CashApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
namespace NjoguAmos\CashApp;

use NjoguAmos\CashApp\Connectors\NetworkConnector;
use NjoguAmos\CashApp\Requests\Network\Brands\ListBrandsRequest;
use NjoguAmos\CashApp\Requests\Network\Brands\GetBrandsRequest;
use Saloon\Exceptions\Request\FatalRequestException;
use Saloon\Exceptions\Request\RequestException;
use Saloon\Http\Response;

class CashApp
{
/**
* @throws FatalRequestException
* @throws RequestException
*/
public static function listBrands(string $cursor = null, int $limit = 50, $reference_id = null): string
public static function getBrands(string $cursor = null, int $limit = 50, $reference_id = null): Response
{
$connector = new NetworkConnector();

$request = new ListBrandsRequest();
$request = new GetBrandsRequest();

if ($cursor) {
$request->query()->add('cursor', $cursor);
Expand All @@ -29,6 +30,6 @@ public static function listBrands(string $cursor = null, int $limit = 50, $refer

$request->query()->add('limit', $limit);

return $connector->send($request)->body();
return $connector->send($request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Saloon\Enums\Method;
use Saloon\Http\Request;

class ListBrandsRequest extends Request
class GetBrandsRequest extends Request
{
protected Method $method = Method::GET;

public function resolveEndpoint(): string
{
return '/networks/brands';
return '/brands';
}
}
15 changes: 11 additions & 4 deletions tests/Feature/CashAppTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?php

use NjoguAmos\CashApp\CashApp;
use NjoguAmos\CashApp\Requests\Network\Brands\ListBrandsRequest;
use NjoguAmos\CashApp\Requests\Network\Brands\GetBrandsRequest;
use Saloon\Http\Request;
use Saloon\Http\Response;

it(description: 'can successfully get brands from cash app API', closure: function () {
$mockClient = mockRequest(
request: ListBrandsRequest::class,
request: GetBrandsRequest::class,
jsonFile: 'network/list-brands.json'
);

/** @noinspection PhpUnhandledExceptionInspection */
$brands = CashApp::listBrands();
$response = CashApp::getBrands(limit: 5);

$mockClient->assertSent(value: ListBrandsRequest::class);
$response->body();

$mockClient->assertSent(function (Request $request, Response $response) {
return $request instanceof GetBrandsRequest
&& $response->getPsrRequest()->getUri()->getPath() === '/network/v1/brands';
});

$mockClient->assertSentCount(count: 1);
});

0 comments on commit aca3ab8

Please sign in to comment.