Skip to content

Commit e4d41fb

Browse files
committed
Add Some phpDoc Style Comments
1 parent 36dbefe commit e4d41fb

File tree

1 file changed

+84
-4
lines changed

1 file changed

+84
-4
lines changed

TwitterOAuth.php

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
22

3+
/**
4+
* TwitterOAuth - https://github.com/ricardoper/TwitterOAuth
5+
* PHP library to communicate with Twitter OAuth API version 1.1
6+
*
7+
* @author Ricardo Pereira <github@ricardopereira.es>
8+
* @copyright 2013
9+
*/
10+
311
namespace TwitterOAuth;
412

513
class TwitterOAuth
@@ -19,7 +27,12 @@ class TwitterOAuth
1927
protected $postParams = array();
2028

2129

22-
public function __construct($config)
30+
/**
31+
* Prepare a new conection with Twitter API via OAuth
32+
*
33+
* @params array $config Configuration array with OAuth access data
34+
*/
35+
public function __construct(array $config)
2336
{
2437
$defs = array(
2538
'consumer_key' => '',
@@ -40,7 +53,14 @@ public function __construct($config)
4053
unset($defs, $filters);
4154
}
4255

43-
public function get($call, $getParams = null, $format = null)
56+
/**
57+
* Send a GET call to Twitter API via OAuth
58+
*
59+
* @params string $call Twitter resource string
60+
* @params array $getParams GET parameters to send
61+
* @params string $format Set the response format
62+
*/
63+
public function get($call, array $getParams = null, $format = null)
4464
{
4565
$this->call = $call;
4666

@@ -55,7 +75,15 @@ public function get($call, $getParams = null, $format = null)
5575
return $this->sendRequest();
5676
}
5777

58-
public function post($call, $postParams = null, $getParams = null, $format = null)
78+
/**
79+
* Send a POST call to Twitter API via OAuth
80+
*
81+
* @params string $call Twitter resource string
82+
* @params array $postParams POST parameters to send
83+
* @params array $getParams GET parameters to send
84+
* @params string $format Set the response format
85+
*/
86+
public function post($call, array $postParams = null, array $getParams = null, $format = null)
5987
{
6088
$this->call = $call;
6189

@@ -76,7 +104,13 @@ public function post($call, $postParams = null, $getParams = null, $format = nul
76104
return $this->sendRequest();
77105
}
78106

79-
protected function getParams($params)
107+
/**
108+
* Converting parameters array to a single string with encoded values
109+
*
110+
* @param array $params Input parameters
111+
* @return string Single string with encoded values
112+
*/
113+
protected function getParams(array $params)
80114
{
81115
$r = '';
82116

@@ -91,6 +125,12 @@ protected function getParams($params)
91125
return trim($r, '&');
92126
}
93127

128+
/**
129+
* Getting full URL from a Twitter resource and format
130+
*
131+
* @param bool $withParams If true then parameters will be outputted
132+
* @return string Full URL
133+
*/
94134
protected function getUrl($withParams = false)
95135
{
96136
$getParams = '';
@@ -106,6 +146,11 @@ protected function getUrl($withParams = false)
106146
return $this->url . $this->call . '.' . $this->format . $getParams;
107147
}
108148

149+
/**
150+
* Getting OAuth parameters to be used in request headers
151+
*
152+
* @return array OAuth parameters
153+
*/
109154
protected function getOauthParameters()
110155
{
111156
$time = time();
@@ -120,6 +165,11 @@ protected function getOauthParameters()
120165
);
121166
}
122167

168+
/**
169+
* Converting all parameters arrays to a single string with encoded values
170+
*
171+
* @return string Single string with encoded values
172+
*/
123173
protected function getRequestString()
124174
{
125175
$params = array_merge($this->getParams, $this->postParams, $this->getOauthParameters());
@@ -129,6 +179,11 @@ protected function getRequestString()
129179
return rawurlencode($params);
130180
}
131181

182+
/**
183+
* Getting OAuth signature base string
184+
*
185+
* @return string OAuth signature base string
186+
*/
132187
protected function getSignatureBaseString()
133188
{
134189
$method = strtoupper($this->method);
@@ -138,16 +193,31 @@ protected function getSignatureBaseString()
138193
return $method . '&' . $url . '&' . $this->getRequestString();
139194
}
140195

196+
/**
197+
* Getting a signing key
198+
*
199+
* @return string Signing key
200+
*/
141201
protected function getSigningKey()
142202
{
143203
return $this->config['consumer_secret'] . '&' . $this->config['oauth_token_secret'];
144204
}
145205

206+
/**
207+
* Calculating the signature
208+
*
209+
* @return string Signature
210+
*/
146211
protected function calculateSignature()
147212
{
148213
return base64_encode(hash_hmac('sha1', $this->getSignatureBaseString(), $this->getSigningKey(), true));
149214
}
150215

216+
/**
217+
* Converting OAuth parameters array to a single string with encoded values
218+
*
219+
* @return string Single string with encoded values
220+
*/
151221
protected function getOauthString()
152222
{
153223
$oauth = array_merge($this->getOauthParameters(), array('oauth_signature' => $this->calculateSignature()));
@@ -167,6 +237,11 @@ protected function getOauthString()
167237
return $oauth;
168238
}
169239

240+
/**
241+
* Building request HTTP headers
242+
*
243+
* @return array HTTP headers
244+
*/
170245
protected function buildRequestHeader()
171246
{
172247
return array(
@@ -175,6 +250,11 @@ protected function buildRequestHeader()
175250
);
176251
}
177252

253+
/**
254+
* Send GET or POST requests to Twitter API
255+
*
256+
* @return mixed Response output with the selected format
257+
*/
178258
protected function sendRequest()
179259
{
180260
$url = $this->getUrl(true);

0 commit comments

Comments
 (0)