Skip to content

Commit

Permalink
Conform remaining docs to API guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed May 1, 2024
1 parent c4a2b40 commit a202fa8
Show file tree
Hide file tree
Showing 51 changed files with 404 additions and 211 deletions.
6 changes: 4 additions & 2 deletions Sources/ATProtoKit/Networking/PlatformAPI/CreateLike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ extension ATProtoKit {
/// - Parameters:
/// - strongReference: The URI of the record, which contains the `recordURI` and `cidHash`.
/// - createdAt: The date and time the like record was created. Defaults to `Date.now`.
/// - shouldValidate: Indicates whether the record should be validated. Optional. Defaults to `true`.
/// - Returns: A `Result`, containing either a ``StrongReference`` if it's successful, or an `Error` if it's not.
/// - shouldValidate: Indicates whether the record should be validated. Optional.
/// Defaults to `true`.
/// - Returns: A `Result`, containing either a ``StrongReference``
/// if it's successful, or an `Error` if it's not.
public func createLikeRecord(_ strongReference: StrongReference, createdAt: Date = Date.now,
shouldValidate: Bool? = true) async throws -> Result<StrongReference, Error> {
// guard let sessionURL = session.pdsURL,
Expand Down
40 changes: 26 additions & 14 deletions Sources/ATProtoKit/Networking/PlatformAPI/CreatePost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ extension ATProtoKit {
/// Creates a post record to the user's account.
///
/// - Parameters:
/// - text: The text that's directly displayed in the post record. Current limit is 300 characters.
/// - text: The text that's directly displayed in the post record. Current limit is
/// 300 characters.
/// - locales: The languages the text is written in. Current limit is 3 languages.
/// - replyTo: The post record that this record is replying to.
/// - embed: The embed container attached to the post record. Current items include images, external links, other posts, lists, and post records with media.
/// - embed: The embed container attached to the post record. Current items include
/// images, external links, other posts, lists, and post records with media.
/// - labels: An array of labels made by the user.
/// - tags: An array of tags for the post record.
/// - creationDate: The date of the post record. Defaults to `Date.now`.
/// - recordKey: The record key of the collection. Optional.
/// - shouldValidate: Indicates whether the record should be validated. Optional. Defaults to `true`.
/// - shouldValidate: Indicates whether the record should be validated. Optional.
/// Defaults to `true`.
/// - swapCommit: Swaps out an operation based on the CID. Optional.
/// - Returns: A strong reference, which contains the newly-created record's URI and CID hash.
public func createPostRecord(text: String, locales: [Locale] = [], replyTo: String? = nil, embed: EmbedIdentifier? = nil,
Expand Down Expand Up @@ -93,7 +96,8 @@ extension ATProtoKit {
/// - images: The ``ImageQuery`` that contains the image data. Current limit is 4 images.
/// - pdsURL: The URL of the Personal Data Server (PDS). Defaults to `nil`.
/// - accessToken: The access token used to authenticate to the user.
/// - Returns: An ``EmbedUnion``, which contains an array of ``EmbedImage``s for use in a record.
/// - Returns: An ``EmbedUnion``, which contains an array of ``EmbedImage``s for
/// use in a record.
///
/// - Important: Each image can only be 1 MB in size.
public func uploadImages(_ images: [ImageQuery], pdsURL: String = "https://bsky.social", accessToken: String) async throws -> EmbedUnion {
Expand All @@ -116,9 +120,11 @@ extension ATProtoKit {
return .images(EmbedImages(images: embedImages))
}

/// Scraps the website for the required information in order to attach to a record's embed at a later request.
/// Scraps the website for the required information in order to attach to a record's embed at a
/// later request.
/// - Parameter url: The URL of the website
/// - Returns: An ``EmbedUnion`` which contains an ``EmbedExternal`` for use in a record.
/// - Returns: An ``EmbedUnion`` which contains an ``EmbedExternal`` for use
/// in a record.
public func buildExternalEmbed(from url: URL) async throws -> EmbedUnion? {

// Temporary comment until it's time to work on this part of the library.
Expand All @@ -128,8 +134,10 @@ extension ATProtoKit {
}

/// Grabs and validates a post record to attach to a record's embed at a later request.
/// - Parameter strongReference: An object that contains the record's `recordURI` (URI) and the `cidHash` (CID) .
/// - Returns: A strong reference, which contains a record's `recordURI` (URI) and the `cidHash` (CID) .
/// - Parameter strongReference: An object that contains the record's `recordURI` (URI) and
/// the `cidHash` (CID) .
/// - Returns: A strong reference, which contains a record's `recordURI` (URI) and the
/// `cidHash` (CID) .
public func addQuotePostToEmbed(_ strongReference: StrongReference) async throws -> EmbedUnion {
let record = try await ATProtoTools().fetchRecordForURI(strongReference.recordURI)
let reference = StrongReference(recordURI: record.recordURI, cidHash: record.recordCID)
Expand All @@ -151,19 +159,23 @@ extension ATProtoKit {

/// Represents the different types of content that can be embedded in a post record.
///
/// `EmbedIdentifier` provides a unified interface for specifying embeddable content, simplifying the process of attaching
/// images, external links, other post records, or media to a post. By abstracting the details of each embed type, it allows methods
/// like ``createPostRecord(text:locales:replyTo:embed:labels:tags:creationDate:recordKey:shouldValidate:swapCommit:)``
/// to handle the necessary operations (e.g., uploading, grabbing metadata, validation, etc.) behind the scenes, streamlining the embedding process.
/// `EmbedIdentifier` provides a unified interface for specifying embeddable content,
/// simplifying the process of attaching images, external links, other post records, or media
/// to a post. By abstracting the details of each embed type, it allows methods like
/// ``createPostRecord(text:locales:replyTo:embed:labels:tags:creationDate:recordKey:shouldValidate:swapCommit:)``
/// to handle the necessary operations (e.g., uploading, grabbing metadata, validation, etc.)
/// behind the scenes, streamlining the embedding process.
public enum EmbedIdentifier {
/// Represents a set of images to be embedded in the post.
/// - Parameter images: An array of `ImageQuery` objects, each containing the image data, metadata, and filenames of the image.
/// - Parameter images: An array of `ImageQuery` objects, each containing the image data,
/// metadata, and filenames of the image.
case images(images: [ImageQuery])
/// Represents an external link to be embedded in the post.
/// - Parameter url: A `URL` pointing to the external content.
case external(url: URL)
/// Represents another post record that is to be embedded within the current post.
/// - Parameter strongReference: A `StrongReference` to the post record to be embedded, which contains a record's `recordURI` (URI) and the `cidHash` (CID) .
/// - Parameter strongReference: A `StrongReference` to the post record to be embedded,
/// which contains a record's `recordURI` (URI) and the `cidHash` (CID) .
case record(strongReference: StrongReference)
/// Represents a post record accompanied by media, to be embedded within the current post.
/// - Parameters:
Expand Down
5 changes: 3 additions & 2 deletions Sources/ATProtoKit/Networking/PlatformAPI/DeleteLike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ extension ATProtoKit {

/// Identifies the record based on the specific information provided.
///
/// `RecordIdentifier` provides a unified interface for specifying how the record is defined. This allows methods like ``deleteLikeRecord(_:)`` to handle the backend of how to grab the details
/// of the record so it can delete it.
/// `RecordIdentifier` provides a unified interface for specifying how the record is defined.
/// This allows methods like ``deleteLikeRecord(_:)`` to handle the backend of how to grab the
/// details of the record so it can delete it.
public enum RecordIdentifier {
/// The record object itself.
/// - Parameter recordQuery: the record object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import Foundation
extension ATProtoKit {
/// Gets information about a given feed generator.
///
/// - Note: According to the AT Protocol specifications: "Get information about a feed generator, including policies and offered feed URIs. Does not require auth; implemented by Feed Generator services
/// (not App View)."
/// - Note: According to the AT Protocol specifications: "Get information about a
/// feed generator, including policies and offered feed URIs. Does not require auth;
/// implemented by Feed Generator services (not App View)."
///
/// - SeeAlso: This is based on the [`app.bsky.feed.describeFeedGenerator`][github] lexicon.
///
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/describeFeedGenerator.json
///
/// - Returns: A `Result`, containing either a ``FeedDescribeFeedGeneratorOutput`` if successful, or an `Error` if not.
/// - Returns: A `Result`, containing either a ``FeedDescribeFeedGeneratorOutput``
/// if successful, or an `Error` if not.
public func describeFeedGenerator(pdsURL: String? = nil) async throws -> Result<FeedDescribeFeedGeneratorOutput, Error> {
guard let sessionURL = pdsURL != nil ? pdsURL : session?.pdsURL,
let requestURL = URL(string: "\(sessionURL)/app.bsky.feed.describeFeedGenerator") else {
Expand Down
9 changes: 6 additions & 3 deletions Sources/ATProtoKit/Networking/PlatformAPI/GetActorFeeds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Foundation
extension ATProtoKit {
/// Retrieving a feed list by a user.
///
/// - Note: According to the AT Protocol specifications: "Get a list of feeds (feed generator records) created by the actor (in the actor's repo)."
/// - Note: According to the AT Protocol specifications: "Get a list of feeds (feed generator
/// records) created by the actor (in the actor's repo)."
///
/// - SeeAlso: This is based on the [`app.bsky.feed.getActorFeeds`][github] lexicon.
///
Expand All @@ -19,8 +20,10 @@ extension ATProtoKit {
/// - Parameters:
/// - actorDID: The decentralized identifier (DID) of the user who created the feeds.
/// - limit: The number of items that can be in the list. Optional. Defaults to `50`.
/// - cursor: The mark used to indicate the starting point for the next set of result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetActorFeedsOutput`` if successful, or an `Error` if not.
/// - cursor: The mark used to indicate the starting point for the next set of
/// result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetActorFeedsOutput``
/// if successful, or an `Error` if not.
public func getActorFeeds(by actorDID: String, limit: Int? = 50, cursor: String? = nil) async throws -> Result<FeedGetActorFeedsOutput, Error> {
guard session != nil,
let accessToken = session?.accessToken else {
Expand Down
22 changes: 15 additions & 7 deletions Sources/ATProtoKit/Networking/PlatformAPI/GetActorLikes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import Foundation
extension ATProtoKit {
/// Retrieves all of the user account's likes.
///
/// - Note: Despite the fact that the documentation in the AT Protocol specifications say that this API call doesn't require auth, testing shows that this is not true. It's unclear whether this is intentional
/// (and therefore, the documentation is outdated) or unintentional (in this case, the underlying implementation is outdated). For now, this method will act as if auth is required until Bluesky clarifies their position.
/// - Note: Despite the fact that the documentation in the AT Protocol specifications say that
/// this API call doesn't require auth, testing shows that this is not true. It's unclear
/// whether this is intentional (and therefore, the documentation is outdated) or unintentional
/// (in this case, the underlying implementation is outdated). For now, this method will act as
/// if auth is required until Bluesky clarifies their position.
///
/// - Important: This will only be able to get like records for the authenticated account. This won't work for any other user account. If you need to grab the like records for user accounts other than the
/// authenticated one, use ``listRecords(from:collection:limit:cursor:isArrayReverse:pdsURL:)`` instead.
/// - Important: This will only be able to get like records for the authenticated account.
/// This won't work for any other user account. If you need to grab the like records for user
/// accounts other than the authenticated one, use
/// ``listRecords(from:collection:limit:cursor:isArrayReverse:pdsURL:)`` instead.
///
/// - Note: According to the AT Protocol specifications: "Get a list of posts liked by an actor. Does not require auth."
/// - Note: According to the AT Protocol specifications: "Get a list of posts liked by an
/// actor. Does not require auth."
///
/// - SeeAlso: This is based on the [`app.bsky.feed.getActorLikes`][github] lexicon.
///
Expand All @@ -25,8 +31,10 @@ extension ATProtoKit {
/// - Parameters:
/// - actorDID: The decentralized identifier (DID) of the user account.
/// - limit: The number of items the list will hold. Optional. Defaults to `50`.
/// - cursor: The mark used to indicate the starting point for the next set of result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetActorLikesOutput`` if successful, or an `Error` if not.
/// - cursor: The mark used to indicate the starting point for the next set of
/// result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetActorLikesOutput``
/// if successful, or an `Error` if not.
public func getActorLikes(by actorDID: String, limit: Int? = 50, cursor: String? = nil) async throws -> Result<FeedGetActorLikesOutput, Error> {
guard session != nil,
let accessToken = session?.accessToken else {
Expand Down
16 changes: 11 additions & 5 deletions Sources/ATProtoKit/Networking/PlatformAPI/GetAuthorFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import Foundation
extension ATProtoKit {
/// Retrieves the user account's posts and reposts.
///
/// - Note: Despite the fact that the documentation in the AT Protocol specifications say that this API call doesn't require auth, testing shows that this is not true. It's unclear whether this is intentional
/// (and therefore, the documentation is outdated) or unintentional (in this case, the underlying implementation is outdated). For now, this method will act as if auth is required until Bluesky clarifies their position.
/// - Note: Despite the fact that the documentation in the AT Protocol specifications
/// say that this API call doesn't require auth, testing shows that this is not true. It's
/// unclear whether this is intentional (and therefore, the documentation is outdated) or
/// unintentional (in this case, the underlying implementation is outdated). For now, this
/// method will act as if auth is required until Bluesky clarifies their position.
///
/// - Note: According to the AT Protocol specifications: "Get a view of an actor's 'author feed' (post and reposts by the author). Does not require auth."
/// - Note: According to the AT Protocol specifications: "Get a view of an actor's
/// 'author feed' (post and reposts by the author). Does not require auth."
///
/// - SeeAlso: This is based on the [`app.bsky.feed.getAuthorFeed`][github] lexicon.
///
Expand All @@ -22,8 +26,10 @@ extension ATProtoKit {
/// - Parameters:
/// - actorDID: The decentralized identifier (DID) of the user account.
/// - limit: The number of items the list will hold. Optional. Defaults to `50`.
/// - cursor: The mark used to indicate the starting point for the next set of result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetAuthorFeedOutput`` if successful, or an `Error` if not.
/// - cursor: The mark used to indicate the starting point for the next set of
/// result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetAuthorFeedOutput``
/// if successful, or an `Error` if not.
public func getAuthorFeed(by actorDID: String, limit: Int? = 50, cursor: String? = nil, postFilter:
FeedGetAuthorFeedFilter? = .postsWithReplies) async throws -> Result<FeedGetAuthorFeedOutput, Error> {
guard session != nil,
Expand Down
9 changes: 6 additions & 3 deletions Sources/ATProtoKit/Networking/PlatformAPI/GetFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Foundation
extension ATProtoKit {
/// Views a given feed generator.
///
/// - Note: According to the AT Protocol specifications: "Get a hydrated feed from an actor's selected feed generator. Implemented by App View."
/// - Note: According to the AT Protocol specifications: "Get a hydrated feed from an actor's
/// selected feed generator. Implemented by App View."
///
/// - SeeAlso: This is based on the [`app.bsky.feed.getFeed`][github] lexicon.
///
Expand All @@ -19,8 +20,10 @@ extension ATProtoKit {
/// - Parameters:
/// - feedURI: The URI of the feed generator.
/// - limit: The number of items the list will hold. Optional. Defaults to `50`.
/// - cursor: The mark used to indicate the starting point for the next set of result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetFeedOutput`` if successful, or an `Error` if not.
/// - cursor: The mark used to indicate the starting point for the next set of
/// result. Optional.
/// - Returns: A `Result`, containing either a ``FeedGetFeedOutput``
/// if successful, or an `Error` if not.
public func getFeed(_ feedURI: String, limit: Int? = 50, cursor: String? = nil) async throws -> Result<FeedGetFeedOutput, Error> {
guard session != nil,
let accessToken = session?.accessToken else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import Foundation
extension ATProtoKit {
/// Retrieves information about a given feed generator.
///
/// - Note: If you need information about multiple feed generators, it's best to use ``getFeedGenerators(_:)`` instead.
/// - Note: If you need information about multiple feed generators, it's best to use
/// ``getFeedGenerators(_:)`` instead.
///
/// - Note: According to the AT Protocol specifications: "Get information about a feed generator. Implemented by AppView."
/// - Note: According to the AT Protocol specifications: "Get information about a
/// feed generator. Implemented by AppView."
///
/// - SeeAlso: This is based on the [`app.bsky.feed.getFeedGenerator`][github] lexicon.
///
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getFeedGenerator.json
///
/// - Parameter feedURI: The URI of the feed generator.
/// - Returns: A `Result`, containing either a ``FeedGetFeedGeneratorOutput`` if successful, or an `Error` if not.
/// - Returns: A `Result`, containing either a ``FeedGetFeedGeneratorOutput``
/// if successful, or an `Error` if not.
public func getFeedGenerator(_ feedURI: String) async throws -> Result<FeedGetFeedGeneratorOutput, Error> {
guard session != nil,
let accessToken = session?.accessToken else {
Expand Down
Loading

0 comments on commit a202fa8

Please sign in to comment.