Skip to content

Commit 7b94ead

Browse files
committed
Improve code examples in docs
1 parent c62cba7 commit 7b94ead

File tree

1 file changed

+106
-65
lines changed

1 file changed

+106
-65
lines changed

docs/usage.md

Lines changed: 106 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,26 @@ You can now use the `getApi()` method to create and get a specific Redmine API.
223223

224224
To check for failed requests you can afterwards check the status code via `$client->getLastResponseStatusCode()`.
225225

226+
#### Tracker API
227+
226228
```php
227-
// ----------------------------
228-
// Trackers
229+
229230
$client->getApi('tracker')->list();
230231
$client->getApi('tracker')->listing();
232+
```
231233

232-
// ----------------------------
233-
// Issue statuses
234+
#### IssueStatus API
235+
236+
```php
234237
$client->getApi('issue_status')->list();
235238
$client->getApi('issue_status')->listing();
236239
$client->getApi('issue_status')->getIdByName('New');
237240

238-
// ----------------------------
239-
// Project
241+
```
242+
243+
#### Project API
244+
245+
```php
240246
$client->getApi('project')->list();
241247
$client->getApi('project')->list([
242248
'limit' => 10,
@@ -258,9 +264,11 @@ $client->getApi('project')->reopen($projectId);
258264
$client->getApi('project')->archive($projectId);
259265
$client->getApi('project')->unarchive($projectId);
260266
$client->getApi('project')->remove($projectId);
267+
```
261268

262-
// ----------------------------
263-
// Users
269+
#### User API
270+
271+
```php
264272
$client->getApi('user')->list();
265273
$client->getApi('user')->listing();
266274
$client->getApi('user')->getCurrentUser([
@@ -290,9 +298,11 @@ $client->getApi('user')->create([
290298
'lastname' => 'test',
291299
'mail' => 'test@example.com',
292300
]);
301+
```
293302

294-
// ----------------------------
295-
// Issues
303+
#### Issue API
304+
305+
```php
296306
$client->getApi('issue')->show($issueId);
297307
$client->getApi('issue')->list([
298308
'limit' => 100,
@@ -377,8 +387,39 @@ $client->getApi('issue')->create([
377387
],
378388
]);
379389

380-
// ----------------------------
381-
// Issue categories
390+
// Issues' stats (see https://github.com/kbsali/php-redmine-api/issues/44)
391+
$issues['all'] = $client->getApi('issue')->list([
392+
'limit' => 1,
393+
'tracker_id' => 1,
394+
'status_id' => '*',
395+
])['total_count'];
396+
397+
$issues['opened'] = $client->getApi('issue')->list([
398+
'limit' => 1,
399+
'tracker_id' => 1,
400+
'status_id' => 'open',
401+
])['total_count'];
402+
403+
$issues['closed'] = $client->getApi('issue')->list([
404+
'limit' => 1,
405+
'tracker_id' => 1,
406+
'status_id' => 'closed',
407+
])['total_count'];
408+
409+
print_r($issues);
410+
/*
411+
Array
412+
(
413+
[all] => 8
414+
[opened] => 7
415+
[closed] => 1
416+
)
417+
*/
418+
```
419+
420+
#### IssueCategory API
421+
422+
```php
382423
$client->getApi('issue_category')->listByProject('project1');
383424
$client->getApi('issue_category')->listing($projectId);
384425
$client->getApi('issue_category')->show($categoryId);
@@ -393,9 +434,11 @@ $client->getApi('issue_category')->remove($categoryId);
393434
$client->getApi('issue_category')->remove($categoryId, [
394435
'reassign_to_id' => $userId,
395436
]);
437+
```
396438

397-
// ----------------------------
398-
// Versions
439+
#### Version API
440+
441+
```php
399442
$client->getApi('version')->listByProject('test');
400443
$client->getApi('version')->listing('test');
401444
$client->getApi('version')->show($versionId);
@@ -407,31 +450,41 @@ $client->getApi('version')->update($versionId, [
407450
'name' => 'v1121',
408451
]);
409452
$client->getApi('version')->remove($versionId);
453+
```
410454

411-
// ----------------------------
412-
// Attachments
455+
#### Attachment API
456+
457+
```php
413458
$client->getApi('attachment')->show($attachmentId);
414459

415460
$file_content = $client->getApi('attachment')->download($attachmentId);
416461
file_put_contents('example.png', $file_content);
462+
```
417463

