|
1 | | -# PHP GitHub API |
| 1 | +# PHP ArgoCD API Client |
2 | 2 |
|
3 | | - |
4 | | -[](https://styleci.io/repos/3948501) |
5 | | -[](https://packagist.org/packages/knplabs/github-api) |
6 | | -[](https://packagist.org/packages/knplabs/github-api) |
7 | | -[](https://packagist.org/packages/knplabs/github-api) |
8 | | -[](https://packagist.org/packages/knplabs/github-api) |
| 3 | +[](https://github.com/your-vendor/argocd-php-client/actions/workflows/ci.yml) <!-- Placeholder CI Badge --> |
| 4 | +[](https://packagist.org/packages/your-vendor/argocd-php-client) <!-- Placeholder Packagist Badge --> |
| 5 | +[](https://packagist.org/packages/your-vendor/argocd-php-client) <!-- Placeholder Packagist Badge --> |
9 | 6 |
|
10 | | -A simple Object Oriented wrapper for GitHub API, written with PHP. |
| 7 | +A PHP client for interacting with the ArgoCD API. This library provides an object-oriented interface to the ArgoCD REST API. |
11 | 8 |
|
12 | | -Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4](http://developer.github.com/v4). The object API (v3) is very similar to the RESTful API. |
| 9 | +This client's structure is based on the [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api) library. |
| 10 | + |
| 11 | +For more context on the AI-assisted development process of this library, please see [AI.md](AI.md). |
13 | 12 |
|
14 | 13 | ## Features |
15 | 14 |
|
16 | | -* Light and fast thanks to lazy loading of API classes |
17 | | -* Extensively tested and documented |
| 15 | +* Light and fast thanks to lazy loading of API classes. |
| 16 | +* Object-oriented interface to the ArgoCD API. |
18 | 17 |
|
19 | 18 | ## Requirements |
20 | 19 |
|
21 | | -* PHP >= 7.2 |
22 | | -* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) |
23 | | -* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation) |
| 20 | +* PHP ^8.3 |
| 21 | +* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) (e.g., `nyholm/psr7`) |
| 22 | +* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation) (e.g., `symfony/http-client` or `guzzlehttp/guzzle`) |
24 | 23 |
|
25 | 24 | ## Quick install |
26 | 25 |
|
27 | 26 | Via [Composer](https://getcomposer.org). |
28 | 27 |
|
29 | | -This command will get you up and running quickly with a Guzzle HTTP client. |
30 | | - |
31 | 28 | ```bash |
32 | | -composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 |
| 29 | +composer require your-vendor/argocd-php-client |
33 | 30 | ``` |
34 | 31 |
|
35 | | -## Advanced install |
36 | | - |
37 | | -We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io). |
38 | | - |
39 | | -### Using a different http client |
| 32 | +You will also need to install implementations for PSR-17 (HTTP Factories) and PSR-18 (HTTP Client), for example: |
40 | 33 |
|
41 | 34 | ```bash |
42 | | -composer require knplabs/github-api:^3.0 symfony/http-client nyholm/psr7 |
43 | | -``` |
44 | | - |
45 | | -To set up the Github client with this HTTP client |
46 | | - |
47 | | -```php |
48 | | -use Github\Client; |
49 | | -use Symfony\Component\HttpClient\HttplugClient; |
50 | | - |
51 | | -$client = Client::createWithHttpClient(new HttplugClient()); |
| 35 | +composer require symfony/http-client nyholm/psr7 |
52 | 36 | ``` |
53 | | - |
54 | | -Read more about [using different clients in our docs](doc/customize.md). |
55 | | - |
56 | | -## Framework integrations |
57 | | - |
58 | | -### Laravel |
59 | | - |
60 | | -To integrate this library in laravel [Graham Campbell](https://github.com/GrahamCampbell) created [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub). See the [installation instructions](https://github.com/GrahamCampbell/Laravel-GitHub#installation) to get started in laravel. |
61 | | - |
62 | | -## Basic usage of `php-github-api` client |
63 | | - |
64 | | -```php |
65 | | -<?php |
66 | | - |
67 | | -// This file is generated by Composer |
68 | | -require_once __DIR__ . '/vendor/autoload.php'; |
69 | | - |
70 | | -$client = new \Github\Client(); |
71 | | -$repositories = $client->api('user')->repositories('ornicar'); |
| 37 | +Or for Guzzle: |
| 38 | +```bash |
| 39 | +composer require guzzlehttp/guzzle php-http/guzzle7-adapter |
72 | 40 | ``` |
73 | 41 |
|
74 | | -From `$client` object, you have access to all available GitHub api endpoints. |
75 | | - |
76 | | -## Cache usage |
77 | | - |
78 | | -This example uses the PSR6 cache pool [redis-adapter](https://github.com/php-cache/redis-adapter). See http://www.php-cache.com/ for alternatives. |
| 42 | +## Basic Usage |
79 | 43 |
|
80 | 44 | ```php |
81 | 45 | <?php |
82 | 46 |
|
83 | 47 | // This file is generated by Composer |
84 | 48 | require_once __DIR__ . '/vendor/autoload.php'; |
85 | 49 |
|
86 | | -use Cache\Adapter\Redis\RedisCachePool; |
87 | | - |
88 | | -$client = new \Redis(); |
89 | | -$client->connect('127.0.0.1', 6379); |
90 | | -// Create a PSR6 cache pool |
91 | | -$pool = new RedisCachePool($client); |
92 | | - |
93 | | -$client = new \Github\Client(); |
94 | | -$client->addCache($pool); |
95 | | - |
96 | | -// Do some request |
97 | | - |
98 | | -// Stop using cache |
99 | | -$client->removeCache(); |
| 50 | +// 1. Instantiate the client with your ArgoCD server URL |
| 51 | +// Ensure your ArgoCD server URL is correct and accessible. |
| 52 | +// The client will automatically append /api/v1 if it's not present. |
| 53 | +$client = new ArgoCD\Client('https://your-argocd-server.example.com'); |
| 54 | + |
| 55 | +// 2. Authenticate |
| 56 | +// Option A: Using username and password (fetches a token via SessionService) |
| 57 | +try { |
| 58 | + $client->authenticate('your-username', 'your-password'); |
| 59 | + echo "Successfully authenticated using username/password. Token: " . substr($client->getToken() ?? 'N/A', 0, 10) . "...\n"; |
| 60 | +} catch (ArgoCD\Exception\RuntimeException $e) { |
| 61 | + die('Authentication failed: ' . $e->getMessage() . "\n"); |
| 62 | +} |
| 63 | + |
| 64 | +// Option B: Using a pre-existing token |
| 65 | +// try { |
| 66 | +// $client->authenticate('your-argocd-api-token'); |
| 67 | +// echo "Successfully authenticated using pre-existing token.\n"; |
| 68 | +// } catch (ArgoCD\Exception\InvalidArgumentException $e) { |
| 69 | +// die('Authentication failed with token: ' . $e->getMessage() . "\n"); |
| 70 | +// } |
| 71 | + |
| 72 | + |
| 73 | +// 3. Access API services |
| 74 | +try { |
| 75 | + // Example: Get user info |
| 76 | + $userInfo = $client->sessionService()->getUserInfo(); |
| 77 | + echo "Logged in as: " . $userInfo->getUsername() . "\n"; |
| 78 | + echo "Logged in status: " . ($userInfo->isLoggedIn() ? 'true' : 'false') . "\n"; |
| 79 | + |
| 80 | + // Example: List accounts (requires admin privileges typically) |
| 81 | + // Note: Ensure the authenticated user has permissions for these operations. |
| 82 | + // try { |
| 83 | + // $accountsList = $client->accountService()->listAccounts(); |
| 84 | + // echo "Listing accounts:\n"; |
| 85 | + // if (count($accountsList->getItems()) > 0) { |
| 86 | + // foreach ($accountsList->getItems() as $account) { |
| 87 | + // echo " - Account Name: " . $account->getName() . ", Enabled: " . ($account->isEnabled() ? 'Yes' : 'No') . "\n"; |
| 88 | + // } |
| 89 | + // } else { |
| 90 | + // echo "No accounts found or not enough permissions.\n"; |
| 91 | + // } |
| 92 | + // } catch (ArgoCD\Exception\RuntimeException $e) { |
| 93 | + // echo "Could not list accounts: " . $e->getMessage() . "\n"; |
| 94 | + // } |
| 95 | + |
| 96 | + |
| 97 | +} catch (ArgoCD\Exception\RuntimeException $e) { |
| 98 | + die('API Error: ' . $e->getMessage() . "\n"); |
| 99 | +} |
| 100 | + |
| 101 | +// Example: Delete the session (logout) |
| 102 | +// try { |
| 103 | +// $client->sessionService()->delete(); |
| 104 | +// echo "Successfully logged out.\n"; |
| 105 | +// } catch (ArgoCD\Exception\RuntimeException $e) { |
| 106 | +// die('Logout failed: ' . $e->getMessage() . "\n"); |
| 107 | +// } |
| 108 | + |
| 109 | +?> |
100 | 110 | ``` |
101 | 111 |
|
102 | | -Using cache, the client will get cached responses if resources haven't changed since last time, |
103 | | -**without** reaching the `X-Rate-Limit` [imposed by github](http://developer.github.com/v3/#rate-limiting). |
104 | | - |
105 | | - |
106 | 112 | ## Documentation |
107 | 113 |
|
108 | | -See the [`doc` directory](doc/) for more detailed documentation. |
| 114 | +Further documentation will be available as the library matures. For now, refer to the source code and the official [ArgoCD API documentation](https://cd.apps.argoproj.io/swagger-ui) (or the `reference/argocd_swagger.json` file in this repository). |
109 | 115 |
|
110 | 116 | ## License |
111 | 117 |
|
112 | | -`php-github-api` is licensed under the MIT License - see the LICENSE file for details |
| 118 | +This library is licensed under the MIT License - see the LICENSE file for details. |
113 | 119 |
|
114 | 120 | ## Maintainers |
115 | 121 |
|
116 | | -Please read [this post](https://knplabs.com/en/blog/news-for-our-foss-projects-maintenance) first. |
117 | | - |
118 | | -This library is maintained by the following people (alphabetically sorted) : |
119 | | -- [@acrobat](https://github.com/acrobat) |
120 | | -- [@Nyholm](https://github.com/Nyholm) |
| 122 | +This library is currently maintained by: |
| 123 | +- [Your Name](https://github.com/your-vendor) (or your GitHub username) |
121 | 124 |
|
122 | 125 | ## Contributors |
123 | 126 |
|
124 | | -- Thanks to [Thibault Duplessis aka. ornicar](https://github.com/ornicar) for his first version of this library. |
125 | | -- Thanks to [Joseph Bielawski aka. stloyd](https://github.com/stloyd) for his contributions and support. |
126 | | -- Thanks to [noloh](https://github.com/noloh) for his contribution on the Object API. |
127 | | -- Thanks to [bshaffer](https://github.com/bshaffer) for his contribution on the Repo API. |
128 | | -- Thanks to [Rolf van de Krol](https://github.com/rolfvandekrol) for his countless contributions. |
129 | | -- Thanks to [Nicolas Pastorino](https://github.com/jeanvoye) for his contribution on the Pull Request API. |
130 | | -- Thanks to [Edoardo Rivello](https://github.com/erivello) for his contribution on the Gists API. |
131 | | -- Thanks to [Miguel Piedrafita](https://github.com/m1guelpf) for his contribution to the v4 & Apps API. |
132 | | -- Thanks to [Emre DEGER](https://github.com/lexor) for his contribution to the Actions API. |
133 | | - |
134 | | -Thanks to GitHub for the high quality API and documentation. |
| 127 | +* This project was significantly bootstrapped with the assistance of an AI agent. See [AI.md](AI.md) for more details. |
| 128 | +* Structure and patterns inspired by [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api). |
| 129 | +* Thanks to the ArgoCD team for their excellent API and documentation. |
| 130 | +``` |
0 commit comments