Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
php-sdk/src/Api/Apis/Storage.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
309 lines (281 sloc)
9.38 KB
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
<?php | |
/** | |
* @package Oneall PHP SDK | |
* @copyright Copyright 2017-Present http://www.oneall.com | |
* @license GNU/GPL 2 or later | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License | |
* as published by the Free Software Foundation; either version 2 | |
* of the License, or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. | |
* | |
* The "GNU General Public License" (GPL) is available at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
*/ | |
namespace Oneall\Api\Apis; | |
use Oneall\Api\AbstractApi; | |
/** | |
* Class Storage | |
* | |
* @package Oneall\Api\Apis | |
*/ | |
class Storage extends AbstractApi | |
{ | |
const MODE_UPDATE_REPLACE = 'replace'; | |
const MODE_UPDATE_APPEND = 'append'; | |
/** | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return 'storage'; | |
} | |
/** | |
* Add user to storage | |
* | |
* @param string $externalId | |
* @param string $login | |
* @param string $password | |
* @param array $identity All additional user information. http://docs.oneall.com/api/basic/identity-structure/ | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/create-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function createUser( | |
array $identity, | |
$externalId = null, | |
$login = null, | |
$password = null | |
) | |
{ | |
$data = [ | |
"request" => [ | |
"user" => [ | |
"identity" => $identity | |
] | |
] | |
]; | |
$data = $this->addInfo($data, 'request/user/externalid', $externalId); | |
$data = $this->addInfo($data, 'request/user/login', $login); | |
$data = $this->addInfo($data, 'request/user/password', $password); | |
return $this->getClient()->post('/storage/users.json', $data); | |
} | |
/** | |
* Update user data | |
* | |
* @param string $userToken | |
* @param mixed $externalId | |
* @param string $login | |
* @param string $password | |
* @param array $identity All additional user information. http://docs.oneall.com/api/basic/identity-structure/ | |
* @param string $mode | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/update-user/ | |
* | |
* @return null|\Oneall\Client\Response null if nothing to update | |
*/ | |
public function updateUser( | |
$userToken, | |
array $identity = [], | |
$externalId = null, | |
$login = null, | |
$password = null, | |
$mode = self::MODE_UPDATE_REPLACE | |
) | |
{ | |
if (empty($externalId) && empty($login) && empty($password) && empty($identity)) | |
{ | |
return null; | |
} | |
$data = [ | |
"request" => [ | |
'update_mode' => $mode, | |
"user" => [] | |
] | |
]; | |
$data = $this->addInfo($data, 'request/user/externalid', $externalId); | |
$data = $this->addInfo($data, 'request/user/login', $login); | |
$data = $this->addInfo($data, 'request/user/password', $password); | |
$data = $this->addInfo($data, 'request/user/identity', $identity); | |
return $this->getClient()->put('/storage/users/' . $userToken . '.json', $data); | |
} | |
/** | |
* Map an external user id to a user token | |
* | |
* @param $userToken | |
* @param $externalId | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/update-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function mapUserAccount($userToken, $externalId) | |
{ | |
$data = [ | |
"request" => [ | |
"user" => [ | |
"externalid" => $externalId | |
] | |
] | |
]; | |
return $this->getClient()->post('/storage/users/' . $userToken . '.json', $data); | |
} | |
/** | |
* Look up user by its external id. | |
* | |
* @param mixed $externalId | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/lookup-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function lookUpById($externalId) | |
{ | |
$data = [ | |
"request" => [ | |
"user" => [ | |
"externalid" => $externalId | |
] | |
] | |
]; | |
return $this->getClient()->post('/storage/users/user/lookup.json', $data); | |
} | |
/** | |
* Look up user by its credentials | |
* | |
* @param string $login | |
* @param string|null $password | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/lookup-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function lookUpByCredentials($login, $password = null) | |
{ | |
$data = [ | |
"request" => [ | |
"user" => [ | |
"login" => $login | |
] | |
] | |
]; | |
$data = $this->addInfo($data, 'request/user/password', $password); | |
return $this->getClient()->post('/storage/users/user/lookup.json', $data); | |
} | |
/** | |
* Synchronize (create or update automatically) a user by his/her user token | |
* | |
* @param string $userToken | |
* @param mixed $externalId | |
* @param string $login | |
* @param string $password | |
* @param array $identity All additional user information. http://docs.oneall.com/api/basic/identity-structure/ | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/synchronize-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function synchronizeByUserToken($userToken, | |
array $identity = [], | |
$externalId = null, | |
$login = null, | |
$password = null) | |
{ | |
$data = [ | |
"request" => [ | |
"synchronize" => [ | |
"identifier" => [ | |
"field" => "user_token", | |
"value" => $userToken | |
], | |
"user" => [] | |
] | |
] | |
]; | |
$data = $this->addInfo($data, 'request/synchronize/user/externalid', $externalId); | |
$data = $this->addInfo($data, 'request/synchronize/user/login', $login); | |
$data = $this->addInfo($data, 'request/synchronize/user/password', $password); | |
$data = $this->addInfo($data, 'request/synchronize/user/identity', $identity); | |
return $this->getClient()->put('/storage/users/user/synchronize.json', $data); | |
} | |
/** | |
* Synchronize (create or update automatically) a user by his/her user token | |
* | |
* @param string $externalId | |
* @param string $login | |
* @param string $password | |
* @param array $identity All additional user information. http://docs.oneall.com/api/basic/identity-structure/ | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/synchronize-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function synchronizeByExternalId($old_externalId, | |
array $identity = [], | |
$externalId = null, | |
$login = null, | |
$password = null) | |
{ | |
$data = [ | |
"request" => [ | |
"synchronize" => [ | |
"identifier" => [ | |
"field" => "externalid", | |
"value" => $old_externalId | |
], | |
"user" => [] | |
] | |
] | |
]; | |
$data = $this->addInfo($data, 'request/synchronize/user/externalid', $externalId); | |
$data = $this->addInfo($data, 'request/synchronize/user/login', $login); | |
$data = $this->addInfo($data, 'request/synchronize/user/password', $password); | |
$data = $this->addInfo($data, 'request/synchronize/user/identity', $identity); | |
return $this->getClient()->put('/storage/users/user/synchronize.json', $data); | |
} | |
/** | |
* Synchronize (create or update automatically) a user by his/her user token | |
* | |
* @param string $login | |
* @param mixed $externalId | |
* @param string $login | |
* @param string $password | |
* @param array $identity All additional user information. http://docs.oneall.com/api/basic/identity-structure/ | |
* | |
* @see http://docs.oneall.com/api/resources/storage/users/synchronize-user/ | |
* | |
* @return \Oneall\Client\Response | |
*/ | |
public function synchronizeByLogin($old_login, | |
array $identity = [], | |
$externalId = null, | |
$login = null, | |
$password = null) | |
{ | |
$data = [ | |
"request" => [ | |
"synchronize" => [ | |
"identifier" => [ | |
"field" => "login", | |
"value" => $old_login | |
], | |
"user" => [] | |
] | |
] | |
]; | |
$data = $this->addInfo($data, 'request/synchronize/user/externalid', $externalId); | |
$data = $this->addInfo($data, 'request/synchronize/user/login', $login); | |
$data = $this->addInfo($data, 'request/synchronize/user/password', $password); | |
$data = $this->addInfo($data, 'request/synchronize/user/identity', $identity); | |
return $this->getClient()->put('/storage/users/user/synchronize.json', $data); | |
} | |
} |