-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vdhicts/feature/init
Initialize the API client
- Loading branch information
Showing
19 changed files
with
614 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: "" | ||
labels: bug | ||
assignees: dvdheiden | ||
|
||
--- | ||
|
||
## Describe the bug | ||
|
||
A clear and concise description of what the bug is. | ||
|
||
## Reproduction | ||
|
||
Steps to reproduce the behavior. | ||
|
||
## Expected behavior vs Actual behavior | ||
|
||
A clear and concise description of what you expected to happen. | ||
|
||
## Additional information | ||
|
||
Anything else you want to provide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: "" | ||
labels: feature | ||
assignees: dvdheiden | ||
|
||
--- | ||
|
||
## Goal | ||
|
||
A clear and concise description of what the problem is. Ex. I think this could be easier when... | ||
|
||
## Additional information | ||
|
||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changes | ||
|
||
Provide a summary of your changes. | ||
|
||
# Checks | ||
|
||
- [ ] The changelog is updated (when applicable) | ||
- [ ] The version is updated in `Client.php` (when applicable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Nuclino API Client | ||
|
||
on: [push] | ||
|
||
jobs: | ||
nuclino-api-client-tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '7.4' | ||
extensions: mbstring, intl | ||
|
||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress | ||
|
||
- name: Execute tests (Unit and Feature tests) via PHPUnit | ||
run: | | ||
vendor/bin/phpunit | ||
- name: Execute static analysis | ||
run: | | ||
vendor/bin/phpstan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
composer.lock | ||
/vendor/ | ||
/.idea/ | ||
/build/ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to | ||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Please note this changelog affects this package and not the | ||
Nuclino API. | ||
|
||
## [1.0.0] | ||
|
||
### Added | ||
|
||
- Add the initial Nuclino API implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,106 @@ | ||
# nuclino-api-client | ||
Client for the Nuclino API | ||
# Nuclino API Client | ||
|
||
Easy to use client for the API of [Nuclino](https://www.nuclino.com/). | ||
|
||
## Requirements | ||
|
||
This package requires at least PHP 7.4. | ||
|
||
## Installation | ||
|
||
This package can be used in any PHP project or with any framework. | ||
|
||
You can install the package via composer: | ||
|
||
`composer require vdhicts/nuclino-api-client` | ||
|
||
## Usage | ||
|
||
This package is just an easy client for using the Nuclino API. Please refer to the | ||
[API documentation](https://help.nuclino.com/d3a29686-api/) for more information about the responses. | ||
|
||
### Getting started | ||
|
||
```php | ||
// Initialize the API | ||
$api = new \Vdhicts\Nuclino\Nuclino($apiKey); | ||
|
||
// List the items | ||
$response = $api->listItems(); | ||
|
||
if ($response->ok()) { | ||
$response->json('data'); | ||
} | ||
``` | ||
|
||
### Handling errors | ||
|
||
A `Response` object will always be returned. See | ||
[Error handling](https://laravel.com/docs/8.x/http-client#error-handling) of the Http Client. | ||
|
||
```php | ||
if ($response->failed()) { | ||
var_dump($response->serverError()); | ||
} | ||
``` | ||
|
||
### Laravel | ||
|
||
This package can be easily used in any Laravel application. I would suggest adding your credentials to the `.env` file | ||
of the project: | ||
|
||
``` | ||
NUCLINO_API_KEY=apikey | ||
``` | ||
|
||
Next create a config file `nuclino.php` in `/config`: | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'api_key' => env('NUCLINO_API_KEY'), | ||
]; | ||
``` | ||
|
||
And provide the API key to the client: | ||
|
||
```php | ||
$api = new \Vdhicts\Nuclino\Nuclino(config('nuclino.api_key')); | ||
``` | ||
|
||
In the future I might make a Laravel specific package which uses this package. | ||
|
||
## Tests | ||
|
||
Unit tests are available in the `tests` folder. Run with: | ||
|
||
`composer test` | ||
|
||
When you want a code coverage report which will be generated in the `build/report` folder. Run with: | ||
|
||
`composer test-coverage` | ||
|
||
## Contribution | ||
|
||
Any contribution is welcome, but it should meet the PSR-12 standard and please create one pull request per feature/bug. | ||
In exchange, you will be credited as contributor on this page. | ||
|
||
## Security | ||
|
||
If you discover any security related issues in this or other packages of Vdhicts, please email info@vdhicts.nl instead | ||
of using the issue tracker. | ||
|
||
## Support | ||
|
||
This package isn't an official package from Nuclino, so they probably won't offer support for it. If you encounter a | ||
problem with this client or has a question about it, feel free to open an issue on GitHub. | ||
|
||
## License | ||
|
||
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). | ||
|
||
## About Vdhicts | ||
|
||
[Vdhicts](https://www.vdhicts.nl) is the name of my personal company for which I work as freelancer. Vdhicts develops | ||
and implements IT solutions for businesses and educational institutions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "vdhicts/nuclino-api-client", | ||
"description": "A client for the API of Nuclino", | ||
"keywords": [ | ||
"nuclino", | ||
"api", | ||
"client" | ||
], | ||
"homepage": "https://github.com/vdhicts/nuclino-api-client", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Dick van der Heiden", | ||
"email": "info@vdhicts.nl", | ||
"homepage": "https://www.vdhicts.nl", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.4|^8.0", | ||
"ext-json": "*", | ||
"guzzlehttp/guzzle": "^7.0", | ||
"illuminate/http": "^8.74", | ||
"illuminate/support": "^8.22" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^1.2", | ||
"phpunit/phpunit": "^9.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Vdhicts\\Nuclino\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Vdhicts\\Nuclino\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit --no-coverage", | ||
"test-coverage": "vendor/bin/phpunit", | ||
"analyse": "vendor/bin/phpstan" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
level: 5 | ||
paths: | ||
- src | ||
- tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="./build/report/"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Vdhicts\Nuclino\Endpoints; | ||
|
||
use Illuminate\Http\Client\Response; | ||
|
||
trait FileEndpoint | ||
{ | ||
public function getFile(string $id): Response | ||
{ | ||
return $this->get(sprintf('v0/files/%s', $id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Vdhicts\Nuclino\Endpoints; | ||
|
||
use Illuminate\Http\Client\Response; | ||
use Vdhicts\Nuclino\Models\Item; | ||
use Vdhicts\Nuclino\Support\RequestHelper; | ||
|
||
trait ItemEndpoint | ||
{ | ||
public function listItems( | ||
string $teamId = null, | ||
string $workspaceId = null, | ||
int $limit = 100, | ||
string $after = null | ||
): Response { | ||
if ($limit > 100) { | ||
$limit = 100; | ||
} | ||
|
||
return $this->get( | ||
RequestHelper::build('v0/items', [ | ||
'teamId' => $teamId, | ||
'workspaceId' => $workspaceId, | ||
'limit' => $limit, | ||
'after' => $after, | ||
]) | ||
); | ||
} | ||
|
||
public function searchItems( | ||
string $search, | ||
string $teamId = null, | ||
string $workspaceId = null, | ||
int $limit = 100 | ||
): Response { | ||
if ($limit > 100) { | ||
$limit = 100; | ||
} | ||
|
||
return $this->get( | ||
RequestHelper::build('v0/items', [ | ||
'teamId' => $teamId, | ||
'workspaceId' => $workspaceId, | ||
'limit' => $limit, | ||
'search' => $search, | ||
]) | ||
); | ||
} | ||
|
||
public function getItem(string $id): Response | ||
{ | ||
return $this->get(sprintf('v0/items/%s', $id)); | ||
} | ||
|
||
public function createItem(Item $item): Response | ||
{ | ||
return $this->post('v0/items', $item->toArray()); | ||
} | ||
|
||
public function updateItem(string $id, Item $item): Response | ||
{ | ||
return $this->put(sprintf('v0/items/%s', $id), $item->toArray()); | ||
} | ||
|
||
public function deleteItem(string $id): Response | ||
{ | ||
return $this->delete(sprintf('v0/items/%s', $id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Vdhicts\Nuclino\Endpoints; | ||
|
||
use Illuminate\Http\Client\Response; | ||
use Vdhicts\Nuclino\Support\RequestHelper; | ||
|
||
trait TeamEndpoint | ||
{ | ||
public function listTeams(int $limit = 100, string $after = null): Response | ||
{ | ||
if ($limit > 100) { | ||
$limit = 100; | ||
} | ||
|
||
return $this->get(RequestHelper::build('v0/teams', [ | ||
'limit' => $limit, | ||
'after' => $after, | ||
])); | ||
} | ||
|
||
public function getTeam(string $id): Response | ||
{ | ||
return $this->get(sprintf('v0/teams/%s', $id)); | ||
} | ||
} |
Oops, something went wrong.