Implement two basic VKAPI methods: users.get and friends.get
This commit is contained in:
@@ -173,4 +173,63 @@ class Vkontakte extends AbstractProvider
|
||||
return new User($response, $response['id']);
|
||||
}
|
||||
|
||||
// ========== API methods ==========
|
||||
|
||||
/**
|
||||
* @see https://vk.com/dev/users.get
|
||||
*
|
||||
* @param integer[] $ids
|
||||
* @param AccessToken|null $token Current user if empty
|
||||
* @param array $params
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function usersGet(array $ids = [], AccessToken $token = null, array $params = [])
|
||||
{
|
||||
if (empty($ids) && !$token)
|
||||
throw new \InvalidArgumentException('Some of parameters usersIds OR access_token are required');
|
||||
|
||||
$default = [
|
||||
'user_ids' => implode(',', $ids),
|
||||
'fields' => $this->userFields,
|
||||
'access_token' => $token ? $token->getToken() : null,
|
||||
'v' => $this->version,
|
||||
];
|
||||
$params = array_merge($default, $params);
|
||||
$query = $this->buildQueryString($params);
|
||||
$url = "$this->baseUri/users.get?$query";
|
||||
|
||||
$response = $this->getResponse($this->createRequest(static::METHOD_GET, $url, $token, []))['response'];
|
||||
$users = !empty($response['items']) ? $response['items'] : $response;
|
||||
$array2user = function ($userData) { return new User($userData); };
|
||||
|
||||
return array_map($array2user, $users);
|
||||
}
|
||||
/**
|
||||
* @see https://vk.com/dev/friends.get
|
||||
*
|
||||
* @param integer $userId
|
||||
* @param AccessToken|null $token
|
||||
* @param array $params
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function friendsGet($userId, AccessToken $token = null, array $params = [])
|
||||
{
|
||||
$default = [
|
||||
'user_id' => $userId,
|
||||
'fields' => $this->userFields,
|
||||
'access_token' => $token ? $token->getToken() : null,
|
||||
'v' => $this->version,
|
||||
];
|
||||
$params = array_merge($default, $params);
|
||||
$query = $this->buildQueryString($params);
|
||||
$url = "$this->baseUri/friends.get?$query";
|
||||
|
||||
$response = $this->getResponse($this->createRequest(static::METHOD_GET, $url, $token, []))['response'];
|
||||
$friends = !empty($response['items']) ? $response['items'] : $response;
|
||||
$array2friend = function ($friendData) { return new User($friendData); };
|
||||
|
||||
return array_map($array2friend, $friends);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user