-
-
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.
- Loading branch information
0 parents
commit 708c224
Showing
8 changed files
with
743 additions
and
0 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,69 @@ | ||
GitLab API | ||
========== | ||
|
||
Balík slouží jako transportní vrstva mezi konkrétní aplikací a GitLabem. | ||
|
||
Pomocí tohoto balíku můžete jednoduchým způsobem pokládat dotazy do GitLabu, detekovat chybové hlášení v Tracy baru a sledovat vytížení požadavků. | ||
|
||
Požadavky typu `GET` se automaticky cachují na `12 hodin`, pokud není řečeno jinak. | ||
|
||
Požadavky typu `POST`, `PUT`, `DELETE` a další změnové akce se necachují vůbec a vždy přenášíme veškerá data znovu. | ||
|
||
Instalace | ||
--------- | ||
|
||
Použijte příkaz Composeru: | ||
|
||
```shell | ||
composer require baraja-core/gitlab-api | ||
``` | ||
|
||
Dále je potřeba nastavit konfiguraci služby pro Nette v NEON souboru. | ||
|
||
Výchozí minimální konfigurace: | ||
|
||
```yaml | ||
services: | ||
gitLabAPI: | ||
factory: Baraja\GitLabApi\GitLabApi(%gitLab.token%) | ||
|
||
parameters: | ||
gitLab: | ||
token: 123-abcDEFghiJKL-789 | ||
|
||
tracy: | ||
bar: | ||
- Baraja\GitLabApi\GitLabApiPanel | ||
``` | ||
|
||
API token musíte vždy změnit pro Váš uživatelský účet! | ||
|
||
Konfigurace | ||
----------- | ||
|
||
Do sekce `parameters` je potřeba vložit defaultní API token pro spojení s GitLabem: | ||
|
||
Příklad: | ||
|
||
```neon | ||
parameters: | ||
gitLab: | ||
token: 123-abcDEFghiJKL-789 | ||
``` | ||
|
||
Volitelně lze nastavit použití Nette Cache: | ||
|
||
```yaml | ||
services: | ||
gitLabAPI: | ||
factory: Baraja\GitLabApi\GitLabApi(%gitLab.token%) | ||
setup: | ||
- setCache(@cache.storage) | ||
``` | ||
Propojení s vlastní GitLab instalací | ||
------------------------------------ | ||
V některých případech je potřeba propojit API na vnitřní firemní síť, kde je GitLab hostován. K tomu slouží metoda `setBaseUrl()` s cestou k doméně. | ||
|
||
Předaným parametrem může být například řetězec `'https://gitlab.com/api/v4/'`. |
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,9 @@ | ||
services: | ||
gitLabAPI: | ||
factory: Baraja\GitLabApi\GitLabApi(%gitLab.token%) | ||
setup: | ||
- setCache(@cache.storage) | ||
|
||
tracy: | ||
bar: | ||
- Baraja\GitLabApi\GitLabApiPanel |
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,22 @@ | ||
{ | ||
"name": "baraja-core/gitlab-api", | ||
"description": "Simple and robust GitLab API wrapper with Tracy debug mode.", | ||
"homepage": "https://github.com/baraja-core/gitlab-api", | ||
"authors": [ | ||
{ | ||
"name": "Jan Barášek", | ||
"homepage": "https://baraja.cz" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1.0", | ||
"ext-curl": "*", | ||
"nette/caching": "^3.0" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"src/" | ||
] | ||
}, | ||
"minimum-stability": "stable" | ||
} |
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,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\GitLabApi\Entity; | ||
|
||
|
||
use Baraja\GitLabApi\GitLabApiException; | ||
|
||
class ApiData extends \stdClass implements \ArrayAccess, \Countable, \IteratorAggregate | ||
{ | ||
|
||
/** | ||
* @param mixed[] $arr | ||
* @param bool $recursive | ||
* @return ApiData | ||
*/ | ||
public static function from(array $arr, bool $recursive = true): self | ||
{ | ||
$obj = new self; | ||
|
||
foreach ($arr as $key => $value) { | ||
if ($recursive && is_array($value)) { | ||
$obj->$key = static::from($value, true); | ||
} else { | ||
$obj->$key = $value; | ||
} | ||
} | ||
|
||
return $obj; | ||
} | ||
|
||
/** | ||
* Returns an iterator over all items. | ||
*/ | ||
public function getIterator(): \RecursiveArrayIterator | ||
{ | ||
return new \RecursiveArrayIterator((array) $this); | ||
} | ||
|
||
/** | ||
* Returns items count. | ||
*/ | ||
public function count(): int | ||
{ | ||
return count((array) $this); | ||
} | ||
|
||
/** | ||
* Replaces or appends a item. | ||
* | ||
* @param mixed $key | ||
* @param mixed $value | ||
* @throws GitLabApiException | ||
*/ | ||
public function offsetSet($key, $value): void | ||
{ | ||
if (!is_scalar($key)) { // prevents null | ||
throw new GitLabApiException('Key must be either a string or an integer, "' . gettype($key) . '" given.'); | ||
} | ||
$this->$key = $value; | ||
} | ||
|
||
/** | ||
* Returns a item. | ||
* | ||
* @return mixed | ||
*/ | ||
public function offsetGet($key) | ||
{ | ||
return $this->$key; | ||
} | ||
|
||
/** | ||
* Determines whether a item exists. | ||
*/ | ||
public function offsetExists($key): bool | ||
{ | ||
return isset($this->$key); | ||
} | ||
|
||
/** | ||
* Removes the element from this list. | ||
*/ | ||
public function offsetUnset($key): void | ||
{ | ||
unset($this->$key); | ||
} | ||
|
||
} |
Oops, something went wrong.