Update Koneko integration
This commit is contained in:
80
resources/public/vendor/rs-plugin/php/twitter/connection/Application.php
vendored
Normal file
80
resources/public/vendor/rs-plugin/php/twitter/connection/Application.php
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace TwitterPhp\Connection;
|
||||
|
||||
use TwitterPhp\RestApiException;
|
||||
|
||||
class Application extends Base
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_consumerKey;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_consumerSecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_bearersToken = null;
|
||||
|
||||
/**
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
public function __construct($consumerKey,$consumerSecret)
|
||||
{
|
||||
$this->_consumerKey = $consumerKey;
|
||||
$this->_consumerSecret = $consumerSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $parameters
|
||||
* @param $method
|
||||
* @return array
|
||||
*/
|
||||
protected function _buildHeaders($url,array $parameters = null,$method)
|
||||
{
|
||||
return $headers = array(
|
||||
"Authorization: Bearer " . $this->_getBearerToken()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bearer token
|
||||
*
|
||||
* @link https://dev.twitter.com/docs/auth/application-only-auth
|
||||
*
|
||||
* @throws \TwitterPhp\RestApiException
|
||||
* @return string
|
||||
*/
|
||||
private function _getBearerToken() {
|
||||
if (!$this->_bearersToken) {
|
||||
$token = urlencode($this->_consumerKey) . ':' . urlencode($this->_consumerSecret);
|
||||
$token = base64_encode($token);
|
||||
|
||||
$headers = array(
|
||||
"Authorization: Basic " . $token
|
||||
);
|
||||
|
||||
$options = array (
|
||||
CURLOPT_URL => self::TWITTER_API_AUTH_URL,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => "grant_type=client_credentials"
|
||||
);
|
||||
|
||||
$response = $this->_callApi($options);
|
||||
|
||||
if (isset($response["token_type"]) && $response["token_type"] == 'bearer') {
|
||||
$this->_bearersToken = $response["access_token"];
|
||||
} else {
|
||||
throw new RestApiException('Error while getting access token');
|
||||
}
|
||||
}
|
||||
return $this->_bearersToken;
|
||||
}
|
||||
}
|
120
resources/public/vendor/rs-plugin/php/twitter/connection/ConnectionAbstract.php
vendored
Normal file
120
resources/public/vendor/rs-plugin/php/twitter/connection/ConnectionAbstract.php
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
namespace TwitterPhp\Connection;
|
||||
|
||||
/**
|
||||
* Class Base
|
||||
* @package TwitterPhp
|
||||
* @subpackage Connection
|
||||
*/
|
||||
abstract class Base
|
||||
{
|
||||
/**
|
||||
* Url for Twitter api
|
||||
*/
|
||||
const TWITTER_API_URL = 'https://api.twitter.com';
|
||||
|
||||
/**
|
||||
* Twitter URL that authenticates bearer tokens
|
||||
*/
|
||||
const TWITTER_API_AUTH_URL = 'https://api.twitter.com/oauth2/token/';
|
||||
|
||||
/**
|
||||
* Version of Twitter api
|
||||
*/
|
||||
const TWITTER_API_VERSION = '1.1';
|
||||
|
||||
/**
|
||||
* Timeout value for curl connections
|
||||
*/
|
||||
const DEFAULT_TIMEOUT = 10;
|
||||
|
||||
/**
|
||||
* METHOD GET
|
||||
*/
|
||||
const METHOD_GET = 'GET';
|
||||
|
||||
/**
|
||||
* METHOD POST
|
||||
*/
|
||||
const METHOD_POST = 'POST';
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $parameters
|
||||
* @param $method
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function _buildHeaders($url,array $parameters = null,$method);
|
||||
|
||||
|
||||
/**
|
||||
* Do GET request to Twitter api
|
||||
*
|
||||
* @link https://dev.twitter.com/docs/api/1.1
|
||||
*
|
||||
* @param $resource
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($resource, array $parameters = array())
|
||||
{
|
||||
$url = $this->_prepareUrl($resource);
|
||||
$headers = $this->_buildHeaders($url,$parameters,self::METHOD_GET);
|
||||
$url = $url . '?' . http_build_query($parameters);
|
||||
$curlParams = array (
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_HTTPHEADER => $headers
|
||||
);
|
||||
|
||||
return $this->_callApi($curlParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do POST request to Twitter api
|
||||
*
|
||||
* @link https://dev.twitter.com/docs/api/1.1
|
||||
*
|
||||
* @param $resource
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($resource, array $parameters = array())
|
||||
{
|
||||
$url = $this->_prepareUrl($resource);
|
||||
$headers = $this->_buildHeaders($url,$parameters,self::METHOD_POST);
|
||||
$curlParams = array (
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => $parameters,
|
||||
CURLOPT_HTTPHEADER => $headers
|
||||
);
|
||||
|
||||
return $this->_callApi($curlParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Twitter api
|
||||
*
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
protected function _callApi(array $params)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl,$params);
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, self::DEFAULT_TIMEOUT);
|
||||
$response = curl_exec($curl);
|
||||
return json_decode($response,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $resource
|
||||
* @return string
|
||||
*/
|
||||
private function _prepareUrl($resource)
|
||||
{
|
||||
return self::TWITTER_API_URL . '/' . self::TWITTER_API_VERSION . '/' . ltrim($resource,'/') . '.json';
|
||||
}
|
||||
}
|
92
resources/public/vendor/rs-plugin/php/twitter/connection/User.php
vendored
Normal file
92
resources/public/vendor/rs-plugin/php/twitter/connection/User.php
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace TwitterPhp\Connection;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_consumerKey;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_consumerSecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_accessToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_accessTokenSecret;
|
||||
|
||||
/**
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
* @param string $accessToken
|
||||
* @param string $accessTokenSecret
|
||||
*/
|
||||
public function __construct($consumerKey,$consumerSecret,$accessToken,$accessTokenSecret)
|
||||
{
|
||||
$this->_consumerKey = $consumerKey;
|
||||
$this->_consumerSecret = $consumerSecret;
|
||||
$this->_accessToken = $accessToken;
|
||||
$this->_accessTokenSecret = $accessTokenSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $parameters
|
||||
* @param $method
|
||||
* @return array
|
||||
*/
|
||||
protected function _buildHeaders($url,array $parameters = null,$method)
|
||||
{
|
||||
$oauthHeaders = array(
|
||||
'oauth_version' => '1.0',
|
||||
'oauth_consumer_key' => $this->_consumerKey,
|
||||
'oauth_nonce' => time(),
|
||||
'oauth_signature_method' => 'HMAC-SHA1',
|
||||
'oauth_token' => $this->_accessToken,
|
||||
'oauth_timestamp' => time()
|
||||
);
|
||||
|
||||
$data = $oauthHeaders;
|
||||
if ($method == self::METHOD_GET) {
|
||||
$data = array_merge($oauthHeaders,$parameters);
|
||||
}
|
||||
$oauthHeaders['oauth_signature'] = $this->_buildOauthSignature($url,$data,$method);
|
||||
ksort($oauthHeaders);
|
||||
$oauthHeader = array();
|
||||
|
||||
foreach($oauthHeaders as $key => $value) {
|
||||
$oauthHeader[] = $key . '="' . rawurlencode($value) . '"';
|
||||
}
|
||||
|
||||
$headers[] = 'Authorization: OAuth ' . implode(', ', $oauthHeader);
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param array $params
|
||||
* @param $method
|
||||
* @return string
|
||||
*/
|
||||
private function _buildOauthSignature($url,array $params,$method)
|
||||
{
|
||||
ksort($params);
|
||||
$sortedParams = array();
|
||||
|
||||
foreach($params as $key=>$value) {
|
||||
$sortedParams[] = $key . '=' . $value;
|
||||
}
|
||||
|
||||
$signatureBaseString = $method . "&" . rawurlencode($url) . '&' . rawurlencode(implode('&', $sortedParams));
|
||||
$compositeKey = rawurlencode($this->_consumerSecret) . '&' . rawurlencode($this->_accessTokenSecret);
|
||||
return base64_encode(hash_hmac('sha1', $signatureBaseString, $compositeKey, true));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user