418-
// ----------------------------
419-
// News
464+
#### News API
465+
466+
```php
420467
$client->getApi('news')->list();
421468
$client->getApi('news')->listByProject('test');
469+
```
422470

423-
// ----------------------------
424-
// Roles
471+
#### Role API
472+
473+
```php
425474
$client->getApi('role')->list();
426475
$client->getApi('role')->show(1);
427476
$client->getApi('role')->listing();
477+
```
428478

429-
// ----------------------------
430-
// Queries
479+
#### Query API
480+
481+
```php
431482
$client->getApi('query')->list();
483+
```
432484

433-
// ----------------------------
434-
// Time entries
485+
#### TimeEntry API
486+
487+
```php
435488
$client->getApi('time_entry')->list();
436489
$client->getApi('time_entry')->show($timeEntryId);
437490
$client->getApi('time_entry')->list([
@@ -471,19 +524,25 @@ $client->getApi('time_entry')->update($timeEntryId, [
471524
],
472525
]);
473526
$client->getApi('time_entry')->remove($timeEntryId);
527+
```
474528

475-
// ----------------------------
476-
// Time entry activities
529+
#### TimeEntryActivity API
530+
531+
```php
477532
$client->getApi('time_entry_activity')->list();
533+
```
478534

479-
// ----------------------------
480-
// Issue relations
535+
#### IssueRelation API
536+
537+
```php
481538
$client->getApi('issue_relation')->listByIssueId($issueId);
482539
$client->getApi('issue_relation')->show($issueRelationId);
483540
$client->getApi('issue_relation')->remove($issueRelationId);
541+
```
484542

485-
// ----------------------------
486-
// Group (of members)
543+
#### Group of members API
544+
545+
```php
487546
$client->getApi('group')->list();
488547
$client->getApi('group')->listing();
489548
$client->getApi('group')->show($groupId, ['include' => 'users,memberships']);
@@ -513,22 +572,28 @@ $client->getApi('group')->update($groupId, [
513572
],
514573
],
515574
]);
575+
```
516576

517-
// ----------------------------
518-
// Project memberships
577+
#### Project Membership API
578+
579+
```php
519580
$client->getApi('membership')->listByProject($projectId);
520581
$client->getApi('membership')->create($projectId, [
521582
'user_id' => 1,
522583
'role_ids' => [5],
523584
]);
524585
$client->getApi('membership')->remove($membershipId);
586+
```
525587

526-
// ----------------------------
527-
// Issue priorities
588+
#### IssuePriority API
589+
590+
```php
528591
$client->getApi('issue_priority')->list();
592+
```
529593

530-
// ----------------------------
531-
// Wiki
594+
#### Wiki API
595+
596+
```php
532597
$client->getApi('wiki')->listByProject('testProject');
533598
$client->getApi('wiki')->show('testProject', 'about');
534599
$client->getApi('wiki')->show('testProject', 'about', $version);
@@ -543,42 +608,18 @@ $client->getApi('wiki')->update('testProject', 'about', [
543608
'version' => null,
544609
]);
545610
$client->getApi('wiki')->remove('testProject', 'about');
611+
```
546612

547-
// ----------------------------
548-
// Issues' stats (see https://github.com/kbsali/php-redmine-api/issues/44)
549-
$issues['all'] = $client->getApi('issue')->list([
550-
'limit' => 1,
551-
'tracker_id' => 1,
552-
'status_id' => '*',
553-
])['total_count'];
554-
555-
$issues['opened'] = $client->getApi('issue')->list([
556-
'limit' => 1,
557-
'tracker_id' => 1,
558-
'status_id' => 'open',
559-
])['total_count'];
560-
561-
$issues['closed'] = $client->getApi('issue')->list([
562-
'limit' => 1,
563-
'tracker_id' => 1,
564-
'status_id' => 'closed',
565-
])['total_count'];
566-
567-
print_r($issues);
568-
/*
569-
Array
570-
(
571-
[all] => 8
572-
[opened] => 7
573-
[closed] => 1
574-
)
575-
*/
613+
#### Search API
576614

615+
```php
577616
// ----------------------------
578617
// Search
579618
$client->getApi('search')->search('Myproject', ['limit' => 100]);
580619
```
581620

621+
#### CustomField API
622+
582623
#### API entry points implementation state:
583624

584625
* :heavy_check_mark: Attachments

0 commit comments

Comments
 (0)