Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed May 31, 2024
2 parents 12d36f8 + 7d53c15 commit e53dd9d
Show file tree
Hide file tree
Showing 462 changed files with 15,961 additions and 11,066 deletions.
17 changes: 10 additions & 7 deletions API_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ There are multiple kinds of models: main models, definition models, record model

### Definition Models
- Documentation for the models are as follows:
- The first line must be structured as "A data model definition for “, followed by a short, one sentence description of what the lexicon is for:
- The first line must be structured as "A definition model for [...].“ (where "[...]") is a short, one sentence description of what the lexicon is for):
```swift
/// A data model definition for the output of checking the user's account status.
/// A definition model for an actor viewer state.
```
The requirements remain the same for the AT Protocol lexicon descriptions, the lexicon's NSID, and the GitHub link.
- For the models themselves, they have the following requirements:
Expand All @@ -180,9 +180,9 @@ There are multiple kinds of models: main models, definition models, record model

### Record Models
- Documentation for the models are as follows:
- The first line must be structured as "A record definition for ", followed by a short, one sentence description of what the lexicon is for:
- The first line must be structured as "A record model for [...]." (where "[...]" is a short, one sentence description of what the lexicon is for):
```swift
/// A record definition of a post.
/// A record model of a post.
```
- After an empty `///` in the next line, the following line has the description that's procided by the lexicon. If there's no description, then this can be skipped. If there is one, it must say "- Note: According to the AT Protocol specifications: "`<#Description#>`"", where "`<#Description#>`" is the description provided by the lexicon.
- After another empty `///` in the next line, the following line states where the API user can see the name of the lexicon, followed by the link. The structure must look like this:
Expand All @@ -200,7 +200,7 @@ There are multiple kinds of models: main models, definition models, record model
### Output Models
- Documentation for the model are as follows:
- The first line must be structured as "An output model for ", followed by a short, one sentence desctiption of what the lexicon is for:
- The first line must be structured as "An output model for [...]." (where "[...]" is a short, one sentence desctiption of what the lexicon is for):
```swift
/// An output model for checking the user's account status.
```
Expand All @@ -223,7 +223,7 @@ There are multiple kinds of models: main models, definition models, record model

### `requestBody` Models
- Documentation for the model are as follows:
- The first line must be structured as "A request body model for ", followed by a short, one sentence desctiption of what the lexicon is for:
- The first line must be structured as "A request body model for [...]." (where "[...]" is a short, one sentence desctiption of what the lexicon is for]):
```swift
/// A request body model for checking the user's account status.
```
Expand Down Expand Up @@ -417,4 +417,7 @@ _TBD..._
```
- If there’s a `return` statement in the `do-catch` block, or if the query method is in there, the request and response methods should be beside each other.
- If any additional method calls are being made, put them beside `createRequest()` and `sendRequest()` if they're strongly related to them.
- In documentation, when referring to the following, you _must_ write them out exactly as shown:
- decentralized identifier (DID)
- content identifer (CID)
- Namespaced Identifier (NSID)
82 changes: 69 additions & 13 deletions Sources/ATProtoKit/ATProtoKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ public class ATProtoKit: ATProtoKitConfiguration {
///
/// If `canUseBlueskyRecords` is set to `false`, these will not be used.
private let recordLexicons: [ATRecordProtocol.Type] = [
FeedGenerator.self, FeedLike.self, FeedPost.self, FeedRepost.self, FeedThreadgate.self, GraphBlock.self, GraphFollow.self, GraphList.self,
GraphListBlock.self, GraphListItem.self, LabelerService.self]
AppBskyLexicon.Feed.GeneratorRecord.self, AppBskyLexicon.Feed.LikeRecord.self, AppBskyLexicon.Feed.PostRecord.self,
AppBskyLexicon.Feed.RepostRecord.self, AppBskyLexicon.Feed.ThreadgateRecord.self, AppBskyLexicon.Graph.BlockRecord.self,
AppBskyLexicon.Graph.FollowRecord.self, AppBskyLexicon.Graph.ListRecord.self, AppBskyLexicon.Graph.ListBlockRecord.self,
AppBskyLexicon.Graph.ListItemRecord.self, AppBskyLexicon.Labeler.ServiceRecord.self, ChatBskyLexicon.Actor.DeclarationRecord.self]

/// Specifies the logger that will be used for emitting log messages.
public private(set) var logger: Logger?
Expand All @@ -135,22 +137,20 @@ public class ATProtoKit: ATProtoKitConfiguration {
/// This will also handle some of the logging-related setup. The identifier will either be your
/// project's `CFBundleIdentifier` or an identifier named
/// `com.cjrriley.ATProtoKit`. However, you can manually override this.
///
/// - Parameters:
/// - session: The authenticated user session within the AT Protocol. Optional.
/// - canUseBlueskyRecords: Indicates whether Bluesky's lexicons should be used.
/// Defaults to `true`.
/// - logIdentifier: Specifies the identifier for managing log outputs. Optional. Defaults
/// - logger: Specifies the identifier for managing log outputs. Optional. Defaults
/// to the project's `CFBundleIdentifier`.
/// - logCategory: Specifies the category name the logs in the logger within ATProtoKit will
/// be in. Optional. Defaults to `ATProtoKit`.
/// - logLevel: Specifies the highest level of logs that will be outputted. Optional.
/// Defaults to `.info`.
public init(session: UserSession? = nil, canUseBlueskyRecords: Bool = true, logger: Logger? = nil) {
self.session = session
self.logger = session?.logger ?? logger

if canUseBlueskyRecords {
if canUseBlueskyRecords && !ATRecordTypeRegistry.areBlueskyRecordsRegistered {
_ = ATRecordTypeRegistry(types: self.recordLexicons)
ATRecordTypeRegistry.areBlueskyRecordsRegistered = false
}
}

Expand Down Expand Up @@ -206,14 +206,70 @@ public class ATProtoAdmin: ATProtoKitConfiguration {
/// Initializes a new instance of `ATProtoAdmin`.
/// - Parameters:
/// - session: The authenticated user session within the AT Protocol.
/// - logIdentifier: Specifies the identifier for managing log outputs. Optional.
/// - logger: Specifies the identifier for managing log outputs. Optional.
/// Defaults to the project's `CFBundleIdentifier`.
/// - logCategory: Specifies the category name the logs in the logger within ATProtoKit
/// will be in. Optional. Defaults to `ATProtoKit`.
/// - logLevel: Specifies the highest level of logs that will be outputted. Optional.
/// Defaults to `.info`.
public init(session: UserSession? = nil, logger: Logger? = nil) {
self.session = session
self.logger = session?.logger ?? logger
}
}

/// The base class that handles all direct Bluesky-related functionality of the ATProtoKit
/// API library.
///
/// This class requires you to first create an instance of ``ATProtoKit/ATProtoKit``. The class
/// will import the session, Bluesky records, and logging information from the instance.
///
/// With some exceptions, the main functionality includes adding, putting, and deleting a record.
public class ATProtoBluesky: ATProtoKitConfiguration {

/// Represents an authenticated user session within the AT Protocol. Optional.
public private(set) var session: UserSession?

/// Specifies the logger that will be used for emitting log messages.
public private(set) var logger: Logger?

/// Represents the instance of ``ATProtoKit/ATProtoKit``.
private let atProtoKitInstance: ATProtoKit

/// Initializes a new instance of `ATProtoBluesky`.
/// - Parameters:
/// - atProtoKitInstance: Represents the instance of ``ATProtoKit/ATProtoKit``.
/// - logger: Specifies the identifier for managing log outputs. Optional.
/// Defaults to the project's `CFBundleIdentifier`.
public init(atProtoKitInstance: ATProtoKit, logger: Logger? = nil) {
self.atProtoKitInstance = atProtoKitInstance
self.session = self.atProtoKitInstance.session ?? nil
self.logger = self.atProtoKitInstance.session?.logger ?? logger
}
}

/// The base class that handles the the Bluesky chat functionality of the ATProtoKit API library.
///
/// This class requires you to first create an instance of ``ATProtoKit/ATProtoKit``. The class
/// will import the session, Bluesky records, and logging information from the instance.
///
/// - Important: Please use an App Password in ``ATProtocolConfiguration`` that has chatting
/// privileges. Failure to do so will result in an error.
public class ATProtoBlueskyChat: ATProtoKitConfiguration {

/// Represents an authenticated user session within the AT Protocol. Optional.
public private(set) var session: UserSession?

/// Specifies the logger that will be used for emitting log messages.
public private(set) var logger: Logger?

/// Represents the instance of ``ATProtoKit/ATProtoKit``.
private let atProtoKitInstance: ATProtoKit

/// Initializes a new instance of `ATProtoBlueskyChat`.
/// - Parameters:
/// - atProtoKitInstance: Represents the instance of ``ATProtoKit/ATProtoKit``.
/// - logger: Specifies the identifier for managing log outputs. Optional.
/// Defaults to the project's `CFBundleIdentifier`.
public init(atProtoKitInstance: ATProtoKit, logger: Logger? = nil) {
self.atProtoKitInstance = atProtoKitInstance
self.session = self.atProtoKitInstance.session ?? nil
self.logger = self.atProtoKitInstance.session?.logger ?? logger
}
}
3 changes: 3 additions & 0 deletions Sources/ATProtoKit/Errors/ATProtoError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public enum ATAPIError: ATProtoError, Decodable {
"UnresolvableDid",
"IncompatibleDidDoc",
"AccountTakedown",
"RepoTakendown",
"RepoDeactivated",
"RepoSuspended",
"DuplicateCreate",
"TokenRequired",
"FutureCursor",
Expand Down
Loading

0 comments on commit e53dd9d

Please sign in to comment.