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

Clean up endpoint definitions in methods classes #410

Merged
merged 8 commits into from
Dec 30, 2023
33 changes: 18 additions & 15 deletions bigbone/src/main/kotlin/social/bigbone/api/method/AccountMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import java.time.Duration
* @see <a href="https://docs.joinmastodon.org/methods/accounts/">Mastodon accounts API methods</a>
*/
class AccountMethods(private val client: MastodonClient) {

private val endpoint = "api/v1/accounts"

/**
* Register an account.
* @param username The desired username for the account
Expand All @@ -38,7 +41,7 @@ class AccountMethods(private val client: MastodonClient) {
reason: String?
): MastodonRequest<Token> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts",
endpoint = endpoint,
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
append("username", username)
Expand All @@ -58,7 +61,7 @@ class AccountMethods(private val client: MastodonClient) {
*/
fun getAccount(accountId: String): MastodonRequest<Account> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId",
endpoint = "$endpoint/$accountId",
method = MastodonClient.Method.GET
)
}
Expand All @@ -69,7 +72,7 @@ class AccountMethods(private val client: MastodonClient) {
*/
fun verifyCredentials(): MastodonRequest<CredentialAccount> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/verify_credentials",
endpoint = "$endpoint/verify_credentials",
method = MastodonClient.Method.GET
)
}
Expand Down Expand Up @@ -167,7 +170,7 @@ class AccountMethods(private val client: MastodonClient) {
defaultLanguage: String?
): MastodonRequest<CredentialAccount> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/update_credentials",
endpoint = "$endpoint/update_credentials",
method = MastodonClient.Method.PATCH,
parameters = Parameters().apply {
displayName?.let { append("display_name", displayName) }
Expand Down Expand Up @@ -199,7 +202,7 @@ class AccountMethods(private val client: MastodonClient) {
@JvmOverloads
fun getFollowers(accountId: String, range: Range = Range()): MastodonRequest<Pageable<Account>> {
return client.getPageableMastodonRequest(
endpoint = "api/v1/accounts/$accountId/followers",
endpoint = "$endpoint/$accountId/followers",
method = MastodonClient.Method.GET,
parameters = range.toParameters()
)
Expand All @@ -214,7 +217,7 @@ class AccountMethods(private val client: MastodonClient) {
@JvmOverloads
fun getFollowing(accountId: String, range: Range = Range()): MastodonRequest<Pageable<Account>> {
return client.getPageableMastodonRequest(
endpoint = "api/v1/accounts/$accountId/following",
endpoint = "$endpoint/$accountId/following",
method = MastodonClient.Method.GET,
parameters = range.toParameters()
)
Expand Down Expand Up @@ -244,7 +247,7 @@ class AccountMethods(private val client: MastodonClient) {
range: Range = Range()
): MastodonRequest<Pageable<Status>> {
return client.getPageableMastodonRequest(
endpoint = "api/v1/accounts/$accountId/statuses",
endpoint = "$endpoint/$accountId/statuses",
method = MastodonClient.Method.GET,
parameters = range.toParameters().apply {
if (onlyMedia) append("only_media", true)
Expand Down Expand Up @@ -275,7 +278,7 @@ class AccountMethods(private val client: MastodonClient) {
filterForLanguages: List<String>? = null
): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/follow",
endpoint = "$endpoint/$accountId/follow",
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
includeReblogs?.let { append("reblogs", includeReblogs) }
Expand All @@ -292,7 +295,7 @@ class AccountMethods(private val client: MastodonClient) {
*/
fun unfollowAccount(accountId: String): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/unfollow",
endpoint = "$endpoint/$accountId/unfollow",
method = MastodonClient.Method.POST
)
}
Expand All @@ -304,7 +307,7 @@ class AccountMethods(private val client: MastodonClient) {
*/
fun blockAccount(accountId: String): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/block",
endpoint = "$endpoint/$accountId/block",
method = MastodonClient.Method.POST
)
}
Expand All @@ -316,7 +319,7 @@ class AccountMethods(private val client: MastodonClient) {
*/
fun unblockAccount(accountId: String): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/unblock",
endpoint = "$endpoint/$accountId/unblock",
method = MastodonClient.Method.POST
)
}
Expand All @@ -338,7 +341,7 @@ class AccountMethods(private val client: MastodonClient) {
muteDuration: Duration? = null
): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/mute",
endpoint = "$endpoint/$accountId/mute",
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
muteNotifications?.let { append("notifications", muteNotifications) }
Expand All @@ -354,7 +357,7 @@ class AccountMethods(private val client: MastodonClient) {
*/
fun unmuteAccount(accountId: String): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/unmute",
endpoint = "$endpoint/$accountId/unmute",
method = MastodonClient.Method.POST
)
}
Expand All @@ -373,7 +376,7 @@ class AccountMethods(private val client: MastodonClient) {
includeSuspended: Boolean? = null
): MastodonRequest<List<Relationship>> {
return client.getMastodonRequestForList(
endpoint = "api/v1/accounts/relationships",
endpoint = "$endpoint/relationships",
method = MastodonClient.Method.GET,
parameters = Parameters().apply {
append("id", accountIds)
Expand Down Expand Up @@ -402,7 +405,7 @@ class AccountMethods(private val client: MastodonClient) {
attemptWebFingerLookup: Boolean? = null
): MastodonRequest<List<Account>> {
return client.getMastodonRequestForList(
endpoint = "api/v1/accounts/search",
endpoint = "$endpoint/search",
method = MastodonClient.Method.GET,
parameters = Parameters().apply {
append("q", query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import social.bigbone.api.exception.BigBoneRequestException
*/
class AnnouncementMethods(private val client: MastodonClient) {

private val announcementsEndpoint = "api/v1/announcements"
private val endpoint = "api/v1/announcements"

/**
* See all currently active announcements set by admins.
Expand All @@ -24,7 +24,7 @@ class AnnouncementMethods(private val client: MastodonClient) {
withDismissed: Boolean = false
): MastodonRequest<List<Announcement>> {
return client.getMastodonRequestForList(
endpoint = announcementsEndpoint,
endpoint = endpoint,
method = MastodonClient.Method.GET,
parameters = Parameters()
.append("with_dismissed", withDismissed)
Expand All @@ -39,7 +39,7 @@ class AnnouncementMethods(private val client: MastodonClient) {
@Throws(BigBoneRequestException::class)
fun dismissAnnouncement(announcementId: String) {
client.performAction(
endpoint = "$announcementsEndpoint/$announcementId/dismiss",
endpoint = "$endpoint/$announcementId/dismiss",
method = MastodonClient.Method.POST
)
}
Expand All @@ -56,7 +56,7 @@ class AnnouncementMethods(private val client: MastodonClient) {
announcementId: String
) {
client.performAction(
endpoint = "$announcementsEndpoint/$announcementId/reactions/$emojiName",
endpoint = "$endpoint/$announcementId/reactions/$emojiName",
method = MastodonClient.Method.PUT
)
}
Expand All @@ -73,7 +73,7 @@ class AnnouncementMethods(private val client: MastodonClient) {
announcementId: String
) {
client.performAction(
endpoint = "$announcementsEndpoint/$announcementId/reactions/$emojiName",
endpoint = "$endpoint/$announcementId/reactions/$emojiName",
method = MastodonClient.Method.DELETE
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import social.bigbone.api.entity.Application
* @see <a href="https://docs.joinmastodon.org/methods/apps/">Mastodon apps API methods</a>
*/
class AppMethods(private val client: MastodonClient) {

private val endpoint = "api/v1/apps"

/**
* Create a new application to obtain OAuth2 credentials.
* @param clientName A name for your application
Expand All @@ -27,7 +30,7 @@ class AppMethods(private val client: MastodonClient) {
scope: Scope? = null
): MastodonRequest<Application> {
return client.getMastodonRequest(
endpoint = "api/v1/apps",
endpoint = endpoint,
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
append("client_name", clientName)
Expand All @@ -50,7 +53,7 @@ class AppMethods(private val client: MastodonClient) {
*/
fun verifyCredentials(): MastodonRequest<Application> {
return client.getMastodonRequest(
endpoint = "api/v1/apps/verify_credentials",
endpoint = "$endpoint/verify_credentials",
method = MastodonClient.Method.GET
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import social.bigbone.api.entity.Account
* @see <a href="https://docs.joinmastodon.org/methods/blocks/">Mastodon blocks API methods</a>
*/
class BlockMethods(private val client: MastodonClient) {

private val endpoint = "api/v1/blocks"

/**
* View your blocks. Blocking and unblocking is achieved via accounts methods.
* @param range optional Range for the pageable return value
Expand All @@ -19,7 +22,7 @@ class BlockMethods(private val client: MastodonClient) {
@JvmOverloads
fun getBlocks(range: Range = Range()): MastodonRequest<Pageable<Account>> {
return client.getPageableMastodonRequest(
endpoint = "api/v1/blocks",
endpoint = endpoint,
method = MastodonClient.Method.GET,
parameters = range.toParameters()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import social.bigbone.api.entity.Status
* @see <a href="https://docs.joinmastodon.org/methods/bookmarks/">Mastodon bookmarks API methods</a>
*/
class BookmarkMethods(private val client: MastodonClient) {

private val endpoint = "api/v1/bookmarks"

/**
* View bookmarked statuses.
* @param range optional Range for the pageable return value
Expand All @@ -19,7 +22,7 @@ class BookmarkMethods(private val client: MastodonClient) {
@JvmOverloads
fun getBookmarks(range: Range = Range()): MastodonRequest<Pageable<Status>> {
return client.getPageableMastodonRequest(
endpoint = "api/v1/bookmarks",
endpoint = endpoint,
method = MastodonClient.Method.GET,
parameters = range.toParameters()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import social.bigbone.api.entity.Conversation
* @see <a href="https://docs.joinmastodon.org/methods/conversations/">Mastodon conversations API methods</a>
*/
class ConversationMethods(private val client: MastodonClient) {

private val endpoint = "api/v1/conversations"

/**
* View your direct conversations with other participants.
* @param range optional Range for the pageable return value
Expand All @@ -19,7 +22,7 @@ class ConversationMethods(private val client: MastodonClient) {
@JvmOverloads
fun getConversations(range: Range = Range()): MastodonRequest<Pageable<Conversation>> {
return client.getPageableMastodonRequest(
endpoint = "api/v1/conversations",
endpoint = endpoint,
method = MastodonClient.Method.GET,
parameters = range.toParameters()
)
Expand All @@ -32,7 +35,7 @@ class ConversationMethods(private val client: MastodonClient) {
*/
fun deleteConversation(conversationId: String) {
client.performAction(
endpoint = "api/v1/conversations/$conversationId",
endpoint = "$endpoint/$conversationId",
method = MastodonClient.Method.DELETE
)
}
Expand All @@ -44,7 +47,7 @@ class ConversationMethods(private val client: MastodonClient) {
*/
fun markConversationAsRead(conversationId: String): MastodonRequest<Conversation> {
return client.getMastodonRequest(
endpoint = "api/v1/conversations/$conversationId/read",
endpoint = "$endpoint/$conversationId/read",
method = MastodonClient.Method.POST
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import social.bigbone.api.entity.CustomEmoji
*/
class CustomEmojiMethods(private val client: MastodonClient) {

private val customEmojisEndpoint = "api/v1/custom_emojis"
private val endpoint = "api/v1/custom_emojis"

/**
* Returns custom emojis that are available on the server.
* @see <a href="https://docs.joinmastodon.org/methods/custom_emojis/#get">Mastodon API documentation: methods/custom_emojis/#get</a>
*/
fun getAllCustomEmojis(): MastodonRequest<List<CustomEmoji>> {
return client.getMastodonRequestForList(
endpoint = customEmojisEndpoint,
endpoint = endpoint,
method = MastodonClient.Method.GET
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import social.bigbone.api.entity.Account
*/
class DirectoryMethods(private val client: MastodonClient) {

private val endpoint = "api/v1/directory"

/**
* When listing, use [AccountOrder.ACTIVE] to sort by most recently posted statuses or [AccountOrder.NEW] to sort
* by most recently created profiles.
Expand All @@ -37,7 +39,7 @@ class DirectoryMethods(private val client: MastodonClient) {
limit: Int? = null
): MastodonRequest<List<Account>> {
return client.getMastodonRequestForList(
endpoint = "api/v1/directory",
endpoint = endpoint,
method = MastodonClient.Method.GET,
parameters = Parameters().apply {
append("local", local)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import social.bigbone.api.Range
*/
class DomainBlockMethods(private val client: MastodonClient) {

private val domainBlocksEndpoint = "/api/v1/domain_blocks"
private val endpoint = "api/v1/domain_blocks"

/**
* View domains the user has blocked.
Expand All @@ -24,7 +24,7 @@ class DomainBlockMethods(private val client: MastodonClient) {
range: Range = Range()
): MastodonRequest<Pageable<String>> {
return client.getPageableMastodonRequest<String>(
endpoint = domainBlocksEndpoint,
endpoint = endpoint,
method = MastodonClient.Method.GET,
parameters = range.toParameters()
)
Expand All @@ -46,7 +46,7 @@ class DomainBlockMethods(private val client: MastodonClient) {
require(!domain.contains(' ')) { "domain must not contain spaces" }

return client.performAction(
endpoint = domainBlocksEndpoint,
endpoint = endpoint,
method = MastodonClient.Method.POST
)
}
Expand All @@ -66,7 +66,7 @@ class DomainBlockMethods(private val client: MastodonClient) {
require(!domain.contains(' ')) { "domain must not contain spaces" }

return client.performAction(
endpoint = domainBlocksEndpoint,
endpoint = endpoint,
method = MastodonClient.Method.DELETE
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import social.bigbone.Parameters
*/
class EmailMethods(private val client: MastodonClient) {

private val emailsEndpoint = "api/v1/emails"
private val endpoint = "api/v1/emails"

/**
* Request a new confirmation email for an unconfirmed user, potentially to a new email address.
Expand All @@ -23,7 +23,7 @@ class EmailMethods(private val client: MastodonClient) {
@JvmOverloads
fun resendConfirmationEmail(emailAddress: String? = null) {
client.performAction(
endpoint = "$emailsEndpoint/confirmations",
endpoint = "$endpoint/confirmations",
method = MastodonClient.Method.POST,
parameters = emailAddress?.let { Parameters().append("email", emailAddress) }
)
Expand Down
Loading