Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setle API Update #1

Merged
merged 12 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: "Tests"

on: [push, pull_request]

jobs:
phpunit-7:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [7.1, 7.4]
dependency-version: [prefer-lowest, prefer-stable]

name: PHPUnit ${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v1, phpunit:7.5

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: phpunit
phpunit-8:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1]
dependency-version: [prefer-lowest, prefer-stable]

name: PHPUnit ${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: phpunit:9.5

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: phpunit
phpcs:
runs-on: ubuntu-latest

name: PHP CodeSniffer

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: php-8.1-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: mbstring, dom, curl, libxml, zip, pcntl, intl, exif, iconv
coverage: none

- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute PHPCS
run: vendor/bin/phpcs

phpstan:
runs-on: ubuntu-latest

name: PHPStan

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: php-8.1-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: mbstring, dom, curl, libxml, zip, pcntl, intl, exif, iconv
coverage: none

- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute PHPStan
run: vendor/bin/phpstan
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/composer.lock
/coverage
/vendor
/.phpunit.result.cache
/.phpunit.result.cache
/.phpcs-cache
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Setle API

PHP client for the [Setle](https://www.setle.be) API. For information and terms of use, refer to the
[official documentation](https://api.setle.be).
[official documentation](https://public-api.setle.app/).

## Installation

Expand All @@ -10,24 +10,16 @@ PHP client for the [Setle](https://www.setle.be) API. For information and terms
## Usage

```php
// Instantiate the API using a broker token
$api = new Setle\Setle('0123456789abcdef');
use Setle\Setle;

// Request a list of estates
$estates = $api->whise()->getEstates();
```

### Available endpoints
// Instantiate the API using a client id and client secret
$api = new Setle('client-id-string', 'client-secret-string');

Use the following methods to access available endpoints:

```php
$api->whise()->getEstates();
$api->whise()->getEstate($id);
$api->skarabee()->getEstates();
$api->skarabee()->getEstate($id);
$api->sweepbright()->getEstates();
$api->sweepbright()->getEstate($id);
// Request a list of estates
$estates = $api->getEstates();
foreach ($estates as $estate) {
echo $estate->estate->estate_type . ': ' . $estate->referral_link . PHP_EOL;
}
```

## Access tokens
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"ocramius/package-versions": "^1.4|^2.1"
fyrts marked this conversation as resolved.
Show resolved Hide resolved
},
"require-dev": {
"phpunit/phpunit": "^7.5|^8.4|^9.0"
"phpunit/phpunit": "^7.5|^8.4|^9.0",
"phpstan/phpstan": "^1.4|^1.9",
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": { "Setle\\": "src/" }
Expand Down
14 changes: 14 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<arg value="nps"/>

<file>src</file>
<file>tests</file>

<rule ref="PSR12"/>
</ruleset>
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 8
paths:
- src
- tests
universalObjectCratesClasses:
- Setle\Response\ResponseObject
ignoreErrors:
-
message: '#^Argument of an invalid type iterable\|object supplied for foreach, only iterables are supported\.$#'
path: src/Response/ResponseObject.php
16 changes: 8 additions & 8 deletions src/ApiAdapter/ApiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

abstract class ApiAdapter implements ApiAdapterInterface
{
/** @var callable */
/** @var callable|null */
protected $debugCallable;

/**
* Send a request to the API and return the parsed response.
*
* @param Request $request
*
* @throws Exception\AuthException if access token is missing or invalid
* @throws Exception\NotFoundException if requested resource is unavailable
* @throws Exception\ApiException if a server-side error occurred
* @throws \Setle\Exception\AuthException if access token is missing or invalid
* @throws \Setle\Exception\NotFoundException if requested resource is unavailable
* @throws \Setle\Exception\ApiException if a server-side error occurred
*
* @return ResponseObject
*/
Expand All @@ -38,21 +38,21 @@ public function request(Request $request): ResponseObject
}

$response = json_decode($response_body, false);

return new ResponseObject($response);
}

/**
* Set a callback for debugging API requests and responses.
*
* @param callable|null $callable Callback that accepts up to three
* arguments - respectively the response body, request endpoint, and the
* arguments - respectively the response body, request endpoint and the
* request body.
*
* @return self
* @return Self
*/
public function debugResponses(?callable $callable): void
public function debugResponses(?callable $callable): self
{
$this->debugCallable = $callable;
return $this;
}
}
15 changes: 10 additions & 5 deletions src/ApiAdapter/HttpApiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
*/
final class HttpApiAdapter extends ApiAdapter
{
private const BASE_URI = 'https://api.setle.be/v1/';
private const BASE_URI = 'https://public-api.setle.app/v1/';

/** @var Client */
private $client;

/**
* @param array<mixed> $http_client_options
*/
public function __construct(array $http_client_options = [])
{
$http_client_options['base_uri'] = self::BASE_URI;
Expand All @@ -41,17 +44,19 @@ public function __construct(array $http_client_options = [])
$http_client_options['headers']['Content-Type'] = 'application/json';

$this->client = new Client(array_merge([
'timeout' => 10.0,
'timeout' => 30.0,
'http_errors' => false,
], $http_client_options));
}

/**
* {@inheritdoc}
*
* @throws Exception\AuthException if access token is missing or invalid
* @throws Exception\NotFoundException if requested resource is unavailable
* @throws Exception\ApiException if a server-side error occurred
* @throws \Setle\Exception\AuthException if access token is missing or invalid
* @throws \Setle\Exception\NotFoundException if requested resource is unavailable
* @throws \Setle\Exception\ApiException if a server-side error occurred
*
* @return string
*/
public function requestBody(Request $request): string
{
Expand Down
1 change: 0 additions & 1 deletion src/Exception/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

class ApiException extends \Exception
{

}
1 change: 0 additions & 1 deletion src/Exception/AuthException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

class AuthException extends \Exception
{

}
14 changes: 14 additions & 0 deletions src/Exception/FailedJsonEncodingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/*
* This file is part of the fw4/setle-api library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Setle\Exception;

class FailedJsonEncodingException extends \Exception
{
}
1 change: 0 additions & 1 deletion src/Exception/InvalidPropertyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

class InvalidPropertyException extends \Exception
{

}
1 change: 0 additions & 1 deletion src/Exception/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

class NotFoundException extends \Exception
{

}
Loading