Skip to content

Commit

Permalink
Merge branch 'bugfix/fix-token-checks'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pölönen committed Sep 21, 2016
2 parents 19242ec + a6d0171 commit 7c0c060
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
32 changes: 24 additions & 8 deletions src/classes/NostoAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public static function create(NostoAccountMetaDataInterface $meta)
$params['details'] = $meta->getDetails();
}

$params['use_exchange_rates'] = $meta->getUseCurrencyExchangeRates();
if ($meta->getDefaultVariationId()) {
$params['default_variant_id'] = $meta->getDefaultVariationId();
}

$request = new NostoApiRequest();
$request->setPath(NostoApiRequest::PATH_SIGN_UP);
$request->setReplaceParams(array('{lang}' => $meta->getLanguageCode()));
Expand Down Expand Up @@ -217,17 +222,28 @@ public function isConnectedToNosto()
if (empty($this->tokens)) {
return false;
}
$countTokens = count($this->tokens);
$foundTokens = 0;
foreach (NostoApiToken::getMandatoryApiTokenNames() as $name) {
if ($this->getApiToken($name) === null) {
return false;
}
}
return true;
}

/**
* @inheritdoc
*/
public function hasMissingTokens()
{
if (empty($this->tokens)) {
return true;
}
foreach (NostoApiToken::getApiTokenNames() as $name) {
foreach ($this->tokens as $token) {
if ($token->name === $name) {
$foundTokens++;
break;
}
if ($this->getApiToken($name) === null) {
return true;
}
}
return ($countTokens === $foundTokens);
return false;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/classes/api/NostoApiToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ public static function getApiTokenNames()
return self::$tokenNames;
}

/**
* Returns mandatory API token names.
*
* @return array the token names.
*/
public static function getMandatoryApiTokenNames()
{
return array(
self::API_SSO,
self::API_PRODUCTS
);
}

/**
* Returns the token name.
*
Expand Down
10 changes: 9 additions & 1 deletion src/interfaces/account/NostoAccountInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ public function delete();
public function getName();

/**
* Checks if this account has been connected to Nosto, i.e. all API tokens exist.
* Checks if this account has been connected to Nosto,
* i.e. all mandatory API tokens exist.
*
* @return bool true if it is connected, false otherwise.
*/
public function isConnectedToNosto();

/**
* Checks if this account has all API tokens
*
* @return bool true if some token(s) are missing, false otherwise.
*/
public function hasMissingTokens();

/**
* Gets an api token associated with this account by it's name , e.g. "sso".
*
Expand Down

0 comments on commit 7c0c060

Please sign in to comment.