Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed Jul 28, 2024
1 parent a735ddd commit 2655e06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Task {
let session = try await config.authenticate()

let atProto = ATProtoKit(session: session)
let postResult = try await atProto.createPostRecord(text: "Hello Bluesky!")
let atProtoBluesky = ATProtoBluesky(atProtoKitInstance: atProto)

let postResult = try await atProtoBluesky.createPostRecord(text: "Hello Bluesky!")

print(postResult)
} catch {
Expand Down Expand Up @@ -108,14 +110,13 @@ let result = ATProtocolConfiguration(handle: "lucy.example.social", appPassword:
This session contains all of the elements you need, such as the access and refresh tokens:
```swift
Task {
let session = try await config.authenticate()

switch session {
case .success(let result):
print("Result (Access Token): \(result.accessToken)")
print("Result (Refresh Token): \(result.refreshToken)")
case .failure(let error):
print("Error: \(error)")
do {
let session = try await config.authenticate()

print("Result (Access Token): \(session.accessToken)")
print("Result (Refresh Token): \(session.refreshToken)")
} catch {
print("Error: \(error)")
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,22 @@ let atProto = ATProtoKit(session: result)
```

### Creating a post
To create a post, use the ``ATProtoKit/ATProtoKit/createPostRecord(text:locales:replyTo:embed:labels:tags:creationDate:recordKey:shouldValidate:swapCommit:)`` method. While this method is extremely extensive, we're only going to focus on the `text` parameter.
To create a post, first create an ``ATProtoBluesky`` instance, with the ``ATProtoKit/ATProtoKit`` instance as the parameter:
```swift
let atProtoBluesky = ATProtoBluesky(atProtoKitInstance: atProto)
```

Then use the ``ATProtoBluesky/createPostRecord(text:locales:replyTo:embed:labels:tags:creationDate:recordKey:shouldValidate:swapCommit:)`` method. While this method is extremely extensive, we're only going to focus on the `text` parameter.

```swift
let postResult = await atProto.createPostRecord(text: "Hello Bluesky!")
let postResult = try await atProtoBluesky.createPostRecord(text: "Hello Bluesky!")
```

You should see the post in your Bluesky account once you run this code. When the method successfully completes, you'll receive a ``ComAtprotoLexicon/Repository/StrongReference`` object that contains the URI of the record (``ComAtprotoLexicon/Repository/StrongReference/recordURI``) and the content identifier hash of the record (``ComAtprotoLexicon/Repository/StrongReference/cidHash``).


let atProtoBluesky = ATProtoBluesky(atProtoKitInstance: atProto)

let postResult = try await atProtoBluesky.createPostRecord(text: "Hello Bluesky!")

print(postResult)
4 changes: 3 additions & 1 deletion Sources/ATProtoKit/ATProtoKit.docc/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Task {
let session = try await config.authenticate()

let atProto = ATProtoKit(session: session)
let postResult = try await atProto.createPostRecord(text: "Hello Bluesky!")
let atProtoBluesky = ATProtoBluesky(atProtoKitInstance: atProto)

let postResult = try await atProtoBluesky.createPostRecord(text: "Hello Bluesky!")

print(postResult)
} catch {
Expand Down

0 comments on commit 2655e06

Please sign in to comment.