/** * @param $name * @param $arguments * @return apiServiceRequest|array * @throws apiException */ public function __call($name, $arguments) { if (count($arguments) != 1 && count($arguments) != 2) { throw new apiException("apiClient method calls expect 1 or 2 parameter (\$client->plus->activities->list(array('userId' => 'me'))"); } if (!is_array($arguments[0])) { throw new apiException("apiClient method parameter should be an array (\$client->plus->activities->list(array('userId' => 'me'))"); } $batchKey = false; if (isset($arguments[1])) { if (!is_string($arguments[1])) { throw new apiException("The batch key parameter should be a string (\$client->plus->activities->list( array('userId' => '@me'), 'batchKey'))"); } $batchKey = $arguments[1]; } if (!isset($this->methods[$name])) { throw new apiException("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it $postBody = null; if (isset($parameters['postBody'])) { if (is_object($parameters['postBody'])) { $this->stripNull($parameters['postBody']); } // Some APIs require the postBody to be set under the data key. if (is_array($parameters['postBody']) && 'buzz' == $this->serviceName) { if (!isset($parameters['postBody']['data'])) { $rawBody = $parameters['postBody']; unset($parameters['postBody']); $parameters['postBody']['data'] = $rawBody; } } $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) ? json_encode($parameters['postBody']) : $parameters['postBody']; // remove from the parameter list so not to trip up the param entry checking & make sure it doesn't end up on the query unset($parameters['postBody']); if (isset($parameters['optParams'])) { $optParams = $parameters['optParams']; unset($parameters['optParams']); $parameters = array_merge($parameters, $optParams); } } if (!isset($method['parameters'])) { $method['parameters'] = array(); } $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { throw new apiException("({$name}) unknown parameter: '{$key}'"); } } if (isset($method['parameters'])) { foreach ($method['parameters'] as $paramName => $paramSpec) { if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { throw new apiException("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; unset($parameters[$paramName]['required']); } else { unset($parameters[$paramName]); } } } // Discovery v1.0 puts the canonical method id under the 'id' field. if (!isset($method['id'])) { $method['id'] = $method['rpcMethod']; } // Discovery v1.0 puts the canonical path under the 'path' field. if (!isset($method['path'])) { $method['path'] = $method['restPath']; } $request = new apiServiceRequest($this->service->restBasePath, $this->service->rpcPath, $method['path'], $method['id'], $method['httpMethod'], $parameters, $postBody); if ($batchKey) { $request->setBatchKey($batchKey); return $request; } else { return apiREST::execute($request); } }
public function __call($name, $arguments) { if (count($arguments) != 1 && count($arguments) != 2) { throw new apiException("apiClient method calls expect one or two parameter (for example: \$apiClient->buzz->activities->list( array('userId' => '@me')) or when executing a batch request: \$apiClient->buzz->activities->list( array('userId' => '@me'), 'batchKey')"); } if (!is_array($arguments[0])) { throw new apiException("apiClient method parameter should be an array (for example: \$apiClient->buzz->activities->list( array('userId' => '@me'))"); } $batchKey = false; if (isset($arguments[1])) { if (!is_string($arguments[1])) { throw new apiException("The batch key parameter should be a string, for example: \$apiClient->buzz->activities->list( array('userId' => '@me'), 'batchKey')"); } $batchKey = $arguments[1]; } if (!isset($this->methods[$name])) { throw new apiException("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it $postBody = null; if (isset($parameters['postBody'])) { if (is_object($parameters['postBody'])) { $this->stripNull($parameters['postBody']); } // Some APIs require the postBody to be set under the data key. if (is_array($parameters['postBody']) && 'buzz' == $this->serviceName) { if (!isset($parameters['postBody']['data'])) { $rawBody = $parameters['postBody']; unset($parameters['postBody']); $parameters['postBody']['data'] = $rawBody; } } $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) ? json_encode($parameters['postBody']) : $parameters['postBody']; // remove from the parameter list so not to trip up the param entry checking & make sure it doesn't end up on the query unset($parameters['postBody']); if (isset($parameters['optParams'])) { $optParams = $parameters['optParams']; unset($parameters['optParams']); $parameters = array_merge($parameters, $optParams); } } if (!isset($method['parameters'])) { $method['parameters'] = array(); } $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { throw new apiException("({$name}) unknown parameter: '{$key}'"); } } if (isset($method['parameters'])) { foreach ($method['parameters'] as $paramName => $paramSpec) { if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { throw new apiException("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; // check to see if the param value matches the required pattern if (isset($parameters[$paramName]['pattern']) && !empty($parameters[$paramName]['pattern'])) { if (preg_match('|' . $parameters[$paramName]['pattern'] . '|', $value) == 0) { throw new apiException("({$name}) invalid parameter format for {$paramName}: {$value} doesn't match \"{$parameters[$paramName]['pattern']}\""); } } $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; // remove all the bits that were already validated in this function & are no longer relevant within the execution chain unset($parameters[$paramName]['pattern']); unset($parameters[$paramName]['required']); } else { unset($parameters[$paramName]); } } } // Discovery v1.0 puts the canonical method id under the 'id' field. if (!isset($method['id'])) { $method['id'] = $method['rpcMethod']; } // Discovery v1.0 puts the canonical path under the 'path' field. if (!isset($method['path'])) { $method['path'] = $method['restPath']; } $request = new apiServiceRequest($this->service->getIo(), $this->service->getRestBasePath(), $this->service->getRpcPath(), $method['path'], $method['id'], $method['httpMethod'], $parameters, $postBody); if ($batchKey) { $request->setBatchKey($batchKey); return $request; } else { return apiREST::execute($request); } }
/** * @param $name * @param $arguments * @return apiHttpRequest|array * @throws apiException */ public function __call($name, $arguments) { if (!isset($this->methods[$name])) { throw new apiException("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it $postBody = null; if (isset($parameters['postBody'])) { if (is_object($parameters['postBody'])) { $this->stripNull($parameters['postBody']); } // Some APIs require the postBody to be set under the data key. if (is_array($parameters['postBody']) && 'latitude' == $this->serviceName) { if (!isset($parameters['postBody']['data'])) { $rawBody = $parameters['postBody']; unset($parameters['postBody']); $parameters['postBody']['data'] = $rawBody; } } $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) ? json_encode($parameters['postBody']) : $parameters['postBody']; unset($parameters['postBody']); if (isset($parameters['optParams'])) { $optParams = $parameters['optParams']; unset($parameters['optParams']); $parameters = array_merge($parameters, $optParams); } } if (!isset($method['parameters'])) { $method['parameters'] = array(); } $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { throw new apiException("({$name}) unknown parameter: '{$key}'"); } } if (isset($method['parameters'])) { foreach ($method['parameters'] as $paramName => $paramSpec) { if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { throw new apiException("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; unset($parameters[$paramName]['required']); } else { unset($parameters[$paramName]); } } } // Discovery v1.0 puts the canonical method id under the 'id' field. if (!isset($method['id'])) { $method['id'] = $method['rpcMethod']; } // Discovery v1.0 puts the canonical path under the 'path' field. if (!isset($method['path'])) { $method['path'] = $method['restPath']; } $restBasePath = $this->service->restBasePath; // Process Media Request $contentType = false; if (isset($method['mediaUpload'])) { $media = apiMediaFileUpload::process($postBody, $parameters); if ($media) { $contentType = isset($media['content-type']) ? $media['content-type'] : null; $postBody = isset($media['postBody']) ? $media['postBody'] : null; $restBasePath = $method['mediaUpload']['protocols']['simple']['path']; $method['path'] = ''; } } $url = apiREST::createRequestUri($restBasePath, $method['path'], $parameters); $httpRequest = new apiHttpRequest($url, $method['httpMethod'], null, $postBody); if ($postBody) { $contentTypeHeader = array(); if (isset($contentType) && $contentType) { $contentTypeHeader['content-type'] = $contentType; } else { $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8'; $contentTypeHeader['content-length'] = apiUtils::getStrLen($postBody); } $httpRequest->setRequestHeaders($contentTypeHeader); } $httpRequest = apiClient::$auth->sign($httpRequest); if (apiClient::$useBatch) { return $httpRequest; } // Terminate immediatly if this is a resumable request. if (isset($parameters['uploadType']['value']) && 'resumable' == $parameters['uploadType']['value']) { return $httpRequest; } return apiREST::execute($httpRequest); }
/** * @param $name * @param $arguments * @return apiServiceRequest|array * @throws apiException */ public function __call($name, $arguments) { if (count($arguments) != 1 && count($arguments) != 2) { throw new apiException("client method calls expect 1 or 2 parameter (\$client->plus->activities->list(array('userId' => 'me'))"); } if (!is_array($arguments[0])) { throw new apiException("client method parameter should be an array (\$client->plus->activities->list(array('userId' => 'me'))"); } $batchKey = false; if (isset($arguments[1])) { if (!is_string($arguments[1])) { throw new apiException("The batch key parameter should be a string (\$client->plus->activities->list( array('userId' => 'me'), 'batchKey'))"); } $batchKey = $arguments[1]; } if (!isset($this->methods[$name])) { throw new apiException("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it $postBody = null; if (isset($parameters['postBody'])) { if (is_object($parameters['postBody'])) { $this->stripNull($parameters['postBody']); } // Some APIs require the postBody to be set under the data key. if (is_array($parameters['postBody']) && 'latitude' == $this->serviceName) { if (!isset($parameters['postBody']['data'])) { $rawBody = $parameters['postBody']; unset($parameters['postBody']); $parameters['postBody']['data'] = $rawBody; } } $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) ? json_encode($parameters['postBody']) : $parameters['postBody']; unset($parameters['postBody']); if (isset($parameters['optParams'])) { $optParams = $parameters['optParams']; unset($parameters['optParams']); $parameters = array_merge($parameters, $optParams); } } if (!isset($method['parameters'])) { $method['parameters'] = array(); } $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { throw new apiException("({$name}) unknown parameter: '{$key}'"); } } if (isset($method['parameters'])) { foreach ($method['parameters'] as $paramName => $paramSpec) { if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { throw new apiException("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; unset($parameters[$paramName]['required']); } else { unset($parameters[$paramName]); } } } // Discovery v1.0 puts the canonical method id under the 'id' field. if (!isset($method['id'])) { $method['id'] = $method['rpcMethod']; } // Discovery v1.0 puts the canonical path under the 'path' field. if (!isset($method['path'])) { $method['path'] = $method['restPath']; } $restBasePath = $this->service->restBasePath; // Process Media Request $contentType = false; if (isset($method['mediaUpload'])) { $media = apiMediaFileUpload::process($postBody, $parameters); if ($media) { $contentType = isset($media['content-type']) ? $media['content-type'] : null; $postBody = isset($media['postBody']) ? $media['postBody'] : null; $restBasePath = $method['mediaUpload']['protocols']['simple']['path']; $method['path'] = ''; } } $request = new apiServiceRequest($restBasePath, $this->service->rpcPath, $method['path'], $method['id'], $method['httpMethod'], $parameters, $postBody); $request->setContentType($contentType); // Terminate immediatly if this is a resumable request. if (isset($parameters['uploadType']['value']) && 'resumable' == $parameters['uploadType']['value']) { return $request; } if ($batchKey) { $request->setBatchKey($batchKey); return $request; } else { return apiREST::execute($request); } }
public function __call($name, $arguments) { if (count($arguments) != 1 && count($arguments) != 2) { throw new apiException("apiClient method calls expect one or two parameter (for example: \$apiClient->buzz->activities->list( array('userId' => '@me')) or when executing a batch request: \$apiClient->buzz->activities->list( array('userId' => '@me'), 'batchKey')"); } if (!is_array($arguments[0])) { throw new apiException("apiClient method parameter should me an array (for example: \$apiClient->buzz->activities->list( array('userId' => '@me'))"); } $batchKey = false; if (isset($arguments[1])) { if (!is_string($arguments[1])) { throw new apiException("The batch key parameter should be a string, for example: \$apiClient->buzz->activities->list( array('userId' => '@me'), 'batchKey')"); } $batchKey = $arguments[1]; } if (!isset($this->methods[$name])) { throw new apiException("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it $postBody = null; if (isset($parameters['postBody'])) { // If the postBody is not a raw json string, json encode it for transport $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) ? json_encode($parameters['postBody']) : $parameters['postBody']; // remove from the parameter list so not to trip up the param entry checking & make sure it doesn't end up on the query unset($parameters['postBody']); //FIXME Should really add the magic array('data' => ..real stuff ..) wrapper around the request as to not bother developers with it } foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { throw new apiException("({$name}) unknown parameter: '{$key}'"); } } if (isset($method['parameters'])) { foreach ($method['parameters'] as $paramName => $paramSpec) { if ($paramSpec['required'] && !isset($parameters[$paramName])) { throw new apiException("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; // check to see if the param value matches the required pattern if (isset($parameters[$paramName]['pattern']) && !empty($parameters[$paramName]['pattern'])) { if (preg_match('|' . $parameters[$paramName]['pattern'] . '|', $value) == 0) { throw new apiException("({$name}) invalid parameter format for {$paramName}: {$value} doesn't match \"{$parameters[$paramName]['pattern']}\""); } } $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; // remove all the bits that were already validated in this function & are no longer relevant within the execution chain unset($parameters[$paramName]['pattern']); unset($parameters[$paramName]['required']); } else { unset($parameters[$paramName]); } } } $request = new apiServiceRequest($this->service->getIo(), $this->service->getBaseUrl(), $method['pathUrl'], $method['rpcName'], $method['httpMethod'], $parameters, $postBody); if ($batchKey) { $request->setBatchKey($batchKey); return $request; } else { return apiREST::execute($request); } }