Skip to content

Commit

Permalink
Move to organization (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenky committed Oct 27, 2023
1 parent 964ae8d commit d7f3cbc
Show file tree
Hide file tree
Showing 94 changed files with 330 additions and 338 deletions.
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A simple package that allows you to write your API integrations or SDKs in a ele

## Installation & Usage

This package requires PHP >= 7.2.5. You'll find installation instructions and full documentation on https://jenky.github.io/atlas.
This package requires PHP >= 7.2.5. You'll find installation instructions and full documentation on https://phanxipang.github.io/fansipan.

## Testing

Expand Down Expand Up @@ -40,20 +40,14 @@ If you discover any security related issues, please email [email protected] instea

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/jenky/atlas.svg?style=for-the-badge
[ico-version]: https://img.shields.io/packagist/v/fansipan/fansipan.svg?style=for-the-badge
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge
[ico-travis]: https://img.shields.io/travis/jenky/atlas/master.svg?style=for-the-badge
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/jenky/atlas.svg?style=for-the-badge
[ico-code-quality]: https://img.shields.io/scrutinizer/g/jenky/atlas.svg?style=for-the-badge
[ico-gh-actions]: https://img.shields.io/github/actions/workflow/status/jenky/atlas/testing.yml?branch=main&label=actions&logo=github&style=for-the-badge
[ico-codecov]: https://img.shields.io/codecov/c/github/jenky/atlas?logo=codecov&style=for-the-badge
[ico-downloads]: https://img.shields.io/packagist/dt/jenky/atlas.svg?style=for-the-badge

[link-packagist]: https://packagist.org/packages/jenky/atlas
[link-travis]: https://travis-ci.org/jenky/atlas
[link-scrutinizer]: https://scrutinizer-ci.com/g/jenky/atlas/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/jenky/atlas
[link-gh-actions]: https://github.com/jenky/atlas/actions
[link-codecov]: https://codecov.io/gh/jenky/atlas
[link-downloads]: https://packagist.org/packages/jenky/atlas
[ico-gh-actions]: https://img.shields.io/github/actions/workflow/status/phanxipang/fansipan/testing.yml?branch=main&label=actions&logo=github&style=for-the-badge
[ico-codecov]: https://img.shields.io/codecov/c/github/phanxipang/fansipan?logo=codecov&style=for-the-badge
[ico-downloads]: https://img.shields.io/packagist/dt/fansipan/fansipan.svg?style=for-the-badge

[link-packagist]: https://packagist.org/packages/fansipan/fansipan
[link-gh-actions]: https://github.com/phanxipang/fansipan/actions
[link-codecov]: https://codecov.io/gh/phanxipang/fansipan
[link-downloads]: https://packagist.org/packages/fansipan/fansipan

10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"name": "jenky/atlas",
"name": "fansipan/fansipan",
"description": "A simple package that allows you to write your API integrations or SDKs in a elegant way.",
"keywords": [
"jenky",
"atlas",
"http",
"sdk",
"api",
"psr7",
"psr17",
"psr18"
],
"homepage": "https://github.com/jenky/atlas",
"homepage": "https://github.com/phanxipang/fansipan",
"license": "MIT",
"authors": [
{
Expand Down Expand Up @@ -39,15 +37,15 @@
},
"autoload": {
"psr-4": {
"Jenky\\Atlas\\": "src"
"Fansipan\\": "src"
},
"classmap": [
"stubs"
]
},
"autoload-dev": {
"psr-4": {
"Jenky\\Atlas\\Tests\\": "tests"
"Fansipan\\Tests\\": "tests"
}
},
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions docs/advanced/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ final class AfterMiddleware
To register default middleware, list the middleware class in the `defaultMiddleware` method of your connector class.

```php
use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Traits\ConnectorTrait;
use Fansipan\Contracts\ConnectorInterface;
use Fansipan\Traits\ConnectorTrait;

final class Connector implements ConnectorInterface
{
Expand All @@ -118,21 +118,21 @@ Once the middleware has been created, you may use the `push` method to assign mi
$connector->middleware()->push(new AddHeader('X-Foo', 'baz'));
```

Creating a middleware that modifies a request is made much simpler using the `Jenky\Atlas\Middleware\Interceptor::request()` method. This middleware accepts a function that takes the request argument:
Creating a middleware that modifies a request is made much simpler using the `Fansipan\Middleware\Interceptor::request()` method. This middleware accepts a function that takes the request argument:

```php
use Jenky\Atlas\Middleware\Interceptor;
use Fansipan\Middleware\Interceptor;
use Psr\Http\Message\RequestInterface;

$connector->middleware()->push(Interceptor::request(function (RequestInterface $request) {
return $request->withHeader('X-Foo', 'bar');
}));
```

Modifying a response is also much simpler using the `Jenky\Atlas\Middleware\Interceptor::response()` middleware:
Modifying a response is also much simpler using the `Fansipan\Middleware\Interceptor::response()` middleware:

```php
use Jenky\Atlas\Middleware\Interceptor;
use Fansipan\Middleware\Interceptor;
use Psr\Http\Message\ResponseInterface;

$connector->middleware()->push(Interceptor::response(function (ResponseInterface $response) {
Expand Down
6 changes: 3 additions & 3 deletions docs/advanced/response-decoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ HTTP response is a crucial aspect of web development, and it is essential to dec

### Configuring

The decoder should be configured as per-request basis. By default `Jenky\Atlas\Request` uses [`ChainDecoder`](https://github.com/jenky/atlas/blob/18f96c176bed75fa321df6a675146820760e295f/src/Request.php#L124-L130) to decode the response body. Essentially, it iterates over a list of `JsonDecoder` and `XmlDecoder` and attempts to read the `Content Type` header to determine which one to use for decoding the body.
The decoder should be configured as per-request basis. By default `Fansipan\Request` uses [`ChainDecoder`](https://github.com/jenky/atlas/blob/18f96c176bed75fa321df6a675146820760e295f/src/Request.php#L124-L130) to decode the response body. Essentially, it iterates over a list of `JsonDecoder` and `XmlDecoder` and attempts to read the `Content Type` header to determine which one to use for decoding the body.

### Creating Custom Decoder

To create a custom decoder, you need to implement [`DecoderInterface`](https://github.com/jenky/atlas/blob/main/src/Contracts/DecoderInterface.php) which defines the structure that a decoder must have. The contract contains only one method: `decode` where you can implement your own logic to decode the response body. Then you can start using it in your request.

```php
use Jenky\Atlas\Contracts\DecoderInterface;
use Jenky\Atlas\Request;
use Fansipan\Contracts\DecoderInterface;
use Fansipan\Request;

class MyRequest extends Request
{
Expand Down
34 changes: 17 additions & 17 deletions docs/advanced/retrying-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Sometimes you may deal with APIs that fail frequently because of network issues

## Getting Started

To retry a failed request, you should use the `Jenky\Atlas\ConnectorConfigurator` to configure your connector for retrying the request. The `retry` method accepts the maximum number of times the request should be attempted, a retry strategy to decide if the request should be retried, and to define the waiting time between each retry.
To retry a failed request, you should use the `Fansipan\ConnectorConfigurator` to configure your connector for retrying the request. The `retry` method accepts the maximum number of times the request should be attempted, a retry strategy to decide if the request should be retried, and to define the waiting time between each retry.

```php
use Jenky\Atlas\ConnectorConfigurator;
use Fansipan\ConnectorConfigurator;

$connector = new MyConnector();
$response = (new ConnectorConfigurator())
Expand All @@ -29,11 +29,11 @@ $response = (new ConnectorConfigurator())

By default, failed requests are retried up to 3 times, with an exponential delay between retries (first retry = 1 second; second retry: 2 seconds, third retry: 4 seconds) and only for the following HTTP status codes: `423`, `425`, `429`, `502` and `503` when using any HTTP method and `500`, `504`, `507` and `510` when using an HTTP [idempotent method](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods).

If needed, you may pass a third argument to the `Jenky\Atlas\RetryableConnector` instance. It is an instance of `Jenky\Atlas\Contracts\RetryStrategyInterface` that determines if the retries should actually be attempted. This will retries the failed requests with a delay of 1 second.
If needed, you may pass a third argument to the `Fansipan\RetryableConnector` instance. It is an instance of `Fansipan\Contracts\RetryStrategyInterface` that determines if the retries should actually be attempted. This will retries the failed requests with a delay of 1 second.

```php
use Jenky\Atlas\ConnectorConfigurator;
use Jenky\Atlas\Retry\RetryCallback;
use Fansipan\ConnectorConfigurator;
use Fansipan\Retry\RetryCallback;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -50,8 +50,8 @@ $response = (new ConnectorConfigurator())
You may also pass second and third arguments to the `RetryCallback::when()` method to customise the waiting time between each retry.

```php
use Jenky\Atlas\ConnectorConfigurator;
use Jenky\Atlas\Retry\RetryCallback;
use Fansipan\ConnectorConfigurator;
use Fansipan\Retry\RetryCallback;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -68,9 +68,9 @@ In the example above, failed requests are retried up to 3 times, with an exponen
Instead of using an interval delay or calculated exponential delay, you may easily configure "exponential" backoffs by using `withDelay()` method. In this example, the retry delay will be 1 second for the first retry, 3 seconds for the second retry, and 10 seconds for the third retry:

```php
use Jenky\Atlas\ConnectorConfigurator;
use Jenky\Atlas\Retry\Backoff;
use Jenky\Atlas\Retry\RetryCallback;
use Fansipan\ConnectorConfigurator;
use Fansipan\Retry\Backoff;
use Fansipan\Retry\RetryCallback;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -84,13 +84,13 @@ $response = (new ConnectorConfigurator())

## Disabling Throwing Exceptions

If a request fails, it will be attempted again - if it reaches the maximum number of errors, a `Jenky\Atlas\Exception\RequestRetryFailedException` will be thrown. If a request is successful at any point, it will return a `Jenky\Atlas\Response` instance.
If a request fails, it will be attempted again - if it reaches the maximum number of errors, a `Fansipan\Exception\RequestRetryFailedException` will be thrown. If a request is successful at any point, it will return a `Fansipan\Response` instance.

If you would like to disable this behavior, you may provide a `throw` argument with a value of `false`. When disabled, the last response received by the client will be returned after all retries have been attempted:


```php
use Jenky\Atlas\ConnectorConfigurator;
use Fansipan\ConnectorConfigurator;

$response = (new ConnectorConfigurator())
->retry(2, null, throw: false)
Expand All @@ -106,8 +106,8 @@ Since middleware is mutable, adding new middleware means that all subsequent req
```php
<?php

use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Traits\ConnectorTrait;
use Fansipan\Contracts\ConnectorInterface;
use Fansipan\Traits\ConnectorTrait;

final class MyConnector implements ConnectorInterface
{
Expand All @@ -116,9 +116,9 @@ final class MyConnector implements ConnectorInterface
```
+++ Usage
```php
use Jenky\Atlas\Middleware\RetryRequests;
use Jenky\Atlas\Retry\Delay;
use Jenky\Atlas\Retry\GenericRetryStrategy;
use Fansipan\Middleware\RetryRequests;
use Fansipan\Retry\Delay;
use Fansipan\Retry\GenericRetryStrategy;

$connector = new MyConnector();

Expand Down
22 changes: 11 additions & 11 deletions docs/advanced/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ label: SDK
## Creating SDK Connector

```php
use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Middleware\Auth\BearerAuthentication;
use Jenky\Atlas\Middleware\Interceptor;
use Jenky\Atlas\Traits\ConnectorTrait;
use Fansipan\Contracts\ConnectorInterface;
use Fansipan\Middleware\Auth\BearerAuthentication;
use Fansipan\Middleware\Interceptor;
use Fansipan\Traits\ConnectorTrait;
use Psr\Http\Message\RequestInterface;

final class Github implements ConnectorInterface
Expand Down Expand Up @@ -66,7 +66,7 @@ $github = new Github('access-token');
When you have created the request, all that developers would need to do is to instantiate and send the request on the connector.

```php
use Jenky\Atlas\Request;
use Fansipan\Request;

final class GetRepository extends Request
{
Expand Down Expand Up @@ -108,8 +108,8 @@ Sometimes you may want to make it easy for the developer to find all the methods

+++ Definition
```php
use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Traits\ConnectorTrait;
use Fansipan\Contracts\ConnectorInterface;
use Fansipan\Traits\ConnectorTrait;

final class Github implements ConnectorInterface
{
Expand Down Expand Up @@ -137,12 +137,12 @@ The resource pattern can help you combine your SDK requests into simple groups t

### Creating a Resource

Let's start by creating a `OrganizationResource` class. This class should contain a constructor that passes in an instance of `Jenky\Atlas\Contracts\ConnectorInterface` and additional constructor arguments that you need for all request grouped under the resource.
Let's start by creating a `OrganizationResource` class. This class should contain a constructor that passes in an instance of `Fansipan\Contracts\ConnectorInterface` and additional constructor arguments that you need for all request grouped under the resource.

```php
<?php

use Jenky\Atlas\Contracts\ConnectorInterface;
use Fansipan\Contracts\ConnectorInterface;

final class OrganizationResource
{
Expand Down Expand Up @@ -175,8 +175,8 @@ Now we'll define a method on the connector which returns this resource class. Do
```php
<?php

use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Traits\ConnectorTrait;
use Fansipan\Contracts\ConnectorInterface;
use Fansipan\Traits\ConnectorTrait;

final class Github implements ConnectorInterface
{
Expand Down
6 changes: 3 additions & 3 deletions docs/basic/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ To create your own HTTP client, use the `defaultClient` method.
```php
<?php

use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Traits\ConnectorTrait;
use Jenky\Atlas\Request;
use Fansipan\Contracts\ConnectorInterface;
use Fansipan\Traits\ConnectorTrait;
use Fansipan\Request;
use GuzzleHttp\Client;
use Psr\Http\Client\ClientInterface;

Expand Down
Loading

0 comments on commit d7f3cbc

Please sign in to comment.