Project

General

Profile

Rest api with php » History » Revision 6

Revision 5 (Terence Mill, 2010-11-23 21:03) → Revision 6/14 (Terence Mill, 2010-11-23 21:03)

h1. Accessing Redmine beyond API with Redmine.module 

 Redmine.module provides a basic API to Redmine, a project tracking system. 

 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. 

 Instead of using the REST API, Redmine.module provides access to the Redmine database from Drupal. 

 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. 

 There is also a function for saving (INSERT or UPDATE) Redmine time entries, redmine_time_entry_save(). 

 "See original article here":http://drupal.org/project/redmine and "projects site":http://drupalmodules.com/module/redmine-api 

 h1. Using the REST API with PHP 

 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: 

 <pre> 
 <code class="php"> 
 <?php 
 require_once ('ActiveResource.php'); 

 class Issue extends ActiveResource { 
     var $site = 'http://username:password@192.168.199.129:3000/'; 
     var $request_format = 'xml'; // REQUIRED! 
 } 

 // create a new issue 
 $issue = new Issue (array ('subject' => 'XML REST API', 'project_id' => '1')); 
 $issue->save (); 
 echo $issue->id; 

 // find issues 
 $issues = $issue->find ('all'); 
 for ($i=0; $i < count($issues); $i++) { 
	 echo $issues[$i]->subject; 
 } 

 // find and update an issue 
 $issue->find (1); 
 echo $issue->subject; 
 $issue->set ('subject', 'This is the new subject')->save (); 

 // delete an issue 
 $issue->find (1); 
 $issue->destroy (); 
 ?> 
 </code> 
 </pre>