Merge pull request #4104 from Rudloff/feature/incoming_api

Implement friendships/incoming and users/lookup APIs
This commit is contained in:
Hypolite Petovan 2017-12-19 05:39:23 -05:00 committed by GitHub
commit 256bf2e888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 6 deletions

View file

@ -504,6 +504,15 @@ Friendica doesn't allow showing followers of other users.
Friendica doesn't allow showing friends of other users. Friendica doesn't allow showing friends of other users.
---
### users/lookup (*; AUTH)
#### Parameters
* user_id: list of ids to lookup
#### Unsupported parameters
* screen_name
* include_entities
--- ---
### account/update_profile_image (POST; AUTH) ### account/update_profile_image (POST; AUTH)
@ -939,6 +948,12 @@ General description of profile data in API returns:
* description ... homepage: different data fields from 'profile' table in database * description ... homepage: different data fields from 'profile' table in database
* users: array with the users allowed to view this profile (empty if is_default=true) * users: array with the users allowed to view this profile (empty if is_default=true)
---
### friendships/incoming (*; AUTH)
#### Unsupported parameters
* cursor
* stringify_ids
--- ---
## Not Implemented API calls ## Not Implemented API calls
@ -963,7 +978,6 @@ The following API calls from the Twitter API are not implemented in either Frien
* direct_messages/show * direct_messages/show
* search/tweets * search/tweets
* friendships/no_retweets/ids * friendships/no_retweets/ids
* friendships/incoming
* friendships/outgoing * friendships/outgoing
* friendships/update * friendships/update
* friends/list * friends/list
@ -973,7 +987,6 @@ The following API calls from the Twitter API are not implemented in either Frien
* account/update_profile * account/update_profile
* account/update_profile_background_image * account/update_profile_background_image
* blocks/ids * blocks/ids
* users/lookup
* users/show * users/show
* users/search * users/search
* account/remove_profile_banner * account/remove_profile_banner

View file

@ -1517,6 +1517,39 @@ function api_users_search($type)
/// @TODO move to top of file or somewhere better /// @TODO move to top of file or somewhere better
api_register_func('api/users/search', 'api_users_search'); api_register_func('api/users/search', 'api_users_search');
/**
* Return user objects
*
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup
*
* @param string $type Return format: json or xml
*
* @return array|string
* @throws UnauthorizedException
* @throws NotFoundException
*/
function api_users_lookup($type)
{
$users = array();
if (x($_REQUEST['user_id'])) {
foreach (explode(',', $_REQUEST['user_id']) as $id) {
if (!empty($id)) {
$users[] = api_get_user(get_app(), $id);
}
}
}
if (empty($users)) {
throw new NotFoundException;
}
return api_format_data("users", $type, array('users' => $users));
}
/// @TODO move to top of file or somewhere better
api_register_func('api/users/lookup', 'api_users_lookup', true);
/** /**
* Returns statuses that match a specified query. * Returns statuses that match a specified query.
* *
@ -3147,9 +3180,11 @@ function api_statuses_f($qtype)
} }
if ($qtype == 'blocks') { if ($qtype == 'blocks') {
$sql_blocked = 'AND `blocked`'; $sql_filter = 'AND `blocked` AND NOT `pending`';
} elseif ($qtype == 'incoming') {
$sql_filter = 'AND `pending`';
} else { } else {
$sql_blocked = 'AND NOT `blocked`'; $sql_filter = 'AND (NOT `blocked` OR `pending`)';
} }
$r = q( $r = q(
@ -3157,8 +3192,7 @@ function api_statuses_f($qtype)
FROM `contact` FROM `contact`
WHERE `uid` = %d WHERE `uid` = %d
AND NOT `self` AND NOT `self`
$sql_blocked $sql_filter
AND NOT `pending`
$sql_extra $sql_extra
ORDER BY `nick` ORDER BY `nick`
LIMIT %d, %d", LIMIT %d, %d",
@ -3243,6 +3277,34 @@ function api_blocks_list($type)
/// @TODO move to top of file or somewhere better /// @TODO move to top of file or somewhere better
api_register_func('api/blocks/list', 'api_blocks_list', true); api_register_func('api/blocks/list', 'api_blocks_list', true);
/**
* Returns the list of pending users IDs
*
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming
*
* @param string $type Either "json" or "xml"
*
* @return boolean|string|array
* @throws UnauthorizedException
*/
function api_friendships_incoming($type)
{
$data = api_statuses_f('incoming');
if ($data === false) {
return false;
}
$ids = array();
foreach ($data['user'] as $user) {
$ids[] = $user['id'];
}
return api_format_data("ids", $type, array('id' => $ids));
}
/// @TODO move to top of file or somewhere better
api_register_func('api/friendships/incoming', 'api_friendships_incoming', true);
function api_statusnet_config($type) function api_statusnet_config($type)
{ {
$a = get_app(); $a = get_app();