/// <summary> /// Returns a list of user IDs of the mutual friends of two users. /// </summary> /// <param name="targetUids">IDs of the users whose friends will be checked against the friends of the user specified in source_uid.</param> /// <param name="sourceUid">ID of the user whose friends will be checked against the friends of the user specified in target_uid.</param> /// <param name="order">Sort order.</param> /// <param name="count">Number of friends to return.</param> /// <param name="offset">Offset needed to return a specific subset of friends.</param> /// <returns>Returns a <see cref="MutualFriends"/> object containing info about mutual friends.</returns> public async Task <Response <List <MutualFriends> > > GetMutual(List <int> targetUids, int?sourceUid = null, FriendsOrder order = FriendsOrder.Hints, int?count = null, int offset = 0) => await Request <List <MutualFriends> >("getMutual", new MethodParams { { "target_uids", string.Join(",", targetUids ?? new List <int>()) }, { "source_uid", sourceUid }, { "order", Utils.ToEnumString(order) }, { "count", count }, { "offset", offset } });
/// <summary> /// Returns a list of user IDs of a user's friends who are online. /// </summary> /// <param name="userId">User ID. By default, the current user ID.</param> /// <param name="listId">Friend list ID. If this parameter is not set, information about all online friends is returned. </param> /// <param name="order">Sort order.</param> /// <param name="count">Number of friends to return.</param> /// <param name="offset">Offset needed to return a specific subset of friends.</param> /// <returns>Return an <see cref="OnlineFriends"/> containing info about online fiends.</returns> public async Task<Response<OnlineFriends>> GetOnline(int? userId = null, int? listId = null, FriendsOrder order = FriendsOrder.Hints, int? count = null, int offset = 0) => await Request<OnlineFriends>("getOnline", new MethodParams { {"user_id", userId}, {"list_id", listId}, {"online_mobile", true}, {"order", Utils.ToEnumString(order)}, {"count", count}, {"offset", offset} });
public void FriendsOrderTest() { // get test Assert.That(FriendsOrder.Name.ToString(), Is.EqualTo("name")); Assert.That(FriendsOrder.Hints.ToString(), Is.EqualTo("hints")); Assert.That(FriendsOrder.Random.ToString(), Is.EqualTo("random")); // parse test Assert.That(FriendsOrder.FromJsonString("name"), Is.EqualTo(FriendsOrder.Name)); Assert.That(FriendsOrder.FromJsonString("hints"), Is.EqualTo(FriendsOrder.Hints)); Assert.That(FriendsOrder.FromJsonString("random"), Is.EqualTo(FriendsOrder.Random)); }
/// <summary> /// Returns a list of user IDs of a user's friends who are online. /// </summary> /// <param name="userId">User ID. By default, the current user ID.</param> /// <param name="listId">Friend list ID. If this parameter is not set, information about all online friends is returned. </param> /// <param name="order">Sort order.</param> /// <param name="count">Number of friends to return.</param> /// <param name="offset">Offset needed to return a specific subset of friends.</param> /// <returns>Return an <see cref="OnlineFriends"/> containing info about online fiends.</returns> public async Task <Response <OnlineFriends> > GetOnline(int?userId = null, int?listId = null, FriendsOrder order = FriendsOrder.Hints, int?count = null, int offset = 0) => await Request <OnlineFriends>("getOnline", new MethodParams { { "user_id", userId }, { "list_id", listId }, { "online_mobile", true }, { "order", Utils.ToEnumString(order) }, { "count", count }, { "offset", offset } });
public void FriendsOrderTest() { // get test Assert.That(actual: FriendsOrder.Name.ToString(), expression: Is.EqualTo(expected: "name")); Assert.That(actual: FriendsOrder.Hints.ToString(), expression: Is.EqualTo(expected: "hints")); Assert.That(actual: FriendsOrder.Random.ToString(), expression: Is.EqualTo(expected: "random")); // parse test Assert.That(actual: FriendsOrder.FromJsonString(response: "name"), expression: Is.EqualTo(expected: FriendsOrder.Name)); Assert.That(actual: FriendsOrder.FromJsonString(response: "hints"), expression: Is.EqualTo(expected: FriendsOrder.Hints)); Assert.That(actual: FriendsOrder.FromJsonString(response: "random"), expression: Is.EqualTo(expected: FriendsOrder.Random)); }
public ReadOnlyCollection<User> Get(long uid, ProfileFields fields = null, int? count = null, int? offset = null, FriendsOrder order = null, NameCase nameCase = null, int? listId = null) { if(listId != null && listId < 0) throw new ArgumentOutOfRangeException("listId", "listId must be a positive number."); var parameters = new VkParameters { { "user_id", uid }, { "fields", fields }, { "count", count }, { "offset", offset }, { "order", order }, {"list_id", listId} , {"name_case", nameCase}}; var response = _vk.Call("friends.get", parameters); if (fields != null) return response["items"].ToReadOnlyCollectionOf<User>(x => x); return response.ToReadOnlyCollectionOf(id => new User { Id = id }); }
public async Task<VkItemsResponse<VkProfile>> Get(long userId, string fields, string nameCase, int count, int offset, FriendsOrder order = FriendsOrder.ByName) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) throw new Exception("Access token is not valid."); var parameters = new Dictionary<string, string>(); if (userId > 0) parameters.Add("user_id", userId.ToString()); if (!string.IsNullOrWhiteSpace(fields)) parameters.Add("fields", fields); if (!string.IsNullOrWhiteSpace(nameCase)) parameters.Add("name_case", nameCase); if (count > 0) parameters.Add("count", count.ToString()); if (offset > 0) parameters.Add("offset", offset.ToString()); switch (order) { case FriendsOrder.ByName: parameters.Add("order", "name"); break; case FriendsOrder.ByRating: parameters.Add("order", "hints"); break; case FriendsOrder.Random: parameters.Add("order", "random"); break; } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "friends.get"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { return new VkItemsResponse<VkProfile>(response["response"]["items"].Select(VkProfile.FromJson).ToList(), (int)response["response"]["count"]); } return VkItemsResponse<VkProfile>.Empty; }
public ReadOnlyCollection<User> GetAll(long uid, ProfileFields fields = null, FriendsOrder order = null, NameCase nameCase = null, int? listId = null) { const int count = 50; var i = 0; var result = new List<User>(); do { var currentItems = _friends.Get(uid, fields, count, i * count, order, nameCase, listId); if (currentItems != null) result.AddRange(currentItems); } while (++i * count < (_vk.CountFromLastResponse ?? 0)); return result.ToReadOnlyCollection(); }
/// <summary> /// Returns a list of user IDs or detailed information about a user's friends. /// </summary> /// <param name="userId">User ID. By default, the current user ID.</param> /// <param name="order">Sort order.</param> /// <param name="listId">ID of the friend list returned by the <see cref="GetLists"/> method to be used as the source. This parameter is taken into account only when the uid parameter is set to the current user ID. </param> /// <param name="count">Number of friends to return.</param> /// <param name="offset">Offset needed to return a specific subset of friends.</param> /// <param name="fields">Profile fields to return.</param> /// <param name="nameCase">Case for declension of user name and surname.</param> /// <returns>Returns a <see cref="List{T}"/> of <see cref="User"/> objects.</returns> public async Task<Response<ItemsList<User>>> Get(int? userId = null, FriendsOrder order = FriendsOrder.Hints, int? listId = null, int? count = null, int offset = 0, List<UserProfileFields> fields = null, NameCases nameCase = NameCases.Nominative) => await Request<ItemsList<User>>("get", new MethodParams { {"user_id", userId}, {"order", Utils.ToEnumString(order)}, {"list_id", listId}, {"count", count}, {"offset", offset}, { "fields", fields == null || !fields.Any() ? new List<UserProfileFields> {UserProfileFields.Nickname} : fields }, {"name_case", Utils.ToEnumString(nameCase)} }, true);
public ReadOnlyCollection<User> Get(long uid, ProfileFields fields = null, int? count = null, int? offset = null, FriendsOrder order = null, NameCase nameCase = null, int? listId = null) { if (listId != null && listId < 0) throw new ArgumentOutOfRangeException("listId", "listId must be a positive number."); var parameters = new FriendsGetParams { UserId = uid, Count = count, Offset = offset, Fields = fields, NameCase = nameCase, ListId = listId, Order = order }; return Get(parameters).ToReadOnlyCollection(); }
public ReadOnlyCollection <User> Get(long uid, ProfileFields fields = null, int?count = null, int?offset = null, FriendsOrder order = null) { var parameters = new VkParameters { { "uid", uid }, { "fields", fields }, { "count", count }, { "offset", offset }, { "order", order } }; var response = _vk.Call("friends.get", parameters); if (fields != null) { return(response.ToReadOnlyCollectionOf <User>(x => x)); } return(response.ToReadOnlyCollectionOf(id => new User { Id = id })); }
public async Task <VkItemsResponse <VkProfile> > Get(long userId, string fields, string nameCase, int count, int offset, FriendsOrder order = FriendsOrder.ByName) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (userId > 0) { parameters.Add("user_id", userId.ToString()); } if (!string.IsNullOrWhiteSpace(fields)) { parameters.Add("fields", fields); } if (!string.IsNullOrWhiteSpace(nameCase)) { parameters.Add("name_case", nameCase); } if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } switch (order) { case FriendsOrder.ByName: parameters.Add("order", "name"); break; case FriendsOrder.ByRating: parameters.Add("order", "hints"); break; case FriendsOrder.Random: parameters.Add("order", "random"); break; } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "friends.get"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { return(new VkItemsResponse <VkProfile>(response["response"]["items"].Select(VkProfile.FromJson).ToList(), (int)response["response"]["count"])); } return(VkItemsResponse <VkProfile> .Empty); }
public ReadOnlyCollection <User> Get(long uid, ProfileFields fields = null, int?count = null, int?offset = null, FriendsOrder order = null, NameCase nameCase = null, int?listId = null) { if (listId != null && listId < 0) { throw new ArgumentOutOfRangeException("listId", "listId must be a positive number."); } var parameters = new FriendsGetParams { UserId = uid, Count = count, Offset = offset, Fields = fields, NameCase = nameCase, ListId = listId, Order = order }; return(Get(parameters).ToReadOnlyCollection()); }
public ReadOnlyCollection<User> Get(long uid, ProfileFields fields = null, int? count = null, int? offset = null, FriendsOrder order = null) { var parameters = new VkParameters { { "uid", uid }, { "fields", fields }, { "count", count }, { "offset", offset }, { "order", order } }; var response = _vk.Call("friends.get", parameters); if (fields != null) return response.ToReadOnlyCollectionOf<User>(x => x); return response.ToReadOnlyCollectionOf(id => new User { Id = id }); }
public ReadOnlyCollection <User> Get(long uid, ProfileFields fields = null, int?count = null, int?offset = null, FriendsOrder order = null, NameCase nameCase = null, int?listId = null) { if (listId != null && listId < 0) { throw new ArgumentOutOfRangeException("listId", "listId must be a positive number."); } var parameters = new VkParameters { { "user_id", uid }, { "fields", fields }, { "count", count }, { "offset", offset }, { "order", order }, { "list_id", listId }, { "name_case", nameCase } }; var response = _vk.Call("friends.get", parameters); if (fields != null) { return(response["items"].ToReadOnlyCollectionOf <User>(x => x)); } return(response.ToReadOnlyCollectionOf(id => new User { Id = id })); }
public async Task <VkItemsResponse <VkProfile> > Get(long userId, string fields, string nameCase, int count, int offset, FriendsOrder order = FriendsOrder.ByName) { var parameters = new Dictionary <string, string>(); if (userId > 0) { parameters.Add("user_id", userId.ToString()); } if (!string.IsNullOrWhiteSpace(fields)) { parameters.Add("fields", fields); } if (!string.IsNullOrWhiteSpace(nameCase)) { parameters.Add("name_case", nameCase); } if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } switch (order) { case FriendsOrder.ByName: parameters.Add("order", "name"); break; case FriendsOrder.ByRating: parameters.Add("order", "hints"); break; case FriendsOrder.Random: parameters.Add("order", "random"); break; } _vkontakte.SignMethod(parameters); var response = await VkRequest.GetAsync(VkConst.MethodBase + "friends.get", parameters); if (response.SelectToken("response.items") != null) { return(new VkItemsResponse <VkProfile>(response["response"]["items"].Select(VkProfile.FromJson).ToList(), (int)response["response"]["count"])); } return(VkItemsResponse <VkProfile> .Empty); }
/// <summary> /// Returns a list of user IDs of the mutual friends of two users. /// </summary> /// <param name="targetUids">IDs of the users whose friends will be checked against the friends of the user specified in source_uid.</param> /// <param name="sourceUid">ID of the user whose friends will be checked against the friends of the user specified in target_uid.</param> /// <param name="order">Sort order.</param> /// <param name="count">Number of friends to return.</param> /// <param name="offset">Offset needed to return a specific subset of friends.</param> /// <returns>Returns a <see cref="MutualFriends"/> object containing info about mutual friends.</returns> public async Task<Response<List<MutualFriends>>> GetMutual(List<int> targetUids, int? sourceUid = null, FriendsOrder order = FriendsOrder.Hints, int? count = null, int offset = 0) => await Request<List<MutualFriends>>("getMutual", new MethodParams { {"target_uids", string.Join(",", targetUids ?? new List<int>())}, {"source_uid", sourceUid}, {"order", Utils.ToEnumString(order)}, {"count", count}, {"offset", offset} });
/// <summary> /// Returns a list of user IDs or detailed information about a user's friends. /// </summary> /// <param name="userId">User ID. By default, the current user ID.</param> /// <param name="order">Sort order.</param> /// <param name="listId">ID of the friend list returned by the <see cref="GetLists"/> method to be used as the source. This parameter is taken into account only when the uid parameter is set to the current user ID. </param> /// <param name="count">Number of friends to return.</param> /// <param name="offset">Offset needed to return a specific subset of friends.</param> /// <param name="fields">Profile fields to return.</param> /// <param name="nameCase">Case for declension of user name and surname.</param> /// <returns>Returns a <see cref="List{T}"/> of <see cref="User"/> objects.</returns> public async Task <Response <ItemsList <User> > > Get(int?userId = null, FriendsOrder order = FriendsOrder.Hints, int?listId = null, int?count = null, int offset = 0, List <UserProfileFields> fields = null, NameCases nameCase = NameCases.Nominative) => await Request <ItemsList <User> >("get", new MethodParams { { "user_id", userId }, { "order", Utils.ToEnumString(order) }, { "list_id", listId }, { "count", count }, { "offset", offset }, { "fields", fields == null || !fields.Any() ? new List <UserProfileFields> { UserProfileFields.Nickname } : fields }, { "name_case", Utils.ToEnumString(nameCase) } }, true);