Permalink
Browse files

Version 0.7.2

- use DIRECTORY_SEPARATOR for multi-environment support. (Issue #80) Props: whallz
- tidied up the curlHeader function to use explode instead of substr and store the keys in the format they are returned from the API
- removed content-length hack as it isn't needed if CURLOPT_POSTFIELDS is initialized on all POSTs
- removed the expects header hack as Twitter no longer requires it to be there
- introduce composer.json. (Issues #39, #77, #85) Props: akandels, conradkleinespel, dguyon, kud, philsturgeon, willdurand
- added support for specifying custom headers when using $tmhOAuth->request. (Issue #98)
  • Loading branch information...
1 parent 84a84fd commit 6c4a2ae0650c7855c0e242fdfc058172ad9fac4e @themattharris committed with themattharris Nov 1, 2012
Showing with 80 additions and 23 deletions.
  1. +10 −2 README.md
  2. +54 −0 composer.json
  3. +16 −21 tmhOAuth.php
View
@@ -48,6 +48,14 @@ If you used custom HTTP request headers when they were defined as `'key: value'`
you should now define them as `'key' => 'value'` pairs.
## Change History
+### 0.7.2 - 01 November 2012
+- use DIRECTORY_SEPARATOR for multi-environment support. (Issue #80) Props: whallz
+- tidied up the curlHeader function to use explode instead of substr and store the keys in the format they are returned from the API
+- removed content-length hack as it isn't needed if CURLOPT_POSTFIELDS is initialized on all POSTs
+- removed the expects header hack as Twitter no longer requires it to be there
+- introduce composer.json. (Issues #39, #77, #85) Props: akandels, conradkleinespel, dguyon, kud, philsturgeon, willdurand
+- added support for specifying custom headers when using $tmhOAuth->request. (Issue #98)
+
### 0.7.1 - 27 October 2012
- set content-length to 0 explictly to avoid a bug between libcurl and Twitter (Issue #94)
- allow initialization without a configuration array (default config to array())
@@ -174,8 +182,8 @@ you should now define them as `'key' => 'value'` pairs.
License: Apache 2 (see [included LICENSE file](https://github.com/themattharris/tmhOAuth/blob/master/LICENSE))
-Follow [@tmhOAuth](https://twitter.com/intent/follow?screen_name=tmhOAuth) to receive updates on releases, or ask for support
-Follow me on Twitter: [@themattharris](https://twitter.com/intent/follow?screen_name=themattharris)
+Follow [@tmhOAuth](https://twitter.com/intent/follow?screen_name=tmhOAuth) to receive updates on releases, or ask for support
+Follow me on Twitter: [@themattharris](https://twitter.com/intent/follow?screen_name=themattharris)
Check out the Twitter Developer Resources: <https://dev.twitter.com>
## To Do
View
@@ -0,0 +1,54 @@
+{
+ "name": "themattharris/tmhOAuth",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.7.2-devel"
+ }
+ },
+ "type": "library",
+ "description": "An OAuth 1.0A library written in PHP by @themattharris, specifically for use with the Twitter API",
+ "version": "0.7.2",
+ "license": "Apache-2.0",
+ "authors": [
+ {
+ "name": "Matt Harris",
+ "email": "matt@themattharris.com",
+ "role": "Developer"
+ }
+ ],
+ "keywords": [
+ "twitter",
+ "oauth"
+ ],
+ "support": {
+ "issues": "https://github.com/themattharris/tmhOAuth/issues"
+ },
+ "require": {
+ "php": ">=5.3.0",
+ "themattharris/tmhOAuth": "0.7.2"
+ },
+ "repositories": {
+ "tmhOAuth": {
+ "type": "package",
+ "package": {
+ "name": "themattharris/tmhOAuth",
+ "description": "An OAuth 1.0A library written in PHP by @themattharris, specifically for use with the Twitter API.",
+ "version": "0.7.2",
+ "dist": {
+ "url": "https://github.com/themattharris/tmhOAuth/zipball/0.7.2-devel",
+ "type": "zip"
+ },
+ "source": {
+ "url": "https://github.com/themattharris/tmhOAuth.git",
+ "type": "git",
+ "reference": "0.7.2"
+ }
+ }
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "./tmhOAuth.php"
+ ]
+ }
+}
View
@@ -7,12 +7,12 @@
* REST requests. OAuth authentication is sent using the an Authorization Header.
*
* @author themattharris
- * @version 0.7.1
+ * @version 0.7.2
*
- * 27 October 2012
+ * 01 November 2012
*/
class tmhOAuth {
- const VERSION = '0.7.1';
+ const VERSION = '0.7.2';
var $response = array();
@@ -62,7 +62,7 @@ public function __construct($config=array()) {
'curl_ssl_verifypeer' => true,
// you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem
- 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem',
+ 'curl_cainfo' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacert.pem',
'curl_capath' => dirname(__FILE__),
'curl_followlocation' => false, // whether to follow redirects or not
@@ -392,17 +392,22 @@ private function sign($method, $url, $params, $useauth) {
*
* @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
* @param string $url the request URL without query string parameters
- * @param array $params the request parameters as an array of key=value pairs
- * @param string $useauth whether to use authentication when making the request. Default true.
+ * @param array $params the request parameters as an array of key=value pairs. Default empty array
+ * @param string $useauth whether to use authentication when making the request. Default true
* @param string $multipart whether this request contains multipart data. Default false
+ * @param array $headers any custom headers to send with the request. Default empty array
*/
- public function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
+ public function request($method, $url, $params=array(), $useauth=true, $multipart=false, $headers=array()) {
$this->config['multipart'] = $multipart;
$this->create_nonce();
$this->create_timestamp();
$this->sign($method, $url, $params, $useauth);
+
+ if (!empty($headers))
+ $this->headers = array_merge((array)$this->headers, (array)$headers);
+
return $this->curlit();
}
@@ -502,12 +507,9 @@ public function transformText($text, $mode='encode') {
private function curlHeader($ch, $header) {
$this->response['raw'] .= $header;
- $i = strpos($header, ':');
- if ( ! empty($i) ) {
- $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
- $value = trim(substr($header, $i + 2));
- $this->response['headers'][$key] = $value;
- }
+ list($key, $value) = array_pad(explode(':', $header, 2), 2, null);
+ $this->response['headers'][trim($key)] = trim($value);
+
return strlen($header);
}
@@ -624,6 +626,7 @@ private function curlit() {
break;
case 'POST':
curl_setopt($c, CURLOPT_POST, true);
+ curl_setopt($c, CURLOPT_POSTFIELDS, $this->request_params);
break;
default:
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method);
@@ -638,16 +641,8 @@ private function curlit() {
$this->request_params = implode('&', $ps);
}
curl_setopt($c, CURLOPT_POSTFIELDS, $this->request_params);
- } else {
- // CURL will not set the content-length (or set it to -1) when there is no data, which breaks Twitter
- // override this and set the length to 0 in that case.
- $this->headers['Content-Type'] = '';
- $this->headers['Content-Length'] = '0';
}
- // CURL defaults to setting this to Expect: 100-Continue which Twitter rejects
- $this->headers['Expect'] = '';
-
if ( ! empty($this->headers)) {
foreach ($this->headers as $k => $v) {
$headers[] = trim($k . ': ' . $v);

1 comment on commit 6c4a2ae

oz4n commented on 6c4a2ae Dec 8, 2012

helllo body...??
I wanted to ask your permission to use the library to expand my use on Yii Framework. ?
logo.png

Please sign in to comment.