ehttpclient Http Client Extension for Yii

  1. Requirements
  2. TODO
  3. Usage
  4. ChangeLog
  5. Resources

I wanted to have a proper Http Client for my Yii Applications. Even though there are a couple of good classes around, I wanted a good one to extend from and also that has an already proven efficiency. So I got into Zend Http Client library (I really do not like to reinvent the wheel -do not worry Zend guys, I have already included the license in it). Hope Yii comes in near future with an HTTP Client by its own, I think is a great thing to have to develop greater things (mash-up applications, social network connectors, universal password validations, Xml-Rpc Servers-Clients, and so on...)

I have worked through the classes and checked that all that is required is within the package. So, with this library you do not need to worry about the inclusion of the Zend Library on the vendors folder.

This version is beta and even though I have tested most of its functionality, I would love your feedback and tests to improve it and make it worth to in have our must have libraries.

I have created a GitHub repository for those willing to contribute on any of the extensions I created. Please, check the link at the bottom of this wiki.

Requirements

Working from Yii v1.1.5 till v1.1.9

TODO

Add streaming support

Usage

Unpack compressed files and place them on your protected/extensions directory.

You can refer to the Zend_Http_Client documentation (remember to exchange the names from Zend to those in the extension).

Here two easy samples (Send me your tests, I would love to see more in action)

Example 1 - Getting my twitter statuses

Yii::import('ext.httpclient.*');

// get my twitter status
$client = new EHttpClient('http://twitter.com/statuses/user_timeline/tonydspaniard.xml', array(
    'maxredirects' => 0,
    'timeout'      => 30));

$response = $client->request();

if($response->isSuccessful())
    echo '<pre>' . htmlentities($response->getBody()) .'</pre>';
else
    echo $response->getRawBody();

Example 2 - Performing a Full Page Google Search Now, using EHttpClientAdapterCurl

Yii::import('ext.httpclient.*');

$client = new EHttpClient('http://www.google.es/search', array(
    'maxredirects' => 3,
    'timeout'      => 30,
    'adapter'	   => 'EHttpClientAdapterCurl'));

$client->setParameterGet(array('hl'=>'es', 'q'=>'manolo'));

$response = $client->request();

if($response->isSuccessful())
   echo $response->getBody();
else
   $response->getRawBody();

Example 3 - Downloading using stream

Yii::import('ext.httpclient.*');

$uri = EUri::factory('http://www.ip2nation.com/ip2nation/Download/');

$temp_dir = realpath(sys_get_temp_dir()). DIRECTORY_SEPARATOR;

$temp_file = tempnam($temp_dir, 'TEST');

$config = array('adapter'=>'EHttpClientAdapterCurl', 'timeout'=>'60');

$client = new EHttpClient($uri, $config);
$client->setStream();

$response = $client->request('GET');

if($response->isSuccessful()){
   // copy stream to temporary file... 
   copy( $response->getStreamName(), $temp_dir . $temp_file );
   // other work with temporary file (ie decompress, decrypt, etc...)
}
else
   $response->getRawBody();

ChangeLog

14 0
31 followers
5 600 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Developed by: Antonio Ramirez
Created on: Dec 27, 2010
Last updated: 12 years ago

Downloads

show all

Related Extensions