-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unable to switch API version on service (#356)
- Loading branch information
Showing
5 changed files
with
91 additions
and
55 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
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atymic\Twitter\Concern; | ||
|
||
use Atymic\Twitter\Contract\Configuration; | ||
use Atymic\Twitter\Contract\Querier; | ||
use Atymic\Twitter\Twitter; | ||
use InvalidArgumentException; | ||
|
||
trait HotSwapper | ||
{ | ||
abstract public function getQuerier(): Querier; | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function usingCredentials( | ||
string $accessToken, | ||
string $accessTokenSecret, | ||
?string $consumerKey = null, | ||
?string $consumerSecret = null | ||
): Twitter { | ||
return $this->setQuerier( | ||
$this->getQuerier() | ||
->usingCredentials( | ||
$accessToken, | ||
$accessTokenSecret, | ||
$consumerKey, | ||
$consumerSecret | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function usingConfiguration(Configuration $configuration): Twitter | ||
{ | ||
return $this->setQuerier( | ||
$this->getQuerier() | ||
->usingConfiguration($configuration) | ||
); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function forApiV1(): Twitter | ||
{ | ||
$config = $this->getQuerier() | ||
->getConfiguration(); | ||
|
||
return $this->usingConfiguration($config->forApiV1()); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function forApiV2(): Twitter | ||
{ | ||
$config = $this->getQuerier() | ||
->getConfiguration(); | ||
|
||
return $this->usingConfiguration($config->forApiV2()); | ||
} | ||
} |
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
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