-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/BskyFeedSendInteractions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// BskyFeedSendInteractions.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-04-15. | ||
// | ||
|
||
import Foundation | ||
|
||
/// The request body model definition for sending interactions to a feed generator. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "end information about interactions with feed items back to the feed generator | ||
/// that served them." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.feed.sendInteractions`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/sendInteractions.json | ||
public struct FeedSendInteractions: Codable { | ||
/// An array of interactions. | ||
public let interactions: [FeedInteraction] | ||
} | ||
|
||
/// The output model definition for sending interactions to a feed generator. | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.feed.sendInteractions`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/sendInteractions.json | ||
public struct FeedSendInteractionsOutput: Codable {} |
54 changes: 54 additions & 0 deletions
54
Sources/ATProtoKit/Networking/PlatformAPI/SendInteractions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// SendInteractions.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-04-15. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoKit { | ||
/// Sends interactions to a feed generator. | ||
/// | ||
/// - Warning: This is a work in progress. This method may not work as expected. Please use this at your own risk. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "end information about interactions with feed items back to the feed generator | ||
/// that served them." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.feed.sendInteractions`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/sendInteractions.json | ||
/// | ||
/// - Parameter interactions: An array of interactions. | ||
/// - Returns: A `Result`, containing either a ``FeedSendInteractionsOutput`` if sucessful, or an `Error` if not. | ||
public func sendInteractions(_ interactions: [FeedInteraction]) async throws -> Result<FeedSendInteractionsOutput, Error>{ | ||
guard session != nil, | ||
let accessToken = session?.accessToken else { | ||
return .failure(ATRequestPrepareError.missingActiveSession) | ||
} | ||
|
||
guard let sessionURL = session?.pdsURL, | ||
let requestURL = URL(string: "\(sessionURL)/xrpc/app.bsky.feed.sendInteractions") else { | ||
return .failure(ATRequestPrepareError.invalidRequestURL) | ||
} | ||
|
||
let requestBody = FeedSendInteractions( | ||
interactions: interactions | ||
) | ||
|
||
do { | ||
let request = APIClientService.createRequest(forRequest: requestURL, | ||
andMethod: .post, | ||
acceptValue: nil, | ||
contentTypeValue: nil, | ||
authorizationValue: "Bearer \(accessToken)") | ||
let response = try await APIClientService.sendRequest(request, | ||
withEncodingBody: requestBody, | ||
decodeTo: FeedSendInteractionsOutput.self) | ||
|
||
return .success(response) | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
} |