Permalink
Browse files

adds MIT licence

  • Loading branch information...
1 parent 44a4f2a commit db7a220a4465e127ed8dbc484bc99a6ed4a53d0b adam committed Dec 12, 2008
Showing with 29 additions and 557 deletions.
  1. +22 −0 LICENCE
  2. +6 −0 README
  3. +1 −0 lib/curl
  4. +0 −2 lib/curl/.gitignore
  5. +0 −64 lib/curl/CHANGELOG
  6. +0 −20 lib/curl/MIT-LICENSE
  7. +0 −121 lib/curl/README.markdown
  8. +0 −145 lib/curl/curl.php
  9. +0 −197 lib/curl/curl.php4
  10. +0 −8 lib/curl/test.php
View
22 LICENCE
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2008 3scale networks S.L.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
View
6 README
@@ -90,3 +90,9 @@ this plugin.
}
?>
+
+
+Legal
+
+Copyright (c) 2008 3scale networks S.L., released under the MIT license.
+
Submodule curl added at f3d0da
View
@@ -1,2 +0,0 @@
-.DS_Store
-curl_cookie.txt
View
@@ -1,64 +0,0 @@
-2008-06-12 - Sean Huber (shuber@huberry.com)
- * $curl->cookie_file defaults to curl_cookie.txt using an absolute path
-
-2008-06-05 - Sean Huber (shuber@huberry.com)
- * Post variables can be passed to the request() method as a query string or array
- * Specified the argument separator for the http_build_query() function
-
-2008-05-16 - Simone Carletti (weppos@weppos.net)
- * FIXED: $this->user_agent raises a notice when HTTP_USER_AGENT server variable is empty.
-
-2008-05-16 - Simone Carletti (weppos@weppos.net)
- * FIXED: PHP 4 compatibility (__construct and http_build_query methods)
- * CHANGED: Various code touch up to be compatibile with Zend Framework coding standard (just because actually it's the best collection of PHP coding standard available)
-
-2008-05-13 - Sean Huber (shuber@huberry.com)
- * Added protected $handle property to use during requests
- * Added php4 version of the curl class
-
-2008-05-13 - Sean Huber (shuber@huberry.com)
- * Fixed bug: post variables were not being sent correctly
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Replaced '1' with 'true' in default curl_setopt options
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Fixed Bug: Custom headers were not being sent correctly for requests
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Converted README to hard tabs
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Converted curl.php to hard tabs
- * Updated README
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Removed test.php
- * Ignored curl_cookie.txt
-
-2008-05-07 - Sean Huber (shuber@huberry.com)
- * Added CHANGELOG
- * Added test.php
- * Added curl error numbers to error strings
- * Curl options prefixed with CURLOPT_ will still work
- * Fixed Bug: Renamed CurlResponse#toString() to CurlResponse#__toString()
View
@@ -1,20 +0,0 @@
-Copyright (c) 2008 Sean Huber - shuber@huberry.com
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,121 +0,0 @@
-Curl, CurlResponse
-==================
-
-Sean Huber [http://github.com/shuber](http://github.com/shuber)
-
-Description
------------
-
-A basic CURL wrapper for PHP (see [http://php.net/curl](http://php.net/curl) for more information about the libcurl extension for PHP)
-
-
-Installation
-------------
-
- git clone git://github.com/shuber/curl.git
-
-
-Usage
------
-
-### Initialization
-
-Simply require and initialize the Curl class like so
-
- require_once 'curl.php';
- $curl = new Curl;
-
-### Performing a Request
-
-The Curl object supports 4 types of requests: GET, POST, PUT, and DELETE. You must specify a url to request and optionally specify an associative array of variables to send along with it.
-
- $response = $curl->get($url, $vars = array()); # The Curl object will append the array of $vars to the $url as a query string
- $response = $curl->post($url, $vars = array());
- $response = $curl->put($url, $vars = array());
- $response = $curl->delete($url, $vars = array());
-
-Examples
-
- $response = $curl->get('google.com?q=test');
-
- # The Curl object will append '&some_variable=some_value' to the url
- $response = $curl->get('google.com?q=test', array('some_variable' => 'some_value'));
-
- $response = $curl->post('test.com/posts', array('title' => 'Test', 'body' => 'This is a test'));
-
-All requests return a CurlResponse object (see below)
-
-### The CurlResponse Object
-
-A normal CURL request will return the headers and the body in one response string. This class parses the two and places them into separate properties.
-
-For example
-
- $response = $curl->get('google.com');
- echo $response->body; # A string containing everything in the response except for the headers
- print_r($response->headers); # An associative array containing the response headers
-
-Which would display something like
-
- <html>
- <head>
- <title>Google.com</title>
- </head>
- <body>
- Some more html...
- </body>
- </html>
-
- Array
- (
- [Http-Version] => 1.0
- [Status-Code] => 200
- [Status] => 200 OK
- [Cache-Control] => private
- [Content-Type] => text/html; charset=ISO-8859-1
- [Date] => Wed, 07 May 2008 21:43:48 GMT
- [Server] => gws
- [Connection] => close
- )
-
-The CurlResponse class defines the magic [__toString()](http://php.net/__toString) method which will return the response body, so `echo $response` is the same as `echo $response->body`
-
-### Cookie Sessions
-
-By default, cookies will be stored in a file called `curl_cookie.txt`. You can change this file's name by setting it like this
-
- $curl->cookie_file = 'some_other_filename';
-
-This allows you to maintain a session across requests
-
-### Basic Configuration Options
-
-You can easily set the referer or user-agent
-
- $curl->referer = 'http://google.com';
- $curl->user_agent = 'some user agent string';
-
-You may even set these headers manually if you wish (see below)
-
-### Setting Custom Headers
-
-You can set custom headers to send with the request
-
- $curl->headers['Host'] = 12.345.678.90;
- $curl->headers['Some-Custom-Header'] = 'Some Custom Value';
-
-### Setting Custom CURL request options
-
-You can set/override many different options for CURL requests (see the [curl_setopt documentation](http://php.net/curl_setopt) for a list of them)
-
- # any of these will work
- $curl->options['AUTOREFERER'] = true;
- $curl->options['autoreferer'] = true;
- $curl->options['CURLOPT_AUTOREFERER'] = true;
- $curl->options['curlopt_autoreferer'] = true;
-
-
-Contact
--------
-
-Problems, comments, and suggestions all welcome: [shuber@huberry.com](mailto:shuber@huberry.com)
View
@@ -1,145 +0,0 @@
-<?php
-
-# Curl, CurlResponse
-#
-# Author Sean Huber - shuber@huberry.com
-# Date May 2008
-#
-# A basic CURL wrapper for PHP
-#
-# See the README for documentation/examples or http://php.net/curl for more information about the libcurl extension for PHP
-
-class Curl
-{
- public $cookie_file;
- public $headers = array();
- public $options = array();
- public $referer = '';
- public $user_agent = '';
-
- protected $error = '';
- protected $handle;
-
-
- public function __construct()
- {
- $this->cookie_file = realpath('.').'/curl_cookie.txt';
- $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ?
- $_SERVER['HTTP_USER_AGENT'] :
- 'Curl/PHP ' . PHP_VERSION . ' (http://github.com/shuber/curl/)';
- }
-
- public function delete($url, $vars = array())
- {
- return $this->request('DELETE', $url, $vars);
- }
-
- public function error()
- {
- return $this->error;
- }
-
- public function get($url, $vars = array())
- {
- if (!empty($vars)) {
- $url .= (stripos($url, '?') !== false) ? '&' : '?';
- $url .= http_build_query($vars, '', '&');
- }
- return $this->request('GET', $url);
- }
-
- public function post($url, $vars = array())
- {
- return $this->request('POST', $url, $vars);
- }
-
- public function put($url, $vars = array())
- {
- return $this->request('PUT', $url, $vars);
- }
-
- protected function request($method, $url, $vars = array())
- {
- $this->handle = curl_init();
-
- # Set some default CURL options
- curl_setopt($this->handle, CURLOPT_COOKIEFILE, $this->cookie_file);
- curl_setopt($this->handle, CURLOPT_COOKIEJAR, $this->cookie_file);
- curl_setopt($this->handle, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($this->handle, CURLOPT_HEADER, true);
- curl_setopt($this->handle, CURLOPT_POSTFIELDS, (is_array($vars) ? http_build_query($vars, '', '&') : $vars));
- curl_setopt($this->handle, CURLOPT_REFERER, $this->referer);
- curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($this->handle, CURLOPT_URL, $url);
- curl_setopt($this->handle, CURLOPT_USERAGENT, $this->user_agent);
-
- # Format custom headers for this request and set CURL option
- $headers = array();
- foreach ($this->headers as $key => $value) {
- $headers[] = $key.': '.$value;
- }
- curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
-
- # Determine the request method and set the correct CURL option
- switch ($method) {
- case 'GET':
- curl_setopt($this->handle, CURLOPT_HTTPGET, true);
- break;
- case 'POST':
- curl_setopt($this->handle, CURLOPT_POST, true);
- break;
- default:
- curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $method);
- }
-
- # Set any custom CURL options
- foreach ($this->options as $option => $value) {
- curl_setopt($this->handle, constant('CURLOPT_'.str_replace('CURLOPT_', '', strtoupper($option))), $value);
- }
-
- $response = curl_exec($this->handle);
- if ($response) {
- $response = new CurlResponse($response);
- } else {
- $this->error = curl_errno($this->handle).' - '.curl_error($this->handle);
- }
- curl_close($this->handle);
- return $response;
- }
-
-}
-
-class CurlResponse
-{
- public $body = '';
- public $headers = array();
-
- public function __construct($response)
- {
- # Extract headers from response
- $pattern = '#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims';
- preg_match_all($pattern, $response, $matches);
- $headers = split("\r\n", str_replace("\r\n\r\n", '', array_pop($matches[0])));
-
- # Extract the version and status from the first header
- $version_and_status = array_shift($headers);
- preg_match('#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#', $version_and_status, $matches);
- $this->headers['Http-Version'] = $matches[1];
- $this->headers['Status-Code'] = $matches[2];
- $this->headers['Status'] = $matches[2].' '.$matches[3];
-
- # Convert headers into an associative array
- foreach ($headers as $header) {
- preg_match('#(.*?)\:\s(.*)#', $header, $matches);
- $this->headers[$matches[1]] = $matches[2];
- }
-
- # Remove the headers from the response body
- $this->body = preg_replace($pattern, '', $response);
- }
-
- public function __toString()
- {
- return $this->body;
- }
-}
Oops, something went wrong.

0 comments on commit db7a220

Please sign in to comment.