<code>Following is simple curl call for php with redmine.
**flie class file in redmine/redmine_curl.php**
<?php # Redmine Api
class class_redmine{
function get_upload_token($filecontent){
global $redmine_url , $redmine_key;
$upload_url = $redmine_url.'uploads.json?key='.$redmine_key;
$request['type'] = 'post';
$request['content_type'] = 'application/octet-stream';
//$filecontent = file_get_contents('test.php');
return $token = $this->curl_redmine($upload_url,$request,$filecontent);
//$token->upload->token;
}
#Issue
function create_issue($post_data){
global $redmine_url , $redmine_key;
$issue_url = $redmine_url.'issues.json?key='.$redmine_key;
$request['type'] = 'post';
$request['content_type'] = 'application/json';
return $this->curl_redmine($issue_url,$request,$post_data);
}
function get_issue($issue_id='',$project_id=''){
global $redmine_url , $redmine_key;
if($project_id!=''){
$issue_url = $redmine_url.'issues.json?key='.$redmine_key.'&project_id='.$project_id;
}else{ $issue_url = ($issue_id=='')?$redmine_url.'issues.json?key='.$redmine_key : $redmine_url.'issues/'.$issue_id.'.json?key='.$redmine_key;
}
return $this->curl_redmine($issue_url,'','');
}
#Projects
function get_projects($project_id=''){
global $redmine_url , $redmine_key;
$proj_url = ($project_id=='')?$redmine_url.'projects.json?key='.$redmine_key : $redmine_url.'projects/'.$project_id.'.json?key='.$redmine_key;
return $this->curl_redmine($proj_url,'','');
}
#Curl
function curl_redmine($redmine_url,$request='',$post_data=''){
if(!isset($request['type'])){ $request['type']=null; }
if(!isset($request['content_type'])){ $request['content_type']=null; }
//Create a curl object
$ch = curl_init();
//Set the useragent
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $redmine_url );
if($request['type'] == 'post'){
//This is a POST query
curl_setopt($ch, CURLOPT_POST,1);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: '.$request['content_type'],
'Content-Length: ' . strlen($post_data))
);
}
//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/
//curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Execute the action to login
$postResult = curl_exec($ch);
//if($postResult == false){ return $info = curl_getinfo($ch);}
$response = json_decode($postResult);
//echo '<pre>'; print_r($response); echo '
';
вернуть $ response;
}
} // class_redmine
?>
** Пример файла example.php **
<? PHP
// код для class_settting.php
функция get_redmine ($ methodName = '', $ data = '') {
global $ redmine_url, $ redmine_key;
// $ query = 'select * from' .VIS_TABLE_PREFIX.'integration, гдеgration_type = 37 и is_enabled = 1 и domain_id = '. VIS_DOMAIN;
// $ res = $ this-> database-> query_exec ($ query);
// $ login_integrate = $ this-> database-> fetch_result_array ($ Рез);
/ * if ($ login_integrate == - 1) {return $ login_integrate; }
if (count ($ login_integrate)> 0 && $ login_integrate! = - 1) {
$ redmine_url = $ login_integrate [0] ['billing_url'];
$ redmine_username = $ login_integrate [0] ['admin_user'];
$ redmine_password = $ login_integrate [0] ['admin_password'];
$ redmine_key = $ login_integrate [0] ['api_key'];
} * /
$ redmine_url = 'http://localhost/redmine/';
$ redmine_key = '41f132773cc29887bc2e4566863aedc01cde6e2b';
include_once ( 'Redmine / redmine_curl.php');
$ obj_redmine = new class_redmine ();
#check Auth
$ res = $ obj_redmine-> get_projects ();
if (! isset ($ res-> projects) || (isset ($ res-> total_count) && ($ res-> total_count) == 0)) {return -1; }
Переключатель ($ имяМетода) {
case 'check_status': return $ login_integrate; ## проверить интеграцию Redmine в видении
перерыв;
## трекеры
//
## Выдать статусы
//
## проекта
case 'projectAll': return $ obj_redmine-> get_projects (); #используемый
перерыв;
case 'projectById': вернуть $ obj_redmine-> get_projects ($ data ['project_id']);
перерыв;
## Пользователи
//
##Вопросы
case 'showIssue': return $ obj_redmine-> get_issue ($ data ['issue_id']);
перерыв;
case 'issueAll': return $ obj_redmine-> get_issue ();
перерыв;
case 'issueByProjectId': вернуть $ obj_redmine-> get_issue ('', $ data ['project_id']);
перерыв;
case 'createIssue': return $ obj_redmine-> create_issue ($ data);
перерыв;
case 'uploadFileToIssue': return $ obj_redmine-> get_upload_token ($ data);
перерыв;
по умолчанию: вернуть 0;
}
}
$ filecontent = file_get_contents ('test.php');
$ token = get_redmine ('uploadFileToIssue', $ filecontent);
$ filecontent = file_get_contents ('Picture.jpg');
$ token2 = get_redmine ('uploadFileToIssue', $ filecontent);
$ uploads = array (
массив (
'token' => $ token-> upload-> token,
'filename' => 'MyFile.php',
'description' => 'MyFile лучше, чем YourFile ...',
'content_type' => 'application / txt',
),
массив (
'token' => $ token2-> upload-> token,
'filename' => 'Picture.jpg',
'description' => 'MyFile лучше, чем YourFile ...',
'content_type' => 'application / image',
),
);
$ custom_fields = array (
массив (
'id' => 1,
'name' => 'Phone',
'value' => '1234265689'
),
массив (
'id' => 2,
'name' => 'Proj sub name',
'value' => 'Test'
),
);
$ post_data = array ('issue' => array (
'project_id' => 4,
'subject' => 'ABCDEFG',
'description' => 'Test',
'uploads' => $ uploads,
'custom_fields' => $ custom_fields,
),);
$ post_data = json_encode ($ post_data);
# все проекты
// $ res = get_redmine ('projectAll');
#proj по id
// $ res = get_redmine ('projectById', array ('project_id' => '4'));
# все вопросы
// $ res = get_redmine ('issueAll');
#get выпуска по идентификатору
// $ res = get_redmine ('showIssue', array ('issue_id' => '85'));
# получить вопрос по идентификатору проекта
// $ res = get_redmine ('issueByProjectId', array ('project_id' => '5'));
# создать проблему
$ res = get_redmine ('createIssue', $ post_data);
эхо '
';print_r($res);
?>
</code>