-
Notifications
You must be signed in to change notification settings - Fork 0
Proxy Library
Category:Libraries | Category:Libraries::Community | Category:Libraries::Connectivity This class enables you to make call to internal and external site with general HTTP request by opening a socket connection to the remote host. No cURL or other fancy stuff dependencies.
[h3]FEATURES[/h3]
- Support all HTTP method (GET, POST, PUT, DELETE) [NEW].
- Support custom HTTP header, and basic HTTP Authorization [NEW].
- Get Full HTTP Header.
- Get Full HTTP Response (Content).
- Get Crawled web content.
- Google Geocoding Functionality [NEW].
- Maintained css path, js path, image, anchor tag and form at rendered option.
- Set Proxy Call support.
- Set Delay HTTP Call support.
- Set User Agent (Browser Identity) support.
- Internal cache (using gzip).
- Persistent Call (processing redirect, either from header or meta)
- NO NEED FANCY CURL STUFF DEPEDENCIES! PURE PHP.
- Cookie support.
- Log and error flag.
[h3]DOWNLOAD[/h3] File:ProxyLibrary_v1.0.6.zip [LATEST] File:ProxyLibrary_v1.0.5.zip File:ProxyLibrary_v1.0.4.zip File:ProxyLibrary_v1.0.3.zip File:ProxyLibrary_v1.0.2.zip File:ProxyLibrary_v1.0.1.zip File:ProxyLibrary_v1.zip
[h3]VERSION HISTORY AND DESCRIPTION[/h3] [i][from pre-beta version][/i] When i develop some project, i need to have a simple way to call another controller, or even an external resource (ex. api from google). I create a simple cURL class to do that. This is the (almost) stable version of that, this enough for my needs. I'll take it to higher level, as soon as i had a long holiday from my work.
For now, enjoy!
[code] // Simple way to use this library // In any controller, put this line... ... $this->load->library('proxy'); $this->proxy->site('http://codeigniter.com',TRUE); ...
// Above example will give you rendered page of CodeIgniter site, if you didn't want // to render it directly, or it was a json which you want to save to var, simply do this... ... $this->load->library('proxy'); $json_var = $this->proxy->site('http://ip2country.sourceforge.net/ip2c.php?ip='.$ip.'&format=JSON'); ...
// To call your controller (maybe in some situation, you need it instead use redirect() function) ... $this->load->library('proxy'); $this->proxy->controller('your_target_controller_name/target_function/some_id'); ... [/code]
[i][from version 1.0.1][/i] [b]MORE FEATURES(All old feature still there):[/b]
-
Get Full HTTP Header.
-
Set Proxy Call.
-
Set Delay HTTP Call.
-
Set user agent.
-
Internal cache (using gzip).
-
Persistent call (processing redirect, either from header or meta)
-
NO NEED FANCY CURL STUFF DEPEDENCIES! PURE PHP.
-
Cookie support.
-
Log and error flag. [code] $this->load->library('proxy'); //Set proxy call $this->proxy->set_proxy('proxy_host',80,'username','password'); $this->proxy->site('twitter.com',TRUE); //Get rendered HTTP header, for use it as variable, // put FALSE on second passed param or simple let it blank $this->proxy->head('codeigniter.com',TRUE); //Set user agent and delay $this->proxy->set_delay(5); $this->proxy->set_useragent($this->session->userdata('user_agent')); $this->proxy->site('twitter.com',TRUE); [/code] ============================================================================ [i][from version 1.0.2][/i] cleaning (some debug crap) and fixing structure alse adding ReadMe.txt ============================================================================ [i][from version 1.0.3][/i] [b]MORE FEATURES(All old feature still there):[/b]
-
Get Crawled web content.
-
Maintained css path, js path, image, anchor tag and form at rendered option.
[code] // Get crawled page of CodeIgniter Forums... $this->load->library('proxy'); $this->proxy->crawl('codeigniter.com/forums',TRUE); [/code]
[i][from version 1.0.4][/i] [b]MORE FEATURES(All old feature still there):[/b]
- Google Geocoding Functionality.
[code] $this->load->library('proxy'); // Generate json response by address $map_data = $this->proxy->geocode('1600 Amphitheatre Parkway, Mountain View, CA'); // Generate json response by latlng $map_data = $this->proxy->geocode(array('40.714224','-73.961452')); // Generate xml response by latlng and set sensor to TRUE $map_data = $this->proxy->geocode(array(40.714224,-73.961452),'XML',TRUE); [/code]
[i][from version 1.0.6][/i] [b]All General HTTP Method Support(All old feature still there):[/b]
HTTP (GET, POST, PUT, DELETE), REST and HTTP Authentfication.
[code] /* [USAGE] Basic http structure : / / $this->proxy->http($method, $destination_url, $request_parameter, $request_header_parameter); */ // $method is HTTP method : 'GET', 'POST', 'PUT', 'DELETE' // $destination_url is the full url. Proxy lib will automaticly find the host, so include the full url, not only the domain // $request_parameter is array of your GET, POST, PUT or DELETE parameter. eg : array('id' => 1); // $request_header_parameter is array of custom HTTP header, it can be API key, oauth stuff, or any of your needs. // PS : For Basic HTTP Authorization, use : array('auth' => 'username:password'), as params
$this->load->library('proxy'); // An easy example performing basic 'POST' and get the result rendered. echo $this->proxy->http('POST', 'http://somesite.com/login.php', array('username' => 'username', 'password' => 'password')); // Perform an API Call? here you go... // An example of GET $username = 'taufanaditya'; $tweets = $this->proxy->http('GET', 'http://twitter.com/statuses/user_timeline/'.$username.'.json'); // Already have your own REST, now you can perform a Rest Client Call, without cURL at all! // An example of POST, with Basic HTTP Authentification echo $this->proxy->http('POST', 'api.yourdomain.com/api/users', array('id' => 10, 'name' => 'Changed via Proxy'), array('auth' => 'username:password')); // An example of PUT, with custom HTTP header (like API Key, or anything else) $new_user = array( 'name' => 'John Doe', 'username' => 'johndoe', 'email' => '[email protected]', 'password' => 'secret', 'confirm_password' => 'secret', ); echo $this->proxy->http('PUT','api.yourdomain.com/api/users', $new_user, array('X-API-KEY' => 'fooandbarnotencrypted')); [/code]
[i]Hope you find this object useful, Cheers![/i] Taufan Aditya A.K.A [b]Toopay[/b]