Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groups Callback API #10

Merged
merged 3 commits into from
Oct 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 86 additions & 12 deletions ModernDev.InTouch.Shared/API/Methods/GroupsMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task<Response<ItemsList<User>>> GetMembers(GroupsGetMembersParams m
/// </summary>
/// <param name="groupId">ID or screen name of the community. </param>
/// <param name="notSure">Optional parameter which is taken into account when gid belongs to the event: True � Perhaps I will attend; False � I will be there for sure(default) </param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> Join(object groupId = null, bool notSure = false)
=> await Request<bool>("join", new MethodParams
{
Expand All @@ -108,7 +108,7 @@ public async Task<Response<bool>> Join(object groupId = null, bool notSure = fal
/// With this method you can leave a group, public page, or event.
/// </summary>
/// <param name="groupId">ID or screen name of the community.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> Leave(object groupId) => await Request<bool>("leave",
new MethodParams
{
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task<Response<ItemsList<User>>> GetInvitedUsers(int groupId, int co
/// <param name="reason">Reason for ban.</param>
/// <param name="comment">Text of comment to ban.</param>
/// <param name="commentVisible">True � text of comment will be visible to the user; False � text of comment will be invisible to the user(default)</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> BanUser(int groupId, int userId, DateTime? endDate = null,
BanTypes reason = BanTypes.Other, string comment = null, bool commentVisible = false)
=> await Request<bool>("banUser", new MethodParams
Expand All @@ -211,7 +211,7 @@ public async Task<Response<bool>> BanUser(int groupId, int userId, DateTime? end
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="userId">User ID.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> UnbanUser(int groupId, int userId)
=> await Request<bool>("unbanUser", new MethodParams
{
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task<Response<Group>> Create(string title, string description = nul
/// <remarks>You must be a community administrator to use this method</remarks>
/// </summary>
/// <param name="methodParams"><see cref="GroupsEditParams"/> object containing method params.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> Edit(GroupsEditParams methodParams)
=> await Request<bool>("edit", methodParams);

Expand Down Expand Up @@ -306,7 +306,7 @@ public async Task<Response<ItemsList<User>>> GetRequests(int groupId, int count
/// Allows to assign or demote community's manager, or to change the level of the existing manager.
/// </summary>
/// <param name="methodParams"><see cref="GroupsEditManagerParams"/> object containing method params.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> EditManager(GroupsEditManagerParams methodParams)
=> await Request<bool>("editManager", methodParams);

Expand All @@ -315,7 +315,7 @@ public async Task<Response<bool>> EditManager(GroupsEditManagerParams methodPara
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="userId">User Id.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> Invite(int groupId, int userId)
=> await Request<bool>("invite", new MethodParams
{
Expand Down Expand Up @@ -343,7 +343,7 @@ public async Task<Response<CommunityLink>> AddLink(int groupId, string link, str
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="linkId">Link Id.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> DeleteLink(int groupId, int linkId)
=> await Request<bool>("deleteLink", new MethodParams
{
Expand All @@ -357,7 +357,7 @@ public async Task<Response<bool>> DeleteLink(int groupId, int linkId)
/// <param name="groupId">Community ID.</param>
/// <param name="linkId">Link Id.</param>
/// <param name="text">New link text.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> EditLink(int groupId, int linkId, string text = null)
=> await Request<bool>("editLink", new MethodParams
{
Expand All @@ -372,7 +372,7 @@ public async Task<Response<bool>> EditLink(int groupId, int linkId, string text
/// <param name="groupId">Community ID.</param>
/// <param name="linkId">Link Id.</param>
/// <param name="after">Link Id after which you want to place movable link. 0 - if you want to place the link at the top spot.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> ReorderLink(int groupId, int linkId, int after = 0)
=> await Request<bool>("reorderLink", new MethodParams
{
Expand All @@ -386,7 +386,7 @@ public async Task<Response<bool>> ReorderLink(int groupId, int linkId, int after
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="userId">User Id.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> RemoveUser(int groupId, int userId)
=> await Request<bool>("removeUser", new MethodParams
{
Expand All @@ -399,14 +399,88 @@ public async Task<Response<bool>> RemoveUser(int groupId, int userId)
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="userId">User Id.</param>
/// <returns>Returns True if the user installed the application; otherwise returns False.</returns>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> ApproveRequest(int groupId, int userId)
=> await Request<bool>("approveRequest", new MethodParams
{
{"group_id", groupId, true},
{"user_id", userId, true}
});

#region Callback methods

/// <summary>
/// Returns Callback API confirmation code for the community.
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <returns>Returns a string with the confirmation code.</returns>
public async Task<Response<string>> GetCallbackConfirmationCode(int groupId)
=> await Request<string>("getCallbackConfirmationCode", new MethodParams
{
{"group_id", groupId, true}
}, false, "code");

/// <summary>
/// Returns Callback API server settings for the community.
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <returns>Returns <see cref="CallbackServerSettings"/> object.</returns>
public async Task<Response<CallbackServerSettings>> GetCallbackServerSettings(int groupId)
=> await Request<CallbackServerSettings>("getCallbackServerSettings", new MethodParams
{
{"group_id", groupId, true}
});

/// <summary>
/// Returns Callback API notifications settings.
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <returns>Returns <see cref="CallbackSettings"/> object.</returns>
public async Task<Response<CallbackSettings>> GetCallbackSettings(int groupId)
=> await Request<CallbackSettings>("getCallbackSettings", new MethodParams
{
{"group_id", groupId, true}
});

/// <summary>
/// Allow to set Callback API server URL for the community.
///
/// To confirm the connection, your server should return a string with a confirmation code.
/// You can get thus code using <see cref="GetCallbackConfirmationCode"/> method.
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="serverUrl">Server URL.</param>
/// <returns>Returns <see cref="CallbackServerState"/> object.</returns>
public async Task<Response<CallbackServerState>> SetCallbackServer(int groupId, string serverUrl)
=> await Request<CallbackServerState>("setCallbackServer", new MethodParams
{
{"group_id", groupId, true},
{"server_url", serverUrl, true}
});

/// <summary>
/// Allow to set Callback API server settings.
/// </summary>
/// <param name="groupId">Community ID.</param>
/// <param name="secretKey">Callback API secret key.</param>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> SetCallbackServerSettings(int groupId, string secretKey)
=> await Request<bool>("setCallbackServerSettings", new MethodParams
{
{"group_id", groupId, true},
{"secretKey", secretKey, true}
});

/// <summary>
/// Allow to set notifications settings for Callback API.
/// </summary>
/// <param name="methodParams"><see cref="GroupsSetCallbackSettingsParams"/> object containing method params.</param>
/// <returns>If successfully executed, returns True.</returns>
public async Task<Response<bool>> SetCallbackSettings(GroupsSetCallbackSettingsParams methodParams)
=> await Request<bool>("setCallbackSettings", methodParams);

#endregion

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
namespace ModernDev.InTouch
{
/// <summary>
/// A <see cref="GroupsSetCallbackSettingsParams"/> class describes a <see cref="GroupsMethods.SetCallbackSettings"/> method params.
/// </summary>
public class GroupsSetCallbackSettingsParams : MethodParamsGroup
{
/// <summary>
/// Community ID.
/// </summary>
[MethodParam(Name ="group_id", IsRequired = true)]
public int GroupId { get; set; }

/// <summary>
/// New messages notifications.
/// </summary>
[MethodParam(Name = "message_new")]
public bool MessageNew { get; set; }

/// <summary>
/// New photos notifications.
/// </summary>
[MethodParam(Name = "photo_new")]
public bool PhotoNew { get; set; }

/// <summary>
/// New audios notifications.
/// </summary>
[MethodParam(Name = "audio_new")]
public bool AudioNew { get; set; }

/// <summary>
/// New videos notifications.
/// </summary>
[MethodParam(Name = "video_new")]
public bool VideoNew { get; set; }

/// <summary>
/// New wall replies notifications.
/// </summary>
[MethodParam(Name = "wall_reply_new")]
public bool WallReplyNew { get; set; }

/// <summary>
/// Wall replies edited notifications.
/// </summary>
[MethodParam(Name = "wall_reply_edit")]
public bool WallReplyEdit { get; set; }

/// <summary>
/// New wall posts notifications.
/// </summary>
[MethodParam(Name = "wall_post_new")]
public bool WallPostNew { get; set; }

/// <summary>
/// New board posts notifications.
/// </summary>
[MethodParam(Name = "board_post_new")]
public bool BoardPostNew { get; set; }

/// <summary>
/// Board posts edited notifications.
/// </summary>
[MethodParam(Name = "board_post_edit")]
public bool BoardPostEdit { get; set; }

/// <summary>
/// Board posts restored notifications
/// </summary>
[MethodParam(Name = "board_post_restore")]
public bool BoardPostRestore { get; set; }

/// <summary>
/// Board posts deleted notifications.
/// </summary>
[MethodParam(Name = "board_post_delete")]
public bool BoardPostDelete { get; set; }

/// <summary>
/// New comment to photo notifications.
/// </summary>
[MethodParam(Name = "photo_comment_new")]
public bool PhotoCommentNew { get; set; }

/// <summary>
/// New comment to video notifications.
/// </summary>
[MethodParam(Name = "video_comment_new")]
public bool VideoCommentNew { get; set; }

/// <summary>
/// New comment to market item notifications.
/// </summary>
[MethodParam(Name = "market_comment_new")]
public bool MarketCommentNew { get; set; }

/// <summary>
/// Joined community notifications.
/// </summary>
[MethodParam(Name = "group_join")]
public bool GroupJoin { get; set; }

/// <summary>
/// Left community notifications.
/// </summary>
[MethodParam(Name = "group_leave")]
public bool GroupLeave { get; set; }
}
}
43 changes: 43 additions & 0 deletions ModernDev.InTouch.Shared/Model/CallbackServerSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This file\code is part of InTouch project.
*
* InTouch - is a .NET wrapper for the vk.com API.
* https://github.com/virtyaluk/InTouch
*
* Copyright (c) 2016 Bohdan Shtepan
* http://modern-dev.com/
*
* Licensed under the GPLv3 license.
*/

using System.Diagnostics;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace ModernDev.InTouch
{
/// <summary>
/// A <see cref="CallbackServerSettings"/> class describes callback server settings.
/// </summary>
[DebuggerDisplay("CallbackServerSettings")]
[DataContract]
public class CallbackServerSettings
{
#region Properties

/// <summary>
/// Server URL.
/// </summary>
[JsonProperty("server_url")]
[DataMember]
public string ServerUrl { get; set; }

/// <summary>
/// Secret key.
/// </summary>
[JsonProperty("secret_key")]
[DataMember]
public string SecretKey { get; set; }
#endregion
}
}
28 changes: 28 additions & 0 deletions ModernDev.InTouch.Shared/Model/CallbackServerState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace ModernDev.InTouch
{
/// <summary>
/// A <see cref="CallbackServerState" /> class describes Callback API server state.
/// </summary>
[DebuggerDisplay("CallbackServerState {State}")]
[DataContract]
public class CallbackServerState
{
/// <summary>
/// State code.
/// </summary>
[JsonProperty("state_code")]
[DataMember]
public int StateCode { get; set; }

/// <summary>
/// State message.
/// </summary>
[JsonProperty("state")]
[DataMember]
public string State { get; set; }
}
}
Loading