Skip to content

Instantly share code, notes, and snippets.

@smalyshev
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smalyshev/7185dc6de6b1d445d4af to your computer and use it in GitHub Desktop.
Save smalyshev/7185dc6de6b1d445d4af to your computer and use it in GitHub Desktop.
New proxyApi
<?php
/*
* By installing or using this file, you are confirming on behalf of the entity
* subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
* the SugarCRM Inc. Master Subscription Agreement ("MSA"), which is viewable at:
* http://www.sugarcrm.com/master-subscription-agreement
*
* If Company is not bound by the MSA, then by installing or using this file
* you are agreeing unconditionally that Company will be bound by the MSA and
* certifying that you have authority to bind Company accordingly.
*
* Copyright 2004-2013 SugarCRM Inc. All rights reserved.
*/
require_once('include/api/SugarApi.php');
class ProxyApi extends SugarApi
{
public function registerApiRest()
{
return array(
'retrieve' => array(
'reqType' => 'POST',
'path' => array('proxy',),
'pathVars' => array(),
'method' => 'proxyCall',
'shortHelp' => 'Returns current user',
'longHelp' => 'include/api/help/me_get_help.html',
'ignoreMetaHash' => true,
'ignoreSystemStatusError' => true,
),
);
}
/**
* Retrieves the current user info
*
* @param $api
* @param $args
* @return array
*/
public function proxyCall($api, $args)
{
$data = array();
if (!empty($args['urls']) && is_array($args['urls'])) {
foreach($args['urls'] as $contentVar => $url) {
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => '30',
));
if(!empty($args['data'][$contentVar])) {
curl_setopt_array($curl, array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $args['data'][$contentVar],
));
}
if(!empty($args['auth'][$contentVar])) {
curl_setopt_array($curl, array(
CURLOPT_USERPWD => $args['auth'][$contentVar],
));
}
$data[$contentVar] = curl_exec($curl);
curl_close($curl);
}
}
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment