Skip to content

Commit

Permalink
PSR-2 code autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Ratushnyi committed Jan 4, 2016
1 parent 83851a1 commit 0763ee4
Show file tree
Hide file tree
Showing 18 changed files with 2,175 additions and 2,067 deletions.
361 changes: 181 additions & 180 deletions example.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<phpunit colors="true" bootstrap="./vendor/autoload.php">
<php>
<ini name="error_reporting" value="-1" />
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Smartling API SDK PHP Test Suite">
Expand Down
29 changes: 15 additions & 14 deletions src/AuthApi/AuthApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
*
* @package Smartling\Auth
*/
interface AuthApiInterface {
interface AuthApiInterface
{

/**
* @return string token
* @throws InvalidAccessTokenException
*/
public function getAccessToken ();
/**
* @return string token
* @throws InvalidAccessTokenException
*/
public function getAccessToken();

/**
* @return string
*/
public function getTokenType ();
/**
* @return string
*/
public function getTokenType();

/**
* @return void
*/
public function resetToken ();
/**
* @return void
*/
public function resetToken();
}
227 changes: 119 additions & 108 deletions src/AuthApi/AuthTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,112 +7,123 @@
use Smartling\BaseApiAbstract;
use Smartling\Helpers\HttpVerbHelper;

class AuthTokenProvider extends BaseApiAbstract implements AuthApiInterface {

const ENDPOINT_URL = 'https://api.smartling.com/auth-api/v2/';

/**
* @var string
*/
private $userIdentifier;

/**
* @var string
*/
private $secretKey;

/**
* @var array
*/
private $data;

/**
* @return string
*/
private function getUserIdentifier () {
return $this->userIdentifier;
}

/**
* @param string $userIdentifier
*/
private function setUserIdentifier ( $userIdentifier ) {
$this->userIdentifier = $userIdentifier;
}

/**
* @return string
*/
private function getSecretKey () {
return $this->secretKey;
}

/**
* @param string $secretKey
*/
private function setSecretKey ( $secretKey ) {
$this->secretKey = $secretKey;
}

/**
* AuthTokenProvider constructor.
*
* @param string $userIdentifier
* @param string $secretKey
* @param ClientInterface $client
* @param LoggerInterface $logger
*/
public function __construct ( $userIdentifier, $secretKey, ClientInterface $client, $logger = null ) {
parent::__construct( '', $client, $logger, self::ENDPOINT_URL );

$this->setUserIdentifier( $userIdentifier );
$this->setSecretKey( $secretKey );
}

/**
* Creates and returns instance of AuthTokenProvider
*
* @param string $userIdentifier
* @param string $secretKey
* @param LoggerInterface $logger
*
* @return AuthTokenProvider
*/
public static function create ( $userIdentifier, $secretKey, $logger = null ) {

$client = self::initializeHttpClient( self::ENDPOINT_URL );

return new self( $userIdentifier, $secretKey, $client, $logger );
}


/**
* @inheritdoc
*/
public function getAccessToken () {
$this->data = $this->sendRequest( 'authenticate', [ ], HttpVerbHelper::HTTP_VERB_POST );

return $this->data['accessToken'];
}

/**
* @inheritdoc
*/
public function getTokenType () {
return isset( $this->data['tokenType'] ) ? $this->data['tokenType'] : '';
}

/**
* @inheritdoc
*/
public function resetToken () {
$this->data = [ ];
}

protected function sendRequest ( $uri, array $requestData, $method ) {
$requestData['userIdentifier'] = $this->getUserIdentifier();
$requestData['userSecret'] = $this->getSecretKey();

return parent::sendRequest( $uri, $requestData, $method, self::STRATEGY_AUTH );
}
class AuthTokenProvider extends BaseApiAbstract implements AuthApiInterface
{

const ENDPOINT_URL = 'https://api.smartling.com/auth-api/v2/';

/**
* @var string
*/
private $userIdentifier;

/**
* @var string
*/
private $secretKey;

/**
* @var array
*/
private $data;

/**
* @return string
*/
private function getUserIdentifier()
{
return $this->userIdentifier;
}

/**
* @param string $userIdentifier
*/
private function setUserIdentifier($userIdentifier)
{
$this->userIdentifier = $userIdentifier;
}

/**
* @return string
*/
private function getSecretKey()
{
return $this->secretKey;
}

/**
* @param string $secretKey
*/
private function setSecretKey($secretKey)
{
$this->secretKey = $secretKey;
}

/**
* AuthTokenProvider constructor.
*
* @param string $userIdentifier
* @param string $secretKey
* @param ClientInterface $client
* @param LoggerInterface $logger
*/
public function __construct($userIdentifier, $secretKey, ClientInterface $client, $logger = null)
{
parent::__construct('', $client, $logger, self::ENDPOINT_URL);

$this->setUserIdentifier($userIdentifier);
$this->setSecretKey($secretKey);
}

/**
* Creates and returns instance of AuthTokenProvider
*
* @param string $userIdentifier
* @param string $secretKey
* @param LoggerInterface $logger
*
* @return AuthTokenProvider
*/
public static function create($userIdentifier, $secretKey, $logger = null)
{

$client = self::initializeHttpClient(self::ENDPOINT_URL);

return new self($userIdentifier, $secretKey, $client, $logger);
}


/**
* @inheritdoc
*/
public function getAccessToken()
{
$this->data = $this->sendRequest('authenticate', [], HttpVerbHelper::HTTP_VERB_POST);

return $this->data['accessToken'];
}

/**
* @inheritdoc
*/
public function getTokenType()
{
return isset($this->data['tokenType']) ? $this->data['tokenType'] : '';
}

/**
* @inheritdoc
*/
public function resetToken()
{
$this->data = [];
}

protected function sendRequest($uri, array $requestData, $method)
{
$requestData['userIdentifier'] = $this->getUserIdentifier();
$requestData['userSecret'] = $this->getSecretKey();

return parent::sendRequest($uri, $requestData, $method, self::STRATEGY_AUTH);
}
}
Loading

0 comments on commit 0763ee4

Please sign in to comment.