Skip to content

Commit

Permalink
Added support for bookmarking and favouriting statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Sep 30, 2023
1 parent e63b95e commit 82be607
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 0 deletions.
96 changes: 96 additions & 0 deletions src/Skybrud.Social.Mastodon/Endpoints/MastodonStatusesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,102 @@ public MastodonStatusesEndpoint(MastodonHttpService service) {

#region Member methods

/// <summary>
/// Bookmarks the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to bookmark.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public MastodonStatusResponse BookmarkStatus(string id) {
return new MastodonStatusResponse(Raw.BookmarkStatus(id));
}

/// <summary>
/// Bookmarks the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public MastodonStatusResponse BookmarkStatus(MastodonBookmarkStatusOptions options) {
return new MastodonStatusResponse(Raw.BookmarkStatus(options));
}

/// <summary>
/// Bookmarks the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to bookmark.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public async Task<MastodonStatusResponse> BookmarkStatusAsync(string id) {
return new MastodonStatusResponse(await Raw.BookmarkStatusAsync(id));
}

/// <summary>
/// Bookmarks the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public async Task<MastodonStatusResponse> BookmarkStatusAsync(MastodonBookmarkStatusOptions options) {
return new MastodonStatusResponse(await Raw.BookmarkStatusAsync(options));
}

/// <summary>
/// Favourites the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to favourite.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public MastodonStatusResponse FavouriteStatus(string id) {
return new MastodonStatusResponse(Raw.FavouriteStatus(id));
}

/// <summary>
/// Favourites the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public MastodonStatusResponse FavouriteStatus(MastodonFavouriteStatusOptions options) {
return new MastodonStatusResponse(Raw.FavouriteStatus(options));
}

/// <summary>
/// Favourites the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to favourite.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public async Task<MastodonStatusResponse> FavouriteStatusAsync(string id) {
return new MastodonStatusResponse(await Raw.FavouriteStatusAsync(id));
}

/// <summary>
/// Favourites the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="MastodonStatusResponse"/> representing the response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public async Task<MastodonStatusResponse> FavouriteStatusAsync(MastodonFavouriteStatusOptions options) {
return new MastodonStatusResponse(await Raw.FavouriteStatusAsync(options));
}

/// <summary>
/// Returns information about the status with specified <paramref name="id"/>.
/// </summary>
Expand Down
104 changes: 104 additions & 0 deletions src/Skybrud.Social.Mastodon/Endpoints/MastodonStatusesRawEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,110 @@ public MastodonStatusesRawEndpoint(MastodonHttpClient client) {

#region Member methods

/// <summary>
/// Bookmarks the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to bookmark.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public IHttpResponse BookmarkStatus(string id) {
if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id));
return BookmarkStatus(new MastodonBookmarkStatusOptions(id));
}

/// <summary>
/// Bookmarks the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public IHttpResponse BookmarkStatus(MastodonBookmarkStatusOptions options) {
if (options is null) throw new ArgumentNullException(nameof(options));
return Client.GetResponse(options);
}

/// <summary>
/// Bookmarks the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to bookmark.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public async Task<IHttpResponse> BookmarkStatusAsync(string id) {
if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id));
return await BookmarkStatusAsync(new MastodonBookmarkStatusOptions(id));
}

/// <summary>
/// Bookmarks the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public async Task<IHttpResponse> BookmarkStatusAsync(MastodonBookmarkStatusOptions options) {
if (options is null) throw new ArgumentNullException(nameof(options));
return await Client.GetResponseAsync(options);
}

/// <summary>
/// Favourites the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to favourite.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public IHttpResponse FavouriteStatus(string id) {
if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id));
return FavouriteStatus(new MastodonFavouriteStatusOptions(id));
}

/// <summary>
/// Favourites the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public IHttpResponse FavouriteStatus(MastodonFavouriteStatusOptions options) {
if (options is null) throw new ArgumentNullException(nameof(options));
return Client.GetResponse(options);
}

/// <summary>
/// Favourites the status with the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status to favourite.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public async Task<IHttpResponse> FavouriteStatusAsync(string id) {
if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id));
return await FavouriteStatusAsync(new MastodonFavouriteStatusOptions(id));
}

/// <summary>
/// Favourites the status identified by the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the request to the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public async Task<IHttpResponse> FavouriteStatusAsync(MastodonFavouriteStatusOptions options) {
if (options is null) throw new ArgumentNullException(nameof(options));
return await Client.GetResponseAsync(options);
}

/// <summary>
/// Returns information about the status with specified <paramref name="id"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Diagnostics.CodeAnalysis;
using Skybrud.Essentials.Common;
using Skybrud.Essentials.Http;

namespace Skybrud.Social.Mastodon.Options.Statuses;

/// <summary>
/// Class with options for favouriting a status.
/// </summary>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#bookmark</cref>
/// </see>
public class MastodonBookmarkStatusOptions : MastodonHttpRequestOptions {

#region Properties

/// <summary>
/// Gets or sets the ID of the status.
/// </summary>
#if NET7_0_OR_GREATER
public required string Id { get; set; }
#else
public string? Id { get; set; }
#endif

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance with default options.
/// </summary>
public MastodonBookmarkStatusOptions() { }

/// <summary>
/// Initializes a new instance based on the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status.</param>
#if NET7_0_OR_GREATER
[SetsRequiredMembers]
#endif
public MastodonBookmarkStatusOptions(string id) {
Id = id;
}

#endregion

#region Member methods

/// <summary>
/// Returns a new <see cref="IHttpRequest"/> instance for this options instance.
/// </summary>
/// <returns>An instance of <see cref="IHttpRequest"/>.</returns>
public override IHttpRequest GetRequest(MastodonHttpClient client) {

// Validate required properties
if (string.IsNullOrWhiteSpace(Id)) throw new PropertyNotSetException(nameof(Id));

// Initialize a new HTTP request
return HttpRequest.Get($"/api/v1/statuses/{Id}/bookmark");

}

#endregion

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Diagnostics.CodeAnalysis;
using Skybrud.Essentials.Common;
using Skybrud.Essentials.Http;

namespace Skybrud.Social.Mastodon.Options.Statuses;

/// <summary>
/// Class with options for favouriting a status.
/// </summary>
/// <see>
/// <cref>https://docs.joinmastodon.org/methods/statuses/#favourite</cref>
/// </see>
public class MastodonFavouriteStatusOptions : MastodonHttpRequestOptions {

#region Properties

/// <summary>
/// Gets or sets the ID of the status.
/// </summary>
#if NET7_0_OR_GREATER
public required string Id { get; set; }
#else
public string? Id { get; set; }
#endif

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance with default options.
/// </summary>
public MastodonFavouriteStatusOptions() { }

/// <summary>
/// Initializes a new instance based on the specified <paramref name="id"/>.
/// </summary>
/// <param name="id">The ID of the status.</param>
#if NET7_0_OR_GREATER
[SetsRequiredMembers]
#endif
public MastodonFavouriteStatusOptions(string id) {
Id = id;
}

#endregion

#region Member methods

/// <summary>
/// Returns a new <see cref="IHttpRequest"/> instance for this options instance.
/// </summary>
/// <returns>An instance of <see cref="IHttpRequest"/>.</returns>
public override IHttpRequest GetRequest(MastodonHttpClient client) {

// Validate required properties
if (string.IsNullOrWhiteSpace(Id)) throw new PropertyNotSetException(nameof(Id));

// Initialize a new HTTP request
return HttpRequest.Get($"/api/v1/statuses/{Id}/favourite");

}

#endregion

}

0 comments on commit 82be607

Please sign in to comment.