You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Create Psr18Client
* Create interfaces for Client and Api
Move Api instantiation into trait
* Issue Api uses getApi on client
* Add new request methods to ClientInterface
* Add tests for new ClientInterface methods
* Add test for requestGet method
* Test Request created by client
* Move tests for request generation into integration test
* Improve integration tests
* Move clients into own namespace, rename interfaces
* Implement auth with username:pwd or access key
* move Api interface
* add content-type header
* Let AbstractApi consume new Client interface
Move json- and XML-decoding into AbtractApi
Fix and improve all tests
* test exception messages
* Implement impersonate user
* Test correct response data in client
* Add tests for AbstractApi
* Add tests for decoding in AbstractApi
Simplify error messages in JSON decoding
* Test XML decoding on post, put and delete requests
* Add integration tests for POST, PUT and DELETE
* Test file upload with content and file path
* Remove debug code
* Update example.php to use new client interface
* Update README.md
* Create usage docs
* Add docs for user impersonation and curl options, improve language
* Improve AbstractApi, remove obvious docblocks
rename $data to $body
rename $decode to $decodeIfJson
* Rephrase trait description, add @internal
* Update manual installation, link to docs
* Add tests for get api over magic getter
* Update requirements in README.md
* Move usage docs into README.md
at the root of their projects. To utilize the library, include
@@ -74,6 +74,7 @@ For example,
74
74
<?php
75
75
// This file is generated by Composer
76
76
require_once 'vendor/autoload.php';
77
+
77
78
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
78
79
```
79
80
@@ -82,25 +83,23 @@ $client = new Redmine\Client('http://redmine.example.com', 'username', 'password
82
83
It is also possible to install the library oneself, either locally to
83
84
a project or globally; say, in `/usr/share/php`.
84
85
85
-
First, download and extract the library somewhere. For example, the
86
-
following steps extract v1.5.18 of the library into the
87
-
`vendor/php-redmine-api-1.5.18` directory:
86
+
Download the library from [php-download.com](https://php-download.com/package/kbsali/redmine-api). The advantage of using this site is that no Composer installation is required. This service will resolve all composer dependencies for you and create a zip archive with `vendor/autoload.php` for you.
87
+
88
+
Than extract the library somewhere. For example, the following steps extract v1.6.0 of the library into the `vendor/php-redmine-api-1.6.0` directory:
- a `Psr\Http\Client\ClientInterface` implementation (like guzzlehttp/guzzle), [see](https://packagist.org/providers/psr/http-client-implementation)
198
+
- a `Psr\Http\Message\ServerRequestFactoryInterface` implementation (like nyholm/psr7), [see](https://packagist.org/providers/psr/http-factory-implementation)
199
+
- a `Psr\Http\Message\StreamFactoryInterface` implementation (like nyholm/psr7), [see](https://packagist.org/providers/psr/http-message-implementation)
200
+
- a URL to your Redmine instance
201
+
- an Apikey or username
202
+
- and optional a password if you want tu use username/password.
203
+
204
+
> :bulb: For security reason it is recommended that you use an ApiKey rather than your username/password.
205
+
206
+
```diff
207
+
<?php
208
+
209
+
require_once 'vendor/autoload.php';
210
+
+
211
+
+$guzzle = \GuzzleHttp\Client();
212
+
+$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
213
+
+
214
+
+// Instantiate with ApiKey
215
+
+$client = new Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
216
+
+// ...or Instantiate with Username/Password (not recommended)
217
+
+$client = new Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', 'username', 'password');
218
+
```
219
+
220
+
##### Guzzle configuration
221
+
222
+
Because the `Psr18Client` is agnostic about the HTTP client implementation every configuration specific to the transport has to be set to the `Psr\Http\Client\ClientInterface` implementation.
223
+
224
+
This means that if you want to set any `cURL` settings to `Guzzle` you have multiple ways to set them:
225
+
226
+
1. Using [Guzzle environment variables](https://docs.guzzlephp.org/en/stable/quickstart.html#environment-variables)
227
+
2. Using [request options](https://docs.guzzlephp.org/en/stable/request-options.html) inside a `Psr\Http\Client\ClientInterface` wrapper:
228
+
229
+
```diff
230
+
<?php
231
+
232
+
require_once 'vendor/autoload.php';
233
+
234
+
+use Psr\Http\Client\ClientInterface;
235
+
+use Psr\Http\Message\RequestInterface;
236
+
+use Psr\Http\Message\ResponseInterface;
237
+
+
238
+
$guzzle = \GuzzleHttp\Client();
239
+
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
240
+
241
+
+$guzzleWrapper = new class(\GuzzleHttp\Client $guzzle) implements ClientInterface
242
+
+{
243
+
+ private $guzzle;
244
+
+
245
+
+ public function __construct(\GuzzleHttp\Client $guzzle)
246
+
+ {
247
+
+ $this->guzzle = $guzzle;
248
+
+ }
249
+
+
250
+
+ public function sendRequest(RequestInterface $request): ResponseInterface
251
+
+ {
252
+
+ return $this->guzzle->send($request, [
253
+
+ // Set the options for every request here
254
+
+ 'auth' => ['username', 'password', 'digest'],
255
+
+ 'cert' => ['/path/server.pem', 'password'],
256
+
+ 'connect_timeout' => 3.14,
257
+
+ // Set specific CURL options, see https://docs.guzzlephp.org/en/stable/faq.html#how-can-i-add-custom-curl-options
258
+
+ 'curl' => [
259
+
+ CURLOPT_SSL_VERIFYPEER => 1,
260
+
+ CURLOPT_SSL_VERIFYHOST => 2,
261
+
+ CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2,
262
+
+ ],
263
+
+ ]);
264
+
+ }
265
+
+};
266
+
+
267
+
// Instantiate with ApiKey
268
+
-$client = new Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
269
+
+$client = new Redmine\Client\Prs18Client($guzzleWrapper, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
270
+
271
+
```
272
+
273
+
## Built-in Redmine features
274
+
275
+
### Impersonate User
276
+
277
+
Redmine allows you [to impersonate another user](https://www.redmine.org/projects/redmine/wiki/Rest_api#User-Impersonation). This can be done using the methods `startImpersonateUser()` and `stopImpersonateUser()`.
278
+
279
+
```php
280
+
$client->startImpersonateUser('kim');
281
+
// all requests will now impersonate the user `kim`
282
+
283
+
// To stop impersonation
284
+
$client->stopImpersonateUser();
285
+
```
286
+
287
+
### API usage
288
+
289
+
You can now use the `getApi()` method to create and get a specific Redmine API.
290
+
291
+
```php
292
+
<?php
293
+
294
+
$client->getApi('user')->all();
295
+
$client->getApi('user')->listing();
145
296
146
-
$client->issue->create([
297
+
$client->getApi('issue')->create([
147
298
'project_id' => 'test',
148
299
'subject' => 'some subject',
149
300
'description' => 'a long description blablabla',
150
301
'assigned_to_id' => 123, // or 'assigned_to' => 'user1'
151
302
]);
152
-
$client->issue->all([
303
+
$client->getApi('issue')->all([
153
304
'limit' => 1000
154
305
]);
155
306
```
156
307
157
-
See `example.php` for further examples.
308
+
See `[example.php](example.php)` for further examples.
158
309
159
310
## User Impersonation
160
311
@@ -165,13 +316,13 @@ As of Redmine V2.2 you can impersonate user through the REST API :
165
316
$client = new Redmine\Client('http://redmine.example.com', 'API_ACCESS_KEY');
0 commit comments