Commit ca6bf859 authored by Max Koder's avatar Max Koder

FIX and MAJ README

parent ad2da87d
......@@ -9,7 +9,7 @@ if ( $app === false) {
throw new Exception('Problem during register app');
}
$token = $app->getAccessToken('write_here_your_token_got_in_step_1');
$token = $app->registerAccessToken('write_here_your_token_got_in_step_1');
$bearer_token = $app->authentify("your_email@mail.com", "Your_Password");
......
This diff is collapsed.
......@@ -9,11 +9,20 @@ if ( $app === false) {
throw new Exception('Problem during register app');
}
var_dump($app->getUser());
//var_dump($app->getUser());
//
//var_dump($app->getFavourites());
//var_dump($app->getAccount(1));
//var_dump($app->getAccount(1629));
//var_dump($app->getFollowers(1629));
//var_dump($app->postStatus('This status is posted by #PHP'));
\ No newline at end of file
//var_dump($app->getFollowing(1629));
//var_dump($app->postStatus('This status is posted by #PHP'));
//var_dump($app->getStatuses('1629', ['only_media' => true]));
//var_dump($app->getStatuses('1629'));
//var_dump($app->getFollowers(1629, ['limit' => 5]));
\ No newline at end of file
......@@ -7,6 +7,7 @@
* @link http://max-koder.fr
* @link https://framagit.org/MaxKoder/TootoPHP
* @package TootoPHP
* @version 1.0.0
* @license http://opensource.org/licenses/MIT The MIT License
*/
......@@ -105,9 +106,13 @@ class HttpRequest
protected function request($method, $url, $headers = [], $params = [])
{
$opts = $this->getDefaultOpts($method);
$opts['http']['content'] = $this->encodeParameters($params);
if ($method === 'GET' && !empty($params)) {
$url .= '?' . $this->encodeParameters($params);
}
else {
$opts['http']['content'] = $this->encodeParameters($params);
}
$opts['http']['header'] = $this->encodeHeaders($headers);
$context = stream_context_create($opts);
$response = @file_get_contents($this->domainURL . $url, null, $context);
if ($response !== false) {
......@@ -117,12 +122,7 @@ class HttpRequest
return false;
}
if ($json !== null) {
return $json;
}
else {
return $response;
}
return ($json !== null) ? $json : $response ;
}
/**
......
......@@ -7,6 +7,7 @@
* @link http://max-koder.fr
* @link https://framagit.org/MaxKoder/TootoPHP
* @package TootoPHP
* @version 1.0.0
* @license http://opensource.org/licenses/MIT The MIT License
*/
......@@ -142,7 +143,7 @@ class TootoPHP
* @param string $authCode
* @return boolean|string
*/
public function getAccessToken($authCode)
public function registerAccessToken($authCode)
{
if (is_array($this->appCredentials) && isset($this->appCredentials['client_id'])) {
// Exchange Access Token for our Auth Token
......@@ -188,11 +189,12 @@ class TootoPHP
$this->headers,
null
);
var_dump($user);
echo 'ooo';
if (is_array($user) && isset($user['username'])) {
$this->userInfos = $user;
}
else {
return false;
}
}
return $this->userInfos;
}
......@@ -205,6 +207,9 @@ class TootoPHP
public function getUserID()
{
$user = $this->getUser();
if (!is_array($user)) {
return false;
}
return $user['id'];
}
......@@ -223,6 +228,21 @@ class TootoPHP
null
);
}
/**
* Get authenticated user's notifications
* Return as an array all user's notifications
*
* @return array
*/
public function getNotifications()
{
return $this->http->get(
$this->http->apiURL . 'notifications',
$this->headers,
null
);
}
/**
* Get an account by his ID
......@@ -264,20 +284,75 @@ class TootoPHP
/**
* Get user's followers by his ID
* If not ID is given, return the authenticated user's followers
*
* Return all followers as an array
*
* @param string $id
* @param array $params
* Params is optionnal associative array with these keys :
* limit : Maximum number of accounts to get (Default 40, Max 80)
* max_id : Get a list of followers with ID less than or equal this value
* since_id : Get a list of followers with ID greater than this value
* @return array
*/
public function getFollowers($id)
public function getFollowers($id = false, $params = [])
{
if ($id === false) {
$id = $this->getUserID();
}
return $this->http->get(
$this->http->apiURL . 'accounts/' . $id . '/followers',
$this->headers,
$params
);
}
/**
* Get user's following by his ID
* If not ID is given, return the authenticated user's following
*
* Return all followings as an array
*
* @param string $id
* @return array
*/
public function getFollowing($id = false)
{
if ($id === false) {
$id = $this->getUserID();
}
return $this->http->get(
$this->http->apiURL . 'accounts/' . $id . '/following',
$this->headers,
null
);
}
/**
* Get user's statuses by his ID
* If not ID is given, return the authenticated user's statuses
*
* Return all statuses as an array
*
* @param string $id
* @param array $params
* Params is optionnal associative array with these keys :
* only_media : Only return statuses that have media attachments
* exclude_replies : Skip statuses that reply to other statuses
* @return array
*/
public function getStatuses($id = false, $params = [])
{
if ($id === false) {
$id = $this->getUserID();
}
return $this->http->get(
$this->http->apiURL . 'accounts/' . $id . '/statuses',
$this->headers,
$params
);
}
/**
* Authentify user
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment