Skip to content

Commit 708c224

Browse files
committed
Init
0 parents  commit 708c224

8 files changed

+743
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
GitLab API
2+
==========
3+
4+
Balík slouží jako transportní vrstva mezi konkrétní aplikací a GitLabem.
5+
6+
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ů.
7+
8+
Požadavky typu `GET` se automaticky cachují na `12 hodin`, pokud není řečeno jinak.
9+
10+
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.
11+
12+
Instalace
13+
---------
14+
15+
Použijte příkaz Composeru:
16+
17+
```shell
18+
composer require baraja-core/gitlab-api
19+
```
20+
21+
Dále je potřeba nastavit konfiguraci služby pro Nette v NEON souboru.
22+
23+
Výchozí minimální konfigurace:
24+
25+
```yaml
26+
services:
27+
gitLabAPI:
28+
factory: Baraja\GitLabApi\GitLabApi(%gitLab.token%)
29+
30+
parameters:
31+
gitLab:
32+
token: 123-abcDEFghiJKL-789
33+
34+
tracy:
35+
bar:
36+
- Baraja\GitLabApi\GitLabApiPanel
37+
```
38+
39+
API token musíte vždy změnit pro Váš uživatelský účet!
40+
41+
Konfigurace
42+
-----------
43+
44+
Do sekce `parameters` je potřeba vložit defaultní API token pro spojení s GitLabem:
45+
46+
Příklad:
47+
48+
```neon
49+
parameters:
50+
gitLab:
51+
token: 123-abcDEFghiJKL-789
52+
```
53+
54+
Volitelně lze nastavit použití Nette Cache:
55+
56+
```yaml
57+
services:
58+
gitLabAPI:
59+
factory: Baraja\GitLabApi\GitLabApi(%gitLab.token%)
60+
setup:
61+
- setCache(@cache.storage)
62+
```
63+
64+
Propojení s vlastní GitLab instalací
65+
------------------------------------
66+
67+
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ě.
68+
69+
Předaným parametrem může být například řetězec `'https://gitlab.com/api/v4/'`.

common.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
gitLabAPI:
3+
factory: Baraja\GitLabApi\GitLabApi(%gitLab.token%)
4+
setup:
5+
- setCache(@cache.storage)
6+
7+
tracy:
8+
bar:
9+
- Baraja\GitLabApi\GitLabApiPanel

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "baraja-core/gitlab-api",
3+
"description": "Simple and robust GitLab API wrapper with Tracy debug mode.",
4+
"homepage": "https://github.com/baraja-core/gitlab-api",
5+
"authors": [
6+
{
7+
"name": "Jan Barášek",
8+
"homepage": "https://baraja.cz"
9+
}
10+
],
11+
"require": {
12+
"php": ">=7.1.0",
13+
"ext-curl": "*",
14+
"nette/caching": "^3.0"
15+
},
16+
"autoload": {
17+
"classmap": [
18+
"src/"
19+
]
20+
},
21+
"minimum-stability": "stable"
22+
}

src/Entity/ApiData.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Baraja\GitLabApi\Entity;
6+
7+
8+
use Baraja\GitLabApi\GitLabApiException;
9+
10+
class ApiData extends \stdClass implements \ArrayAccess, \Countable, \IteratorAggregate
11+
{
12+
13+
/**
14+
* @param mixed[] $arr
15+
* @param bool $recursive
16+
* @return ApiData
17+
*/
18+
public static function from(array $arr, bool $recursive = true): self
19+
{
20+
$obj = new self;
21+
22+
foreach ($arr as $key => $value) {
23+
if ($recursive && is_array($value)) {
24+
$obj->$key = static::from($value, true);
25+
} else {
26+
$obj->$key = $value;
27+
}
28+
}
29+
30+
return $obj;
31+
}
32+
33+
/**
34+
* Returns an iterator over all items.
35+
*/
36+
public function getIterator(): \RecursiveArrayIterator
37+
{
38+
return new \RecursiveArrayIterator((array) $this);
39+
}
40+
41+
/**
42+
* Returns items count.
43+
*/
44+
public function count(): int
45+
{
46+
return count((array) $this);
47+
}
48+
49+
/**
50+
* Replaces or appends a item.
51+
*
52+
* @param mixed $key
53+
* @param mixed $value
54+
* @throws GitLabApiException
55+
*/
56+
public function offsetSet($key, $value): void
57+
{
58+
if (!is_scalar($key)) { // prevents null
59+
throw new GitLabApiException('Key must be either a string or an integer, "' . gettype($key) . '" given.');
60+
}
61+
$this->$key = $value;
62+
}
63+
64+
/**
65+
* Returns a item.
66+
*
67+
* @return mixed
68+
*/
69+
public function offsetGet($key)
70+
{
71+
return $this->$key;
72+
}
73+
74+
/**
75+
* Determines whether a item exists.
76+
*/
77+
public function offsetExists($key): bool
78+
{
79+
return isset($this->$key);
80+
}
81+
82+
/**
83+
* Removes the element from this list.
84+
*/
85+
public function offsetUnset($key): void
86+
{
87+
unset($this->$key);
88+
}
89+
90+
}

0 commit comments

Comments
 (0)