Skip to content

Commit 50300b0

Browse files
authored
Merge pull request #1 from APIstax/develop
Release 1.0.0
2 parents 76934db + 907eb58 commit 50300b0

File tree

10 files changed

+355
-431
lines changed

10 files changed

+355
-431
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: weekly

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
- push
3+
4+
name: Test
5+
6+
jobs:
7+
run:
8+
name: Tests
9+
10+
strategy:
11+
matrix:
12+
php-versions: ['7.3', '7.4', '8.0', '8.1']
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Install PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-versions }}
24+
extensions: sockets, json, curl
25+
26+
- name: Install dependencies with composer
27+
run: composer install
28+
29+
- name: Test with phpunit
30+
run: vendor/bin/phpunit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,5 @@ Temporary Items
134134

135135
.openapi-generator
136136
gen
137-
/composer.lock
137+
composer.lock
138+
.phpunit.result.cache

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
# APIstax PHP Client
22

3-
[![Latest Version](https://img.shields.io/github/release/apistax/client-php.svg?style=flat-square)](https://github.com/apistax/client-php/releases)
3+
[![Latest Version](https://img.shields.io/github/v/tag/apistax/client-php?label=Latest%20Version)](https://packagist.org/packages/apistax/client)
44
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
55

6+
APIstax PHP client is a complete PHP client implementation for the [APIstax](https://apistax.io?utm_source=github&utm_medium=apistax-php-client&utm_campaign=readme) platform.
7+
8+
## Usage
9+
10+
Install the latest version:
11+
12+
```bash
13+
composer require 'apistax/client'
14+
```
15+
16+
Get your APIstax API key [here](https://app.apistax.io/api-keys?utm_source=github&utm_medium=apistax-php-client&utm_campaign=readme).
17+
18+
Initialise an `APIstaxClient` and start using it.
19+
20+
```php
21+
<?php
22+
23+
$config = new \APIstax\Configuration();
24+
$config->setApiKey("API_KEY");
25+
26+
$client = new \APIstax\APIstaxClient($config);
27+
28+
$payload = new \APIstax\Models\VatVerificationPayload();
29+
$payload->setVatId("VAT_ID");
30+
31+
$result = $this->client->verifyVatId($payload);
32+
```
633

734
The further information and documentation about the APIs can be found on [APIstax documentation](https://apistax.io/docs?utm_source=github&utm_medium=apistax-php-client&utm_campaign=readme) page.

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apistax/client",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"description": "Secure and reliable APIs for your common business needs.",
55
"type": "library",
66
"keywords": [
@@ -34,6 +34,10 @@
3434
"guzzlehttp/guzzle": "^7.3",
3535
"guzzlehttp/psr7": "^1.7 || ^2.0"
3636
},
37+
"require-dev": {
38+
"phpunit/phpunit": "^9",
39+
"donatj/mock-webserver": "^v2.5.0"
40+
},
3741
"autoload": {
3842
"psr-4": {
3943
"APIstax\\": "lib/"

lib/APIstaxClient.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@
2020

2121
class APIstaxClient
2222
{
23-
private const baseUrl = "https://api.apistax.io";
24-
2523
/**
2624
* @var ClientInterface
2725
*/
2826
private $client;
2927

3028
/**
31-
* @var string
29+
* @var Configuration
3230
*/
33-
private $apiKey;
31+
private $configuration;
3432

35-
public function __construct(string $apiKey)
33+
public function __construct(Configuration $configuration = null)
3634
{
3735
$this->client = new Client();
38-
$this->apiKey = $apiKey;
36+
37+
if($configuration === null) {
38+
$this->configuration = Configuration::getDefaultConfiguration();
39+
} else {
40+
$this->configuration = $configuration;
41+
}
3942
}
4043

4144
/**
@@ -87,7 +90,7 @@ public function verifyVatId(VatVerificationPayload $payload): VatVerificationRes
8790
*/
8891
public function geocodeSearch(GeocodeSearchPayload $payload): ?GeocodeResult
8992
{
90-
return $this->requestJson("/v1/geocode/search", $payload, null, "\APIstax\Models\GeocodeSearchPayload");
93+
return $this->requestJson("/v1/geocode/search", $payload, null, "\APIstax\Models\GeocodeResult");
9194
}
9295

9396
/**
@@ -100,7 +103,7 @@ public function geocodeSearch(GeocodeSearchPayload $payload): ?GeocodeResult
100103
*/
101104
public function geocodeReverse(GeocodeReversePayload $payload): ?GeocodeResult
102105
{
103-
return $this->requestJson("/v1/geocode/reverse", $payload, null, "\APIstax\Models\GeocodeReversePayload");
106+
return $this->requestJson("/v1/geocode/reverse", $payload, null, "\APIstax\Models\GeocodeResult");
104107
}
105108

106109
/**
@@ -147,7 +150,7 @@ private function requestJson(string $path, $body, $query, string $type): ModelIn
147150
*/
148151
private function request(string $path, $body, $query = null): ResponseInterface
149152
{
150-
$url = self::baseUrl . $path;
153+
$url = $this->configuration->getHost() . $path;
151154
$options = $this->createRequestOptions($body, $query);
152155

153156
try {
@@ -176,8 +179,9 @@ private function createRequestOptions($body, $query): array
176179
'headers' => [
177180
'User-Agent' => 'apistax-php-client',
178181
'Content-Type' => 'application/json',
179-
'Authorization' => 'Bearer ' . $this->apiKey
180-
]
182+
'Authorization' => 'Bearer ' . $this->configuration->getApiKey()
183+
],
184+
'http_errors' => false
181185
];
182186

183187
if (isset($query)) {

0 commit comments

Comments
 (0)