_host = $options['baseUrl']; } if (isset($options['namespace'])) { $this->_namespace = $options['namespace']; } if (isset($options['defaults'])) { $this->_defaults = $options['defaults']; } if (! isset($options['httpClient'])) { $options['httpClient'] = new Zend_Http_Client(); } $this->_httpClient = $options['httpClient']; } /** * When a method call is made against this proxy, convert it to * an HTTP request to make against the Nirvanix REST service. * * $imfs->DeleteFiles(array('filePath' => 'foo')); * * Assuming this object was proxying the IMFS namespace, the * method call above would call the DeleteFiles command. The * POST parameters would be filePath, merged with the * $this->_defaults (containing the sessionToken). * * @param string $methodName Name of the command to call * on this namespace. * @param array $args Only the first is used and it must be * an array. It contains the POST params. * * @return Zend_Service_Nirvanix_Response */ public function __call($methodName, $args) { $uri = $this->_makeUri($methodName); $this->_httpClient->setUri($uri); if (!isset($args[0]) || !is_array($args[0])) { $args[0] = array(); } $params = array_merge($this->_defaults, $args[0]); $this->_httpClient->resetParameters(); $this->_httpClient->setParameterPost($params); $httpResponse = $this->_httpClient->request(Zend_Http_Client::POST); return $this->_wrapResponse($httpResponse); } /** * Return the HTTP client used for this namespace. This is useful * for inspecting the last request or directly interacting with the * HTTP client. * * @return Zend_Http_Client */ public function getHttpClient() { return $this->_httpClient; } /** * Make a complete URI from an RPC method name. All Nirvanix REST * service URIs use the same format. * * @param string $methodName RPC method name * @return string */ protected function _makeUri($methodName) { $methodName = ucfirst($methodName); return "{$this->_host}/ws/{$this->_namespace}/{$methodName}.ashx"; } /** * All Nirvanix REST service calls return an XML payload. This method * makes a Zend_Service_Nirvanix_Response from that XML payload. * * @param Zend_Http_Response $httpResponse Raw response from Nirvanix * @return Zend_Service_Nirvanix_Response Wrapped response */ protected function _wrapResponse($httpResponse) { return new Zend_Service_Nirvanix_Response($httpResponse->getBody()); } }