あとで書くよ
services_twitterのprepareRequestメソッド
protected function prepareRequest($endpoint, array $args = array(), $cat = null)
{
$params = array();
$files = array();
// check if we have is a search or trends call, in this case the base
// uri is different
if ( $cat == 'search'
|| ( $cat == 'trends'
&& !in_array((string)$endpoint['name'], array('available', 'location'))
)
) {
$uri = self::$searchUri;
} else {
$uri = self::$uri;
}
// ssl requested
if ($this->getOption('use_ssl')) {
$uri = str_replace('http://', 'https://', $uri);
}
// build the uri path
if (!isset($endpoint['routing'])) {
$path = '/';
if ($cat !== null) {
$path .= $cat . '/';
}
$path .= (string)$endpoint['name'];
} else {
$path = (string)$endpoint['routing'];
}
$method = (string)$endpoint['method'];
// check if we have a POST method and a registered source to pass
$source = $this->getOption('source');
if ($method == 'POST' && $source !== null) {
$params['source'] = $source;
}
// check arguments requirements
$minargs = isset($endpoint['min_args'])
? (int)$endpoint['min_args']
: count($endpoint->xpath('param[@required="true" or @required="1"]'));
if (!$minargs && (isset($args[0]) && !is_array($args[0]))) {
throw new Services_Twitter_Exception(
$path . ' expects an array as unique parameter',
self::ERROR_PARAMS,
$path
);
}
if ( $minargs && (!isset($args[0])
|| is_array($args[0])
&& $minargs > count($args[0]))
) {
throw new Services_Twitter_Exception(
'Not enough arguments for ' . $path,
self::ERROR_PARAMS,
$path
);
}
$needargs = $minargs;
// now process arguments according to their definition in the xml
// mapping
foreach ($endpoint->param as $param) {
$pName = (string)$param['name'];
$pType = (string)$param['type'];
$pMaxLength = (int)$param['max_length'];
$pMaxLength = $pMaxLength > 0 ? $pMaxLength : null;
$pReq = (string)$param['required'] == 'true' || $needargs;
if ($pReq && !is_array($args[0])) {
$arg = array_shift($args);
$needargs--;
} else if (isset($args[0][$pName])) {
$arg = $args[0][$pName];
$needargs--;
} else {
continue;
}
try {
$this->validateArg($pName, $arg, $pType, $pMaxLength);
} catch (Exception $exc) {
throw new Services_Twitter_Exception(
$path . ': ' . $exc->getMessage(),
self::ERROR_PARAMS,
$path
);
}
if ($pName == 'id' && !isset($endpoint['routing'])) {
$path .= '/' . $arg;
} else {
if (strpos($path, ':') !== false) {
$path = preg_replace('/:'.preg_quote($pName).'(\/|$)/', rawurlencode($arg).'$1', $path);
} else {
if ($pType == 'string' && !$this->isUtf8($arg)) {
// iso-8859-1 string that we must convert to unicode
$arg = utf8_encode($arg);
}
if ($pType == 'image') {
// we have a file upload
$files[$pName] = $arg;
} else {
$params[$pName] = $arg;
}
}
}
}
$uri .= $path . '.' . $this->getOption('format');
return array($uri, $method, $params, $files);
}
カテゴリー: php