-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(location): Relocate twitter client in twitter lib
This commit adds classes previously located in twitter-stream in this lib
- Loading branch information
Showing
37 changed files
with
3,599 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
use Symfony\Component\Console\Application; | ||
use Twitter\API\REST\Factory\CodebirdFactory; | ||
use Twitter\API\REST\TwitterApiGateway; | ||
use Twitter\Console\AuthenticationCommand; | ||
|
||
function autoload() | ||
{ | ||
$autoloadFiles = [ | ||
__DIR__.'/../autoload.php', | ||
__DIR__ . '/../vendor/autoload.php', | ||
__DIR__ . '/../../../autoload.php' | ||
]; | ||
|
||
foreach ($autoloadFiles as $autoloadFile) { | ||
if (file_exists($autoloadFile)) { | ||
require_once $autoloadFile; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
function getConfig() | ||
{ | ||
$directories = [ | ||
getcwd(), | ||
getcwd() . DIRECTORY_SEPARATOR . 'config', | ||
__DIR__ . '/..', | ||
__DIR__ . '/../config', | ||
__DIR__ . '/../..', | ||
__DIR__ . '/../../config', | ||
__DIR__ . '/../../../..', | ||
__DIR__ . '/../../../../config' | ||
]; | ||
|
||
$configFile = null; | ||
foreach ($directories as $directory) { | ||
$configFile = $directory . DIRECTORY_SEPARATOR . 'twitter-cli-config.php'; | ||
|
||
if (file_exists($configFile)) { | ||
break; | ||
} | ||
} | ||
|
||
if ($configFile === null || ! file_exists($configFile)) { | ||
showHelp(); | ||
exit(1); | ||
} | ||
|
||
if (! is_readable($configFile)) { | ||
showReadErrorMessage($configFile); | ||
exit(1); | ||
} | ||
|
||
$config = require $configFile; | ||
|
||
if (!is_array($config) || | ||
! isset($config['key']) || | ||
! isset($config['secret']) | ||
) { | ||
echo 'Configuration file must return an array containing the "key", "secret" keys.' . "\n"; | ||
exit(1); | ||
} | ||
|
||
return $config; | ||
} | ||
|
||
function showHelp() | ||
{ | ||
echo <<<HELP | ||
You are missing a "twitter-cli-config.php" or "config/twitter-cli-config.php" file | ||
in your project, which is required to get the Burrow Console working. You can use | ||
the following sample as a template: | ||
<?php | ||
return [ | ||
'key' => '<your_key>', | ||
'secret' => '<your_secret>' | ||
]; | ||
HELP; | ||
} | ||
|
||
/** | ||
* @param $configFile | ||
*/ | ||
function showReadErrorMessage($configFile) | ||
{ | ||
echo 'Configuration file [' . $configFile . '] does not have read permission.' . "\n"; | ||
} | ||
|
||
|
||
autoload(); | ||
$config = getConfig(); | ||
|
||
$application = new Application(); | ||
$application->add( | ||
new AuthenticationCommand( | ||
new TwitterApiGateway( | ||
new CodebirdFactory(), | ||
$config['key'], | ||
$config['secret'] | ||
), | ||
'api:authenticate' | ||
) | ||
); | ||
|
||
$application->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
return [ | ||
'key' => '<your_key>', | ||
'secret' => '<your_secret>' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Twitter\API\Exception; | ||
|
||
class TwitterException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Twitter\API\Exception; | ||
|
||
use Twitter\API\REST\Response\ApiRate; | ||
|
||
class TwitterRateLimitException extends TwitterException | ||
{ | ||
/** @var string */ | ||
private $category; | ||
|
||
/** @var ApiRate */ | ||
private $rate; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCategory() | ||
{ | ||
return $this->category; | ||
} | ||
|
||
/** | ||
* @return \DateTimeInterface | ||
*/ | ||
public function nextWindow() | ||
{ | ||
return $this->rate->nextWindow(); | ||
} | ||
|
||
/** | ||
* @param string $category | ||
* @param ApiRate $rate | ||
* | ||
* @return TwitterRateLimitException | ||
*/ | ||
public static function create($category, ApiRate $rate) | ||
{ | ||
$exception = new self('You have reached rate limit. You cannot make an API call yet.'); | ||
$exception->category = $category; | ||
$exception->rate = $rate; | ||
|
||
return $exception; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Twitter\API\REST; | ||
|
||
interface ApiParameters | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function toArray(); | ||
} |
Oops, something went wrong.