Rest api with php » History » Version 6
Terence Mill, 2010-11-23 21:03
1 | 4 | Terence Mill | h1. Accessing Redmine beyond API with Redmine.module |
---|---|---|---|
2 | |||
3 | 6 | Terence Mill | Redmine.module provides a basic API to Redmine, a project tracking system. |
4 | |||
5 | Unfortunately Redmine's REST API is not sufficiently mature (at time of authoring) for the project that needed this module. Progress for this is on the roadmap for Redmine 1.1.0, and this module may be updated to use it. |
||
6 | |||
7 | Instead of using the REST API, Redmine.module provides access to the Redmine database from Drupal. |
||
8 | |||
9 | Redmine.module provides a and partially manages a profile.module field for user's Redmine User ID, as well as a Redmine database functions, redmine_query(), and redmine_write_record(). These are wrappers for Drupal's db_query() and drupal_write_record() functions. |
||
10 | |||
11 | There is also a function for saving (INSERT or UPDATE) Redmine time entries, redmine_time_entry_save(). |
||
12 | |||
13 | 5 | Terence Mill | "See original article here":http://drupal.org/project/redmine and "projects site":http://drupalmodules.com/module/redmine-api |
14 | 4 | Terence Mill | |
15 | 1 | Jean-Philippe Lang | h1. Using the REST API with PHP |
16 | |||
17 | 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: |
18 | 1 | Jean-Philippe Lang | |
19 | <pre> |
||
20 | 3 | Azamat Hackimov | <code class="php"> |
21 | 1 | Jean-Philippe Lang | <?php |
22 | require_once ('ActiveResource.php'); |
||
23 | |||
24 | class Issue extends ActiveResource { |
||
25 | var $site = 'http://username:password@192.168.199.129:3000/'; |
||
26 | var $request_format = 'xml'; // REQUIRED! |
||
27 | } |
||
28 | |||
29 | // create a new issue |
||
30 | $issue = new Issue (array ('subject' => 'XML REST API', 'project_id' => '1')); |
||
31 | $issue->save (); |
||
32 | 2 | Jean-Philippe Lang | echo $issue->id; |
33 | 1 | Jean-Philippe Lang | |
34 | // find issues |
||
35 | $issues = $issue->find ('all'); |
||
36 | for ($i=0; $i < count($issues); $i++) { |
||
37 | echo $issues[$i]->subject; |
||
38 | } |
||
39 | |||
40 | // find and update an issue |
||
41 | $issue->find (1); |
||
42 | echo $issue->subject; |
||
43 | $issue->set ('subject', 'This is the new subject')->save (); |
||
44 | |||
45 | // delete an issue |
||
46 | $issue->find (1); |
||
47 | $issue->destroy (); |
||
48 | ?> |
||
49 | 3 | Azamat Hackimov | </code> |
50 | 1 | Jean-Philippe Lang | </pre> |