Skip to content

Commit

Permalink
Добавлены отсутствующие методы в категорию Ads (#1193)
Browse files Browse the repository at this point in the history
* Реализовал метод getMusicians

* Реализовал метод getMusiciansByIds

* Реализовал метод updateOfficeUsers
  • Loading branch information
Hiccstrid2019 authored Aug 16, 2021
1 parent e65ab72 commit c04208c
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 0 deletions.
25 changes: 25 additions & 0 deletions VkNet.Tests/Categories/Ads/GetMusiciansByIdsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using VkNet.Tests.Infrastructure;

namespace VkNet.Tests.Categories.Ads
{
[TestFixture]
public class GetMusiciansByIdsTest : CategoryBaseTest
{
protected override string Folder => "Ads";

[Test]
public void GetMusiciansByIds()
{
Url = "https://api.vk.com/method/ads.getMusiciansByIds";

ReadCategoryJsonPath(nameof(Api.Ads.GetMusiciansByIds));

var result = Api.Ads.GetMusiciansByIds("1, 2, 3");
Assert.That(result[0].Name, Is.EqualTo("UGLYBOY"));
Assert.That(result[1].Name, Is.EqualTo("Rudesarcasmov"));
Assert.That(result[2].Name, Is.EqualTo("Santiz"));
Assert.That(result[1].Id, Is.EqualTo(2));
}
}
}
28 changes: 28 additions & 0 deletions VkNet.Tests/Categories/Ads/GetMusiciansTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using NUnit.Framework;
using VkNet.Enums;
using VkNet.Enums.SafetyEnums;
using VkNet.Model;
using VkNet.Model.RequestParams.Ads;
using VkNet.Tests.Infrastructure;

namespace VkNet.Tests.Categories.Ads
{
[TestFixture]
public class GetMusiciansTest : CategoryBaseTest
{
protected override string Folder => "Ads";

[Test]
public void GetMusicians()
{
Url = "https://api.vk.com/method/ads.getMusicians";

ReadCategoryJsonPath(nameof(Api.Ads.GetMusicians));

var result = Api.Ads.GetMusicians("Alan Walker");
Assert.That(result[0].Name, Is.EqualTo("Alan Walker"));
Assert.That(result[0].Id, Is.EqualTo(32697));
}
}
}
66 changes: 66 additions & 0 deletions VkNet.Tests/Categories/Ads/UpdateOfficeUsersTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using NUnit.Framework;
using VkNet.Enums.SafetyEnums;
using VkNet.Model;
using VkNet.Model.RequestParams.Ads;
using VkNet.Tests.Infrastructure;

namespace VkNet.Tests.Categories.Ads
{
[TestFixture]
public class UpdateOfficeUsersTest : CategoryBaseTest
{
protected override string Folder => "Ads";

[Test]
public void UpdateOfficeUsers()
{
Url = "https://api.vk.com/method/ads.updateOfficeUsers";

ReadCategoryJsonPath(nameof(Api.Ads.UpdateOfficeUsers));

OfficeUsersSpecification officeUsersSpecification1 = new OfficeUsersSpecification
{
UserId = 12423,
Role = AccessRole.Reports,
ClientsIds = new int[]
{
1245,
566,
323
},
GrantAccessToAllClients = true,
ViewBudget = true
};

OfficeUsersSpecification officeUsersSpecification2 = new OfficeUsersSpecification
{
UserId = 4324432,
Role = AccessRole.Manager,
ClientsIds = new int[]
{
567357,
566566,
3645623
},
GrantAccessToAllClients = false,
ViewBudget = false
};

OfficeUsersSpecification[] data =
{
officeUsersSpecification1,
officeUsersSpecification2
};

var result = Api.Ads.UpdateOfficeUsers(new AdsDataSpecificationParams<OfficeUsersSpecification>
{
AccountId = 1605245430,
Data = data
});

Assert.That(result[0].UserId, Is.EqualTo(1567));
Assert.That(result[0].IsSuccess, Is.False);
Assert.That(result[0].Error.ErrorCode, Is.EqualTo(100));
}
}
}
7 changes: 7 additions & 0 deletions VkNet.Tests/TestData/Categories/Ads/GetMusicians.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"response": [{
"id": 32697,
"name": "Alan Walker",
"avatar": "https://sun9-24.u...-e7E&type=audio"
}]
}
13 changes: 13 additions & 0 deletions VkNet.Tests/TestData/Categories/Ads/GetMusiciansByIds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"response": [{
"id": 1,
"name": "UGLYBOY",
"avatar": "https://sun9-11.u...FeTk&type=audio"
}, {
"id": 2,
"name": "Rudesarcasmov"
}, {
"id": 3,
"name": "Santiz"
}]
}
10 changes: 10 additions & 0 deletions VkNet.Tests/TestData/Categories/Ads/UpdateOfficeUsers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"response": [{
"user_id": 1567,
"is_success": false,
"error": {
"error_code": 100,
"error_msg": "One of the parameters specified was missing or invalid: account_id is undefined"
}
}]
}
32 changes: 32 additions & 0 deletions VkNet/Abstractions/Category/Async/IAdsCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -862,5 +862,37 @@ public interface IAdsCategoryAsync
/// Страница документации ВКонтакте http://vk.com/dev/ads.updateTargetPixel
/// </remarks>
Task<bool> UpdateTargetPixelAsync(UpdateTargetPixelParams updateTargetPixelParams);

/// <summary>
/// Возвращает информацию о музыкантах (по имени музыканта), на слушателей которых доступно таргетирование.
/// </summary>
/// <param name="artistName"></param>
/// <returns>Возвращает массив всех подходящих под запрос artistName музыкантов.</returns>
/// <remarks>
/// Страница документации ВКонтакте http://vk.com/dev/ads.getMusicians
/// </remarks>
Task<ReadOnlyCollection<GetMusiciansResult>> GetMusiciansAsync(string artistName);

/// <summary>
/// Возвращает информацию о музыкантах (по id музыкантов) на слушателей, для которых доступно таргетирование.
/// </summary>
/// <param name="ids"></param>
/// <returns>Возвращает массив музыкантов с соответствующими идентификаторами из запроса.</returns>
/// <remarks>
/// Страница документации ВКонтакте http://vk.com/dev/ads.getMusiciansByIds
/// </remarks>
Task<ReadOnlyCollection<GetMusiciansByIdsResult>> GetMusiciansByIdsAsync(string ids);

/// <summary>
/// Добавляет/редактирует администраторов и/или наблюдателей в рекламный кабинет.
/// </summary>
/// <param name="officeUsersSpecification"></param>
/// <returns>
/// Возвращает массив значений - ответов на каждый запрос в массиве response
/// </returns>
/// <remarks>
/// Страница документации ВКонтакте http://vk.com/dev/ads.updateOfficeUsers
/// </remarks>
Task<ReadOnlyCollection<UpdateOfficeUsersResult>> UpdateOfficeUsersAsync(AdsDataSpecificationParams<OfficeUsersSpecification> officeUsersSpecification);
}
}
9 changes: 9 additions & 0 deletions VkNet/Abstractions/Category/IAdsCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,14 @@ public interface IAdsCategory : IAdsCategoryAsync

/// <inheritdoc cref="IAdsCategoryAsync.UpdateTargetPixelAsync"/>
bool UpdateTargetPixel(UpdateTargetPixelParams updateTargetPixelParams);

/// <inheritdoc cref="IAdsCategoryAsync.GetMusiciansAsync"/>
ReadOnlyCollection<GetMusiciansResult> GetMusicians(string artistName);

/// <inheritdoc cref="IAdsCategoryAsync.GetMusiciansByIdsAsync"/>
ReadOnlyCollection<GetMusiciansByIdsResult> GetMusiciansByIds(string ids);

/// <inheritdoc cref="IAdsCategoryAsync.UpdateOfficeUsersAsync"/>
ReadOnlyCollection<UpdateOfficeUsersResult> UpdateOfficeUsers(AdsDataSpecificationParams<OfficeUsersSpecification> officeUsersSpecification);
}
}
32 changes: 32 additions & 0 deletions VkNet/Categories/AdsCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,37 @@ public bool UpdateTargetPixel(UpdateTargetPixelParams updateTargetPixelParams)
{ "category_id", updateTargetPixelParams.CategoryId }, { "client_id", updateTargetPixelParams.ClientId }
});
}

/// <inheritdoc/>
public ReadOnlyCollection<GetMusiciansResult> GetMusicians(string artistName)
{
return _vk.Call<ReadOnlyCollection<GetMusiciansResult>>("ads.getMusicians",
new VkParameters
{
{ "artist_name", artistName }
});
}

/// <inheritdoc/>
public ReadOnlyCollection<GetMusiciansByIdsResult> GetMusiciansByIds(string ids)
{
return _vk.Call<ReadOnlyCollection<GetMusiciansByIdsResult>>("ads.getMusiciansByIds",
new VkParameters
{
{ "ids", ids }
});
}

/// <inheritdoc/>
public ReadOnlyCollection<UpdateOfficeUsersResult> UpdateOfficeUsers(
AdsDataSpecificationParams<OfficeUsersSpecification> officeUsersSpecification)
{
return _vk.Call<ReadOnlyCollection<UpdateOfficeUsersResult>>("ads.updateOfficeUsers",
new VkParameters
{
{ "account_id", officeUsersSpecification.AccountId },
{ "data", officeUsersSpecification.Data }
});
}
}
}
19 changes: 19 additions & 0 deletions VkNet/Categories/Async/AdsCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,24 @@ public Task<bool> UpdateTargetPixelAsync(UpdateTargetPixelParams updateTargetPix
{
return TypeHelper.TryInvokeMethodAsync(() => UpdateTargetPixel(updateTargetPixelParams));
}

/// <inheritdoc/>
public Task<ReadOnlyCollection<GetMusiciansResult>> GetMusiciansAsync(string artistName)
{
return TypeHelper.TryInvokeMethodAsync(() => GetMusicians(artistName));
}

/// <inheritdoc/>
public Task<ReadOnlyCollection<GetMusiciansByIdsResult>> GetMusiciansByIdsAsync(string ids)
{
return TypeHelper.TryInvokeMethodAsync(() => GetMusiciansByIds(ids));
}

/// <inheritdoc/>
public Task<ReadOnlyCollection<UpdateOfficeUsersResult>> UpdateOfficeUsersAsync(
AdsDataSpecificationParams<OfficeUsersSpecification> officeUsersSpecification)
{
return TypeHelper.TryInvokeMethodAsync(() => UpdateOfficeUsers(officeUsersSpecification));
}
}
}
59 changes: 59 additions & 0 deletions VkNet/Model/Ads/OfficeUsersSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using VkNet.Enums;
using VkNet.Enums.SafetyEnums;
using VkNet.Utils;
using VkNet.Utils.JsonConverter;

namespace VkNet.Model
{
/// <summary>
///
/// </summary>
[Serializable]
public class OfficeUsersSpecification
{
/// <summary>
/// Идентификатор пользователя, добавляемого как администратор/наблюдатель.
/// </summary>
[JsonProperty("user_id")]
public long UserId { get; set; }

/// <summary>
/// Тип полномочий.
/// </summary>
[JsonProperty("role")]
[JsonConverter(typeof(SafetyEnumJsonConverter))]
public AccessRole Role { get; set; }

/// <summary>
/// Массив идентификаторов клиента.
/// </summary>
[JsonProperty("clients_ids")]
public int[] ClientsIds { get; set; }

/// <summary>
/// Доступ ко всем текущим и новым клиентам этого кабинета.
/// </summary>
[JsonProperty("grant_access_to_all_clients")]
public bool GrantAccessToAllClients { get; set; }

/// <summary>
/// Показывать ли бюджет пользователю.
/// </summary>
[JsonProperty("view_budget")]
public bool? ViewBudget { get; set; }

public OfficeUsersSpecification FromJson(VkResponse response)
{
return new OfficeUsersSpecification
{
UserId = response["user_id"],
Role = response["role"],
ClientsIds = response["client_ids"].ToListOf<int>(x => x).ToArray(),
GrantAccessToAllClients = response["grant_access_to_all_clients"]
};
}
}
}
46 changes: 46 additions & 0 deletions VkNet/Model/Results/Ads/GetMusiciansByIdsResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using Newtonsoft.Json;
using VkNet.Utils;

namespace VkNet.Model
{
/// <summary>
///
/// </summary>
[Serializable]
public class GetMusiciansByIdsResult
{
/// <summary>
/// Идентификатор музыканта.
/// </summary>
[JsonProperty("id")]
public long Id { get; set; }

/// <summary>
/// Полный псевдоним музыканта.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Аватарка музыканта.
/// </summary>
[JsonProperty("avatar")]
public string Avatar { get; set; }

/// <summary>
/// Разобрать из json.
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns></returns>
public static GetMusiciansByIdsResult FromJson(VkResponse response)
{
return new GetMusiciansByIdsResult
{
Id = response["id"],
Name = response["name"],
Avatar = response["avatar"]
};
}
}
}
Loading

0 comments on commit c04208c

Please sign in to comment.