I share the code of two PHP functions performing basic Mingle operations (creating a card and updating a card) hoping it will help you to save some time. They can easily be adapted to perform other basic operations such that getting a card data or removing a card.
Code Snippet
// Mingle card creation function returning the Mingle number of the new card (use CURL library)
function create_card($url, $parameters)
{
$ch = curl_init();
if ($ch)
{
// HTTP POST call configuration
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
// HTTP POST call
$header = curl_exec($ch);
curl_close($ch);
// Card number extract from header data
$pos1 = strpos($header, "/cards/") + 7;
$pos2 = strpos($header, ".xml");
$number = substr($header, $pos1, $pos2 - $pos1);
return $number;
} else
{
return "";
}
}
// Mingle card update function (use CURL library)
function update_card($url, $parameters)
{
$ch = curl_init();
if ($ch)
{
// Creation of the file to send through the HTTP PUT call
$putFile = tmpfile();
fwrite($putFile, $parameters);
fseek($putFile, 0);
// HTTP PUT call configuration
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $putFile);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($parameters));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
// HTTP PUT call
curl_exec($ch);
fclose($putFile);
curl_close($ch);
return true;
} else
{
return false;
}
}
// Call examples
$card_number = create_card(
"http://user:password@your.mingle.server:8080/api/v2/projects/my_project/cards.xml",
"card[name]=A new story card&card[card_type_name]=Story");
update_card(
"http://user:password@your.mingle.server:8080/api/v2/projects/my_project/cards/123.xml",
"card[name]=A new story card name&card[description]=A new description");
?>
Comments
0 comments
Please sign in to leave a comment.