-
-
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
8 changed files
with
245 additions
and
52 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
Sources/ATProtoKit/APIReference/AppBskyAPI/GetQuotes.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,75 @@ | ||
// | ||
// GetQuotes.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-08-23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoKit { | ||
|
||
/// Gets an array of quuote posts that has embeded a given post. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Get a list of quotes for a | ||
/// given post." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.feed.getQuotes`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getQuotes.json | ||
/// | ||
/// | ||
public func getQuotes( | ||
from postURI: String, | ||
postCID: String?, | ||
limit: Int? = 50 | ||
) async throws -> AppBskyLexicon.Feed.GetQuotesOutput { | ||
guard session != nil, | ||
let accessToken = session?.accessToken else { | ||
throw ATRequestPrepareError.missingActiveSession | ||
} | ||
|
||
guard let sessionURL = session?.pdsURL, | ||
let requestURL = URL(string: "\(sessionURL)/xrpc/app.bsky.feed.getQuotes") else { | ||
throw ATRequestPrepareError.invalidRequestURL | ||
} | ||
|
||
var queryItems = [(String, String)]() | ||
|
||
queryItems.append(("uri", postURI)) | ||
|
||
if let postCID { | ||
queryItems.append(("cid", postCID)) | ||
} | ||
|
||
if let limit { | ||
let finalLimit = max(1, min(limit, 100)) | ||
queryItems.append(("limit", "\(finalLimit)")) | ||
} | ||
|
||
let queryURL: URL | ||
|
||
do { | ||
queryURL = try APIClientService.setQueryItems( | ||
for: requestURL, | ||
with: queryItems | ||
) | ||
|
||
let request = APIClientService.createRequest( | ||
forRequest: queryURL, | ||
andMethod: .get, | ||
acceptValue: "application/json", | ||
contentTypeValue: nil, | ||
authorizationValue: "Bearer \(accessToken)" | ||
) | ||
let response = try await APIClientService.shared.sendRequest( | ||
request, | ||
decodeTo: AppBskyLexicon.Feed.GetQuotesOutput.self | ||
) | ||
|
||
return response | ||
} catch { | ||
throw error | ||
} | ||
} | ||
} |
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
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
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
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
34 changes: 34 additions & 0 deletions
34
Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedGetQuotes.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,34 @@ | ||
// | ||
// AppBskyFeedGetQuotes.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-08-23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension AppBskyLexicon.Feed { | ||
|
||
/// An output model for getting the quote posts of a given post. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Get posts in a thread. Does not require | ||
/// auth, but additional metadata and filtering will be applied for authed requests." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.feed.getPostThread`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getPostThread.json | ||
public struct GetQuotesOutput: Codable { | ||
|
||
/// The URI of the given post. | ||
public let postURI: String | ||
|
||
/// The CID hash of the given post. | ||
public let postCID: String? | ||
|
||
/// The mark used to indicate the starting point for the next set of results. Optional. | ||
public let cursor: String? | ||
|
||
/// An array of quote posts. | ||
public let posts: [AppBskyLexicon.Feed.PostViewDefinition] | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedPostgate.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,61 @@ | ||
// | ||
// AppBskyFeedPostgate.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-08-23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension AppBskyLexicon.Feed { | ||
|
||
/// A record model for the rules of a post's interaction. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Record defining interaction rules for | ||
/// a post. The record key (rkey) of the postgate record must match the record key of the post, | ||
/// and that record must be in the same repository." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.feed.postgate`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/postgate.json | ||
public struct PostgateRecord: ATRecordProtocol { | ||
|
||
/// The identifier of the lexicon. | ||
/// | ||
/// - Warning: The value must not change. | ||
public static var type: String = "app.bsky.feed.postgate" | ||
|
||
/// The date and time the post was created. | ||
@DateFormatting public var createdAt: Date | ||
|
||
/// The URI of the post. | ||
public let postURI: String | ||
|
||
/// An array of URIs belonging to posts that the `postURI`'s auther has detached. Optional. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "List of AT-URIs embedding this | ||
/// post that the author has detached from." | ||
public let detachedEmbeddingURIs: [String]? | ||
|
||
/// An array of rules for embedding the post. Optional. | ||
public let embeddingRules: [ATUnion.EmbeddingRulesUnion]? | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(self._createdAt, forKey: .createdAt) | ||
try container.encode(self.postURI, forKey: .postURI) | ||
|
||
try truncatedEncodeIfPresent(self.detachedEmbeddingURIs, withContainer: &container, forKey: .detachedEmbeddingURIs, upToArrayLength: 50) | ||
|
||
try truncatedEncodeIfPresent(self.embeddingRules, withContainer: &container, forKey: .embeddingRules, upToArrayLength: 5) | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case createdAt | ||
case postURI = "post" | ||
case detachedEmbeddingURIs = "detachedEmbeddingUris" | ||
case embeddingRules | ||
} | ||
} | ||
} |
Oops, something went wrong.