From 861fe1e5d2797167b292bdbd794900c1bd6c92a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Sat, 31 Aug 2019 19:35:31 +0200 Subject: [PATCH] Add documentation --- README.md | 155 ++++++++++++++++++++++++++++++++++++ README.stub | 143 +++++++++++++++++++++++++++++++++ composer.json | 5 +- generator/generate-docs.php | 83 +++++++++++++++++++ phpunit.xml | 5 -- 5 files changed, 384 insertions(+), 7 deletions(-) create mode 100644 README.md create mode 100644 README.stub create mode 100644 generator/generate-docs.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e715b8 --- /dev/null +++ b/README.md @@ -0,0 +1,155 @@ +# bitinflow Accounts + +[![Latest Stable Version](https://img.shields.io/packagist/v/ghostzero/bitinflow-accounts.svg?style=flat-square)](https://packagist.org/packages/ghostzero/bitinflow-accounts) +[![Total Downloads](https://img.shields.io/packagist/dt/ghostzero/bitinflow-accounts.svg?style=flat-square)](https://packagist.org/packages/ghostzero/bitinflow-accounts) +[![License](https://img.shields.io/packagist/l/ghostzero/bitinflow-accounts.svg?style=flat-square)](https://packagist.org/packages/ghostzero/bitinflow-accounts) + +PHP bitinflow Accounts API Client for Laravel 5+ + +## Table of contents + +1. [Installation](#installation) +2. [Configuration](#configuration) +3. [Examples](#examples) +4. [Documentation](#documentation) +6. [Development](#Development) + +## Installation + +``` +composer require ghostzero/bitinflow-accounts +``` + +**If you use Laravel 5.5+ you are already done, otherwise continue.** + +Add Service Provider to your `app.php` configuration file: + +```php +GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class, +``` + +## Configuration + +Copy configuration to config folder: + +``` +$ php artisan vendor:publish --provider="GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider" +``` + +Add environmental variables to your `.env` + +``` +BITINFLOW_ACCOUNTS_KEY= +BITINFLOW_ACCOUNTS_SECRET= +BITINFLOW_ACCOUNTS_REDIRECT_URI=http://localhost +``` + +## Examples + +#### Basic + +```php +$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); + +$bitinflowAccounts->setClientId('abc123'); + +// Get SSH Key by User ID +$result = $bitinflowAccounts->getSshKeysByUserId(38); + +// Check, if the query was successfull +if ( ! $result->success()) { + die('Ooops: ' . $result->error()); +} + +// Shift result to get single key data +$sshKey = $result->shift(); + +echo $sshKey->name; +``` + +#### Setters + +```php +$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); + +$bitinflowAccounts->setClientId('abc123'); +$bitinflowAccounts->setClientSecret('abc456'); +$bitinflowAccounts->setToken('abcdef123456'); + +$bitinflowAccounts = $bitinflowAccounts->withClientId('abc123'); +$bitinflowAccounts = $bitinflowAccounts->withClientSecret('abc123'); +$bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456'); +``` + +#### OAuth Tokens + +```php +$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); + +$bitinflowAccounts->setClientId('abc123'); +$bitinflowAccounts->setToken('abcdef123456'); + +$result = $bitinflowAccounts->getAuthedUser(); + +$user = $userResult->shift(); +``` + +```php +$bitinflowAccounts->setToken('uvwxyz456789'); + +$result = $bitinflowAccounts->getAuthedUser(); +``` + +```php +$result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser(); +``` + +#### Facade + +```php +use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts; + +BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser(); +``` + +## Documentation + +### Users + +```php +public function getAuthedUser() +``` + +### SshKeys + +```php +public function getSshKeysByUserId(int $id) +public function createSshKey(string $publicKey, string $name = NULL) +public function deleteSshKey(int $id) +``` + +[**OAuth Scopes Enums**](https://git.preuss.io/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php) + +## Development + +#### Run Tests + +```shell +composer test +``` + +```shell +CLIENT_ID=xxxx CLIENT_KEY=yyyy CLIENT_ACCESS_TOKEN=zzzz composer test +``` + +#### Generate Documentation + +```shell +composer docs +``` + +--- + +Join the bitinflow Discord! + +[![Discord](https://discordapp.com/api/guilds/373468864098336768/embed.png?style=banner2)](https://discord.gg/2ZrCe2h) \ No newline at end of file diff --git a/README.stub b/README.stub new file mode 100644 index 0000000..4d433c0 --- /dev/null +++ b/README.stub @@ -0,0 +1,143 @@ +# bitinflow Accounts + +[![Latest Stable Version](https://img.shields.io/packagist/v/ghostzero/bitinflow-accounts.svg?style=flat-square)](https://packagist.org/packages/ghostzero/bitinflow-accounts) +[![Total Downloads](https://img.shields.io/packagist/dt/ghostzero/bitinflow-accounts.svg?style=flat-square)](https://packagist.org/packages/ghostzero/bitinflow-accounts) +[![License](https://img.shields.io/packagist/l/ghostzero/bitinflow-accounts.svg?style=flat-square)](https://packagist.org/packages/ghostzero/bitinflow-accounts) + +PHP bitinflow Accounts API Client for Laravel 5+ + +## Table of contents + +1. [Installation](#installation) +2. [Configuration](#configuration) +3. [Examples](#examples) +4. [Documentation](#documentation) +6. [Development](#Development) + +## Installation + +``` +composer require ghostzero/bitinflow-accounts +``` + +**If you use Laravel 5.5+ you are already done, otherwise continue.** + +Add Service Provider to your `app.php` configuration file: + +```php +GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class, +``` + +## Configuration + +Copy configuration to config folder: + +``` +$ php artisan vendor:publish --provider="GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider" +``` + +Add environmental variables to your `.env` + +``` +BITINFLOW_ACCOUNTS_KEY= +BITINFLOW_ACCOUNTS_SECRET= +BITINFLOW_ACCOUNTS_REDIRECT_URI=http://localhost +``` + +## Examples + +#### Basic + +```php +$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); + +$bitinflowAccounts->setClientId('abc123'); + +// Get SSH Key by User ID +$result = $bitinflowAccounts->getSshKeysByUserId(38); + +// Check, if the query was successfull +if ( ! $result->success()) { + die('Ooops: ' . $result->error()); +} + +// Shift result to get single key data +$sshKey = $result->shift(); + +echo $sshKey->name; +``` + +#### Setters + +```php +$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); + +$bitinflowAccounts->setClientId('abc123'); +$bitinflowAccounts->setClientSecret('abc456'); +$bitinflowAccounts->setToken('abcdef123456'); + +$bitinflowAccounts = $bitinflowAccounts->withClientId('abc123'); +$bitinflowAccounts = $bitinflowAccounts->withClientSecret('abc123'); +$bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456'); +``` + +#### OAuth Tokens + +```php +$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); + +$bitinflowAccounts->setClientId('abc123'); +$bitinflowAccounts->setToken('abcdef123456'); + +$result = $bitinflowAccounts->getAuthedUser(); + +$user = $userResult->shift(); +``` + +```php +$bitinflowAccounts->setToken('uvwxyz456789'); + +$result = $bitinflowAccounts->getAuthedUser(); +``` + +```php +$result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser(); +``` + +#### Facade + +```php +use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts; + +BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser(); +``` + +## Documentation + + + +[**OAuth Scopes Enums**](https://git.preuss.io/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php) + +## Development + +#### Run Tests + +```shell +composer test +``` + +```shell +CLIENT_ID=xxxx CLIENT_KEY=yyyy CLIENT_ACCESS_TOKEN=zzzz composer test +``` + +#### Generate Documentation + +```shell +composer docs +``` + +--- + +Join the bitinflow Discord! + +[![Discord](https://discordapp.com/api/guilds/373468864098336768/embed.png?style=banner2)](https://discord.gg/2ZrCe2h) \ No newline at end of file diff --git a/composer.json b/composer.json index de33ecf..8621d70 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ghostzero/bitinflow-accounts", - "description": "bitinflow Accounts Client for Laravel", + "description": "PHP bitinflow Accounts API Client for Laravel 5+", "license": "MIT", "authors": [ { @@ -30,7 +30,8 @@ } }, "scripts": { - "test": "vendor/bin/phpunit" + "test": "vendor/bin/phpunit", + "docs": "php generator/generate-docs.php" }, "extra": { "laravel": { diff --git a/generator/generate-docs.php b/generator/generate-docs.php new file mode 100644 index 0000000..05ad1c7 --- /dev/null +++ b/generator/generate-docs.php @@ -0,0 +1,83 @@ +map(function ($trait) { + + $title = str_replace('Trait', '', Arr::last(explode('\\', $trait))); + + $methods = []; + + $reflection = new ReflectionClass($trait); + + collect($reflection->getMethods()) + ->reject(function (ReflectionMethod $method) { + return $method->isAbstract(); + }) + ->reject(function (ReflectionMethod $method) { + return $method->isPrivate() || $method->isProtected(); + }) + ->reject(function (ReflectionMethod $method) { + return $method->isConstructor(); + }) + ->each(function (ReflectionMethod $method) use (&$methods, $title, $trait) { + + $declaration = collect($method->getModifiers())->map(function (int $modifier) { + return $modifier == ReflectionMethod::IS_PUBLIC ? 'public ' : ''; + })->join(' '); + + $declaration .= 'function '; + $declaration .= $method->getName(); + $declaration .= '('; + + $declaration .= collect($method->getParameters())->map(function (ReflectionParameter $parameter) { + + $parameterString = Arr::last(explode('\\', $parameter->getType()->getName())); + $parameterString .= ' '; + $parameterString .= '$'; + $parameterString .= $parameter->getName(); + + if ($parameter->isDefaultValueAvailable()) { + $parameterString .= ' = '; + $parameterString .= str_replace(PHP_EOL, '', var_export($parameter->getDefaultValue(), true)); + } + + return $parameterString; + + })->join(', '); + + $declaration .= ')'; + + $methods[] = $declaration; + }); + + return [$title, $methods]; + }) + ->map(function ($args) { + + list($title, $methods) = $args; + + $markdown = '### ' . $title; + $markdown .= PHP_EOL . PHP_EOL; + $markdown .= '```php'; + $markdown .= PHP_EOL; + + $markdown .= collect($methods)->each(function ($method) { + return $method; + })->implode(PHP_EOL); + + $markdown .= PHP_EOL; + $markdown .= '```'; + + return $markdown; + })->join(PHP_EOL . PHP_EOL); + +$content = file_get_contents(__DIR__ . '/../README.stub'); + +$content = str_replace('', $markdown, $content); + +file_put_contents(__DIR__ . '/../README.md', $content); \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 4edc35a..723c89e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,11 +15,6 @@ tests - - - - - src