2023-01-20 16:57:25 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2022 Marcin Czachurski and the repository contributors.
|
2023-03-28 10:35:38 +02:00
|
|
|
// Licensed under the Apache License 2.0.
|
2023-01-20 16:57:25 +01:00
|
|
|
//
|
|
|
|
|
2023-01-10 08:04:25 +01:00
|
|
|
import Foundation
|
|
|
|
|
2023-02-19 10:43:37 +01:00
|
|
|
public extension PixelfedClientAuthenticated {
|
2023-01-18 18:41:42 +01:00
|
|
|
func boost(statusId: EntityId) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
// TODO: Check whether the current user already boosted the status
|
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.reblog(statusId),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
2023-01-15 12:41:55 +01:00
|
|
|
|
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-18 18:41:42 +01:00
|
|
|
func unboost(statusId: EntityId) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.unreblog(statusId),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-18 18:41:42 +01:00
|
|
|
func bookmark(statusId: EntityId) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.bookmark(statusId),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-18 18:41:42 +01:00
|
|
|
func unbookmark(statusId: EntityId) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.unbookmark(statusId),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-18 18:41:42 +01:00
|
|
|
func favourite(statusId: EntityId) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.favourite(statusId),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-18 18:41:42 +01:00
|
|
|
func unfavourite(statusId: EntityId) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.unfavourite(statusId),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
2023-02-18 20:59:21 +01:00
|
|
|
|
|
|
|
func pin(statusId: EntityId) async throws -> Status {
|
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.pin(statusId),
|
2023-02-18 20:59:21 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
|
|
|
return try await downloadJson(Status.self, request: request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func unpin(statusId: EntityId) async throws -> Status {
|
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.unpin(statusId),
|
2023-02-18 20:59:21 +01:00
|
|
|
withBearerToken: token
|
|
|
|
)
|
|
|
|
|
|
|
|
return try await downloadJson(Status.self, request: request)
|
|
|
|
}
|
2023-01-10 08:04:25 +01:00
|
|
|
|
2023-02-19 10:43:37 +01:00
|
|
|
func new(statusComponents: Pixelfed.Statuses.Components) async throws -> Status {
|
2023-01-10 08:04:25 +01:00
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.new(statusComponents),
|
2023-01-10 08:04:25 +01:00
|
|
|
withBearerToken: token)
|
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
return try await downloadJson(Status.self, request: request)
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|
2023-02-18 20:59:21 +01:00
|
|
|
|
|
|
|
func delete(statusId: EntityId) async throws {
|
|
|
|
let request = try Self.request(
|
|
|
|
for: baseURL,
|
2023-02-19 10:43:37 +01:00
|
|
|
target: Pixelfed.Statuses.delete(statusId),
|
2023-02-18 20:59:21 +01:00
|
|
|
withBearerToken: token)
|
|
|
|
|
|
|
|
try await send(request: request)
|
|
|
|
}
|
2023-01-10 08:04:25 +01:00
|
|
|
}
|