Create a gist now

Instantly share code, notes, and snippets.

iTango Web Client
<?php
/**
* Copyright (c) 2014 Shine Software.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the names of the copyright holders nor the names of the
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package RESTful Service Client
* @subpackage Client
* @author Michelangelo Turillo <mturillo@shinesoftware.com>
* @copyright 2015 Michelangelo Turillo.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://shinesoftware.com
* @version @@PACKAGE_VERSION@@
*/
/* Authentication key - request a new CLIENT-SECRET by email info@itango.it */
$secret = "CLIENT-SECRET";
/* Server URI */
$URI = "http://itango.it/v1/events/";
try {
/* Server Parameters */
$data['title'] = "Tango Festival";
$data['category_id'] = "2"; // Festival
$data['start'] = date('Y-m-d 21.30');
$data['end'] = date('Y-m-d 00.30');
$data['city'] = "Trieste";
$data['country_id'] = "82"; // Italy
$data['language_id'] = "2"; // Italian
$data['url'] = "http://www.mysite.com"; // Italian
$data['contact'] = "+39.123123123";
$data['tags'] = "milonga,mirada,tango,festival";
$data['content'] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce tortor tellus, pellentesque pretium congue vel, commodo non felis. Sed sed accumsan tortor. <br/><br/>
https://www.youtube.com/watch?v=_4G03HpzArc <br/><br/>
https://instagram.com/instatango <br/><br/>
http://open.spotify.com/user/1172633665/playlist/06ILuqOdtGUHTwGF9hxFZ7 <br/><br/>
#milonga";
$data['address'] = "Viale XX Settembre, 3 Trieste";
$data['city'] = "Trieste";
$data['showonlist'] = "1";
$data['visible'] = "1"; // True
/* Server Call */
$result = CallAPI("POST", $URI . $secret, $data);
/* Call result data */
/* {"data":[{"id":"251","title":"Tango Festival","start":"2015-10-08 21:30:00","end":"2015-10-08 00:30:00","address":"Viale XX Settembre, 3 Trieste","city":"Trieste","parent_id":null,"url":"tango-festival.html"}]} */
print_r($result);
}catch(Exception $e){
die($e->getMessage());
}
/* Custom Function for call the API by the cURL method */
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment