/// <summary> /// Gets a list of URLs for the separate services of an instance /// </summary> /// <param name="address">The address to query</param> /// <returns></returns> public static async Task <Result <ServerURLs> > GetServerURLs(string address) { // Instantiates temporary objects RequestsClient requestsClient = new RequestsClient(); Endpoint target = new Endpoint("/Home/InstanceInfo", HttpMethod.Get); // Retrieves URL information and converts to stream HttpResponseMessage response = await requestsClient.SendRequest(address, target); return(await ResponseParser.ParseJsonResponse <ServerURLs>(response)); }
/// <summary> /// Queries the given server with the given authentication token, return user information if available /// </summary> /// <param name="address">The instance to query</param> /// <param name="token">The token to send</param> public async Task <Result <CrossConnectionUser> > AuthenticateToken(string address, string token) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "token", token } }; HttpResponseMessage response = await _requestsClient .SendRequest(address, CrossConnectionEndpoints.AuthenticateToken, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <CrossConnectionUser>(response)); }
/// <summary> /// Retrieves a thread of the given ID /// </summary> /// <param name="threadID">The thread to retrieve</param> /// <returns>The requested thread</returns> public async Task <Result <ApiThread> > GetThreadAsync(int threadID) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", threadID.ToString() } }; // Retrieves response and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.Thread, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <ApiThread>(response)); }
/// <summary> /// Retrieves the list of threads at the front page /// </summary> /// <returns>The list of threads</returns> public async Task <Result <List <ApiThread> > > GetFrontPageAsync(int page = 1) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "page", page.ToString() } }; // Retrieves response and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.FrontPage, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <List <ApiThread> >(response).ConfigureAwait(false)); }
/// <summary> /// Checks if a domain has already been registered in the given server /// </summary> /// <param name="address">The server to query</param> /// <param name="checkAddress">The address to check</param> /// <returns>Returns a successful when it has not been registered, otherwise returns a failure result</returns> public async Task <Result> CheckAddress(string address, string checkAddress) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "address", checkAddress } }; HttpResponseMessage response = await _requestsClient .SendRequest(address, CrossConnectionEndpoints.CheckAddress, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse(response).ConfigureAwait(false)); }
/// <summary> /// Retrieves a user comment of the given ID /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <Result <ApiComment> > GetUserCommentAsync(int id) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", id.ToString() } }; // Sends request and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.GetUserComment, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <ApiComment>(response).ConfigureAwait(false)); }
/// <summary> /// Download the profile picture of the given user as a stream /// </summary> /// <param name="id">The ID of the user</param> /// <returns></returns> public async Task <Result <Stream> > GetProfileImg(int id) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", id.ToString() } }; // Sends request and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.ProfilePicture, parameters) .ConfigureAwait(false); return(await ResponseParser.ParseStreamResponse(response)); }
/// <summary> /// Deletes a thread of the given ID /// </summary> /// <param name="id">The ID of the thread to delete</param> /// <returns></returns> public async Task <Result> DeleteThreadAsync(int id) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", id.ToString() } }; // Retrieves the response and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.DeleteThread, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse(response).ConfigureAwait(false)); }
/// <summary> /// Creates a new thread /// </summary> /// <param name="title">The title of the new thread</param> /// <param name="contents">The contents of the new thread</param> /// <returns>The newly created thread/error</returns> public async Task <Result <ApiThread> > CreateThreadAsync(string title, string contents) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "title", title }, { "content", contents } }; // Retrieves response and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.CreateThread, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <ApiThread>(response)); }
/// <summary> /// Registers an outgoing token at the given address /// </summary> /// <param name="address"></param> /// <param name="registerAddress"></param> /// <param name="token">The token to register on the remote server</param> /// <returns></returns> public async Task <Result> RegisterAddress(string address, string registerAddress, string token) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "address", registerAddress }, { "token", token } }; HttpResponseMessage response = await _requestsClient .SendRequest(address, CrossConnectionEndpoints.RegisterToken, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse(response).ConfigureAwait(false)); }
/// <summary> /// Gets comments from the user of the given ID /// </summary> /// <param name="id">The ID of the user to retrieve comments for</param> /// <param name="page">The page of comments to retrieve</param> /// <returns></returns> public async Task <Result <List <ApiComment> > > GetUserCommentsAsync(int id, int page = 1) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", id.ToString() }, { "page", page.ToString() } }; // Receives response and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.UserComments, parameters) .ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <List <ApiComment> >(response).ConfigureAwait(false)); }
/// <summary> /// Posts a comment to the given thread /// </summary> /// <param name="threadID">The thread to post the comment to</param> /// <param name="content">The comment to post</param> /// <returns></returns> public async Task <Result <ApiComment> > PostCommentAsync(int threadID, string content) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", threadID.ToString() }, { "content", content } }; // Retrieves response and returns result HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.PostComment, parameters).ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <ApiComment>(response).ConfigureAwait(false)); }
/// <summary> /// Updates a thread /// </summary> /// <remarks> /// The user must be the owner of the thread to update it, and only the locked status of the thread can be changed /// </remarks> /// <param name="id">The id of the thread to update</param> /// <param name="request">The update information of the request</param> /// <returns></returns> public async Task <Result <ApiThread> > UpdateThread(int id, UpdateThreadRequest request) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "id", id.ToString() } }; if (request.Locked != null) { parameters.Add("locked", request.Locked.ToString()); } HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.UpdateThread, parameters) .ConfigureAwait(false); return(await ResponseParser.ParseJsonResponse <ApiThread>(response).ConfigureAwait(false)); }
/// <summary> /// Logs the user in, returning an access token /// </summary> /// <param name="username">The username to use</param> /// <param name="password">The password to use</param> /// <returns>The LoginResponse containing the access token</returns> public async Task <Result <LoginResponse> > LoginAsync(string username, string password) { Dictionary <string, string> parameters = new Dictionary <string, string>() { { "username", username }, { "password", password } }; // Sends login and returns result, saving the token if successful HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.Login, parameters).ConfigureAwait(false); Result <LoginResponse> loginResponse = await ResponseParser.ParseJsonResponse <LoginResponse>(response).ConfigureAwait(false); if (loginResponse.Success) { TokenStorage.SetToken(loginResponse.Value.Token); } return(loginResponse); }