本文整理汇总了PHP中Zend_Rest_Client类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Rest_Client类的具体用法?PHP Zend_Rest_Client怎么用?PHP Zend_Rest_Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Rest_Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction()
{
$this->_helper->viewRenderer->setNoRender(false);
$this->_helper->layout()->enableLayout();
if ($this->getRequest()->isPost()) {
if ($this->_getParam('num_cnpj') == '') {
Zend_Layout::getMvcInstance()->assign('msg_error', 'Campo CNPJ é obrigatório !');
} else {
if (strlen($this->_getParam('num_cnpj')) < 18) {
Zend_Layout::getMvcInstance()->assign('msg_error', 'CNPJ está incorreto !');
} else {
$num_cnpj = $this->_getParam('num_cnpj', '');
$this->view->assign('num_cnpj', $num_cnpj);
// Incluir arquivo de cliente web service
require_once 'Zend/Rest/Client.php';
// Criar classe da conexão com o web-service
$clientRest = new Zend_Rest_Client('http://' . $_SERVER['HTTP_HOST'] . '/Consulta/sintegra');
// Fazer requisição do registro
$result = $clientRest->ConsultarRegistro($num_cnpj, $this->generateAuthKey())->get();
$result = json_decode($result);
if (count($result) <= 0) {
Zend_Layout::getMvcInstance()->assign('msg_error', 'Não foi encontrado nenhum registro para o CNPJ ' . $num_cnpj);
} else {
$result = get_object_vars($result[0]);
Zend_Layout::getMvcInstance()->assign('msg_success', 'Exibindo dados do CNPJ ' . $num_cnpj);
$this->view->assign('result', $result);
}
}
}
}
}
示例2: execute
public function execute()
{
$action = SJB_Request::getVar('action');
$sessionUpdateData = SJB_Session::getValue(self::SESSION_UPDATE_TAG);
if ($action == 'mark_as_closed') {
if (is_array($sessionUpdateData)) {
$sessionUpdateData['closed_by_user'] = true;
SJB_Session::setValue(self::SESSION_UPDATE_TAG, $sessionUpdateData);
}
exit;
}
// check updates
$serverUrl = SJB_System::getSystemSettings('SJB_UPDATE_SERVER_URL');
$version = SJB_System::getSystemSettings('version');
// CHECK FOR UPDATES
$updateInfo = SJB_Session::getValue(self::SESSION_UPDATE_TAG);
if (empty($updateInfo)) {
// check URL for accessibility
$ch = curl_init($serverUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$urlInfo = curl_getinfo($ch);
$availableVersion = array();
$updateStatus = '';
if ($urlInfo['http_code'] > 0) {
// OK. Url is accessible - lets get update info
try {
$client = new Zend_Rest_Client($serverUrl);
$result = $client->isUpdateAvailable($version['major'], $version['minor'], $version['build'], SJB_System::getSystemSettings('USER_SITE_URL'))->get();
if ($result->isSuccess()) {
$updateStatus = (string) $result->updateStatus;
switch ($updateStatus) {
case 'available':
$availableVersion = array('major' => (string) $result->version->major, 'minor' => (string) $result->version->minor, 'build' => (string) $result->version->build);
break;
}
}
} catch (Exception $e) {
SJB_Error::writeToLog('Update Check: ' . $e->getMessage());
}
}
$updateInfo = array('availableVersion' => $availableVersion, 'updateStatus' => $updateStatus);
SJB_Session::setValue(self::SESSION_UPDATE_TAG, $updateInfo);
} else {
if (isset($updateInfo['availableVersion']) && !empty($updateInfo['availableVersion'])) {
if ($updateInfo['availableVersion']['build'] <= $version['build']) {
$updateInfo = array('availableVersion' => $updateInfo['availableVersion'], 'updateStatus' => 'none');
}
}
}
echo json_encode($updateInfo);
exit;
}
示例3: setUp
/**
* @return void
*/
public function setUp()
{
$httpClient = new Zend_Http_Client();
$httpClient->setConfig(array('useragent' => 'Zend_Service_Delicious - Unit tests/0.1', 'keepalive' => true));
Zend_Rest_Client::setHttpClient($httpClient);
$this->_delicious = new Zend_Service_Delicious();
}
示例4: setUp
public function setUp()
{
$this->adapter = new Zend_Http_Client_Adapter_Test();
$client = new Zend_Http_Client(null, array('adapter' => $this->adapter));
Zend_Rest_Client::setHttpClient($client);
$this->shipapi = new ShipApi('user', 'pass', 'http://www.test.com');
}
示例5: authenticate
/**
* Connects to the AUTH API in Teleserv to authenticate an agent against his HOME credentials.
*
* @return Zend_Auth_Result
* @author Bryan Zarzuela
* @throws Zend_Auth_Adapter_Exception
*/
public function authenticate()
{
// This is not a real salt. I have to fix this one of these days.
// Encrypt the password before sending over the wire.
$password = sha1($this->_password . 'andpepper');
$client = new Zend_Rest_Client($this->_url);
$response = $client->authenticate($this->_username, $password)->post();
if (!$response->isSuccess()) {
throw new Zend_Auth_Adapter_Exception("Cannot authenticate");
}
if (!$response->success()) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
}
$data = unserialize($response->data());
// var_dump($data);
$identity = new Teleserv_Auth_Identity($data);
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
}
示例6: setUp
/**
*
* @return void
*/
public function setUp()
{
if (!constant('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED')) {
$this->markTestSkipped('Zend_Service_Delicious online tests are not enabled');
}
$httpClient = new Zend_Http_Client();
$httpClient->setConfig(array('useragent' => 'Zend_Service_Delicious - Unit tests/0.1', 'keepalive' => true));
Zend_Rest_Client::setDefaultHTTPClient($httpClient);
$this->_delicious = new Zend_Service_Delicious(self::TEST_UNAME, self::TEST_PASS);
}
示例7: findPackstations
/**
* Call corresponding web service method and return the results.
*
* @deprecated Zend_Rest_Client does not format URI accordingly
* @param array $params
* @return array The parsed packstation data
* @throws Dhl_Account_Exception
*/
public function findPackstations(array $params)
{
/* @var $helper Dhl_Account_Helper_Data */
$helper = Mage::helper('dhlaccount/data');
$params = $this->getDefaultParams() + $params;
try {
$result = $this->getClient()->postfinder($params)->get();
} catch (Zend_Rest_Client_Result_Exception $e) {
$response = $this->client->getHttpClient()->getLastResponse();
$helper->log($this->client->getHttpClient()->getLastRequest());
$helper->log(sprintf("%s\nHTTP/%s %s %s", $e->getMessage(), $response->getVersion(), $response->getStatus(), $response->getMessage()));
throw new Dhl_Account_Exception($helper->__('An error occured while retrieving the packstation data.'));
}
// TODO(nr): transform web service response to usable output.
return $result;
}
示例8: __construct
public function __construct($type)
{
$this->_type = $type;
$app = $GLOBALS['application']->getOption('app');
$message_config = $app['messages'][$type];
$server = $message_config['server'];
$context = $message_config['context'];
unset($message_config['server']);
unset($message_config['context']);
$this->_messages = new StdClass();
foreach ($message_config as $key => $method) {
$key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$this->_messages->{$key} = $context . $method;
}
Zend_Rest_Client::__construct($server);
$this->getHttpClient()->setHeaders('Accept-Encoding', 'plain');
}
示例9: search
function search()
{
// load Zend classes
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Rest_Client');
// define category prefix
$prefix = 'hollywood';
// initialize REST client
$wikipedia = new Zend_Rest_Client('http://en.wikipedia.org/w/api.php');
// set query parameters
$wikipedia->action('query');
$wikipedia->list('allcategories');
//All list queries return a limited number of results.
$wikipedia->acprefix($prefix);
$wikipedia->format('xml');
// perform request and iterate over XML result set
$result = $wikipedia->get();
//echo "<ol>";
foreach ($result->query->allcategories->c as $c) {
//<a href="http://www.wikipedia.org/wiki/Category:
echo $c . "<br>";
}
}
示例10: Zend_Rest_Client
- http://framework.zend.com/manual/en/zend.rest.client.html
- http://www.pixelated-dreams.com/archives/243-Next-Generation-REST-Web-Services-Client.html
**/
require 'Zend/Rest/Client.php';
$taskr_site_url = "http://localhost:7007";
/**
If your Taskr server is configured to require authentication, uncomment the next block
and change the username and password to whatever you have in your server's config.yml.
**/
//$username = 'taskr';
//$password = 'task!';
//Zend_Rest_Client::getHttpClient()->setAuth($username, $password);
/**
Initialize the REST client.
**/
$rest = new Zend_Rest_Client($taskr_site_url);
/**
Retreiving the list of all scheduled Tasks
**/
$tasks = $rest->get("/tasks.xml");
// $tasks is a SimpleXml object, so calling print_r($result) will let
// you see all of its data.
//
// Here's an example of how to print out all of the tasks as an HTML list:
if ($tasks->task) {
echo "<ul>\n";
foreach ($tasks->task as $task) {
echo "\t<li>" . $task->name . "</li>\n";
echo "\t<ul>\n";
echo "\t\t<li>execute " . $task->{'schedule-method'} . " " . $task->{'schedule-when'} . "</li>\n";
echo "\t\t<li>created by " . $task->{'created-by'} . " on " . $task->{'created-on'} . "</li>\n";
示例11: Zend_Rest_Client
<?php
/**
* @file
* @ingroup DAPCPTest
*
* @author Dian
*/
require_once 'Zend/Rest/Client.php';
$client = new Zend_Rest_Client('http://localhost/mw/api.php?action=wspcp&format=xml');
#$client->readPage("WikiSysop", NULL, NULL, NULL, NULL, "Main Page")->get();
$client->method("readPage");
$client->title("Main Page");
$result = $client->get();
var_dump($result->wspcp()->text);
//echo $client->createPage("WikiSysop", NULL, NULL, NULL, NULL, "REST Test", "Adding some content")->get()->getIterator()->asXML();
//$__obj = $client->readPage("WikiSysop", NULL, NULL, NULL, NULL, "Main Page")->get();
//$__res = $__obj->__toString();
//var_dump($client->readPage("WikiSysop", NULL, NULL, NULL, NULL, "Main Page")->get());
//echo $client->login("WikiSysop", "!>ontoprise?")->get();
//var_dump($client->sayHello("Tester", "now")->get());
示例12: itemLookup
/**
* Look up item(s) by ASIN
*
* @param string $asin Amazon ASIN ID
* @param array $options Query Options
* @see http://www.amazon.com/gp/aws/sdk/main.html/102-9041115-9057709?s=AWSEcommerceService&v=2005-10-05&p=ApiReference/ItemLookupOperation
* @throws Zend_Service_Exception
* @return Zend_Service_Amazon_Item|Zend_Service_Amazon_ResultSet
*/
public function itemLookup($asin, array $options = array())
{
$defaultOptions = array('IdType' => 'ASIN', 'ResponseGroup' => 'Small');
$options['ItemId'] = (string) $asin;
$options = $this->_prepareOptions('ItemLookup', $options, $defaultOptions);
$this->_rest->getHttpClient()->resetParameters();
$response = $this->_rest->restGet('/onca/xml', $options);
if ($response->isError()) {
/**
* @see Zend_Service_Exception
*/
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus());
}
$dom = new DOMDocument();
$dom->loadXML($response->getBody());
self::_checkErrors($dom);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
$items = $xpath->query('//az:Items/az:Item');
if ($items->length == 1) {
/**
* @see Zend_Service_Amazon_Item
*/
require_once 'Zend/Service/Amazon/Item.php';
return new Zend_Service_Amazon_Item($items->item(0));
}
/**
* @see Zend_Service_Amazon_ResultSet
*/
require_once 'Zend/Service/Amazon/ResultSet.php';
return new Zend_Service_Amazon_ResultSet($dom);
}
示例13: webSearch
/**
* Perform a web content search on search.yahoo.com. A basic query
* consists simply of a text query. Additional options that can be
* specified consist of:
* 'results' => int How many results to return, max is 50
* 'start' => int The start offset for search results
* 'language' => lang The target document language to match
* 'type' => (all|any|phrase) How the query should be parsed
* 'site' => string A site to which your search should be restricted
* 'format' => (any|html|msword|pdf|ppt|rss|txt|xls)
* 'adult_ok' => bool permit 'adult' content in the search results
* 'similar_ok' => bool permit similar results in the result set
* 'country' => string The country code for the content searched
* 'license' => (any|cc_any|cc_commercial|cc_modifiable) The license of content being searched
* 'region' => The regional search engine on which the service performs the search. default us.
*
* @param string $query the query being run
* @param array $options any optional parameters
* @return Zend_Service_Yahoo_WebResultSet The return set
* @throws Zend\Service\Exception
*/
public function webSearch($query, array $options = array())
{
static $defaultOptions = array('type' => 'all',
'start' => 1,
'results' => 10,
'format' => 'any');
$options = $this->_prepareOptions($query, $options, $defaultOptions);
$this->_validateWebSearch($options);
$this->_rest->getHttpClient()->resetParameters();
$this->_rest->setUri('http://search.yahooapis.com');
$response = $this->_rest->restGet('/WebSearchService/V1/webSearch', $options);
if ($response->isError()) {
throw new Zend\Service\Exception('An error occurred sending request. Status code: ' .
$response->getStatus());
}
$dom = new DOMDocument();
$dom->loadXML($response->getBody());
self::_checkErrors($dom);
return new Zend_Service_Yahoo_WebResultSet($dom);
}
示例14: getRecommendations
/**
* Get recommendations from recommender API
* @param string $type
* @param array $parameters
* @return array
*/
public function getRecommendations($type, $parameters)
{
try {
$response = $this->_client->restGet(sprintf('/recommend/%s', $type), $parameters);
$this->_recommendLogger->logApiCall($this->_client, $response);
if ($response->getStatus() !== 200) {
throw new \Zend_Http_Client_Exception('Recommender failed to respond');
}
$recommendations = json_decode($response->getRawBody(), true);
if (is_array($recommendations)) {
return $recommendations;
}
} catch (\Zend_Http_Client_Exception $e) {
$this->_recommendLogger->logApiCallException($this->_client, $e);
}
return [];
}
示例15: _setHeaders
/**
* Set special headers for request
*
* @param string $apiToken
* @param string $apiVersion
* @param string $requestSignature
* @return void
*/
protected function _setHeaders($apiToken, $apiVersion, $requestSignature = null)
{
$headers = array('User-Agent' => 'TicketEvolution_Webservice', 'X-Token' => (string) $apiToken, 'Accept' => (string) 'application/json');
if (!empty($requestSignature)) {
$headers['X-Signature'] = (string) $requestSignature;
}
$this->_rest->getHttpClient()->setHeaders($headers);
}