Rest api with php » History » Version 4
Terence Mill, 2010-11-23 21:02
1 | 4 | Terence Mill | h1. Accessing Redmine beyond API with Redmine.module |
---|---|---|---|
2 | |||
3 | "See original article here":http://drupal.org/project/redmine |
||
4 | |||
5 | 1 | Jean-Philippe Lang | h1. Using the REST API with PHP |
6 | |||
7 | 2 | Jean-Philippe Lang | Here is an example that uses "PHP ActiveResource":http://wiki.github.com/lux/phpactiveresource/, a lightweight PHP library that can be used to access Rails' REST APIs: |
8 | 1 | Jean-Philippe Lang | |
9 | <pre> |
||
10 | 3 | Azamat Hackimov | <code class="php"> |
11 | 1 | Jean-Philippe Lang | <?php |
12 | require_once ('ActiveResource.php'); |
||
13 | |||
14 | class Issue extends ActiveResource { |
||
15 | var $site = 'http://username:password@192.168.199.129:3000/'; |
||
16 | var $request_format = 'xml'; // REQUIRED! |
||
17 | } |
||
18 | |||
19 | // create a new issue |
||
20 | $issue = new Issue (array ('subject' => 'XML REST API', 'project_id' => '1')); |
||
21 | $issue->save (); |
||
22 | 2 | Jean-Philippe Lang | echo $issue->id; |
23 | 1 | Jean-Philippe Lang | |
24 | // find issues |
||
25 | $issues = $issue->find ('all'); |
||
26 | for ($i=0; $i < count($issues); $i++) { |
||
27 | echo $issues[$i]->subject; |
||
28 | } |
||
29 | |||
30 | // find and update an issue |
||
31 | $issue->find (1); |
||
32 | echo $issue->subject; |
||
33 | $issue->set ('subject', 'This is the new subject')->save (); |
||
34 | |||
35 | // delete an issue |
||
36 | $issue->find (1); |
||
37 | $issue->destroy (); |
||
38 | ?> |
||
39 | 3 | Azamat Hackimov | </code> |
40 | 1 | Jean-Philippe Lang | </pre> |