Update documentation and move to /.build directory

This commit is contained in:
Angelo Stavrow 2021-05-20 15:59:31 -04:00
parent e79851c508
commit 13ed82b066
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
16 changed files with 619 additions and 470 deletions

View File

@ -0,0 +1,18 @@
# Types
- [WFClient](/WFClient)
- [WFError](/WFError)
- [WFCollection](/WFCollection)
- [WFPost](/WFPost)
- [WFUser](/WFUser)
# Protocols
- [URLSessionProtocol](/URLSessionProtocol):
Define requirements for `URLSession`s here for dependency-injection purposes (specifically, for testing).
- [URLSessionDataTaskProtocol](/URLSessionDataTaskProtocol):
Define requirements for `URLSessionDataTask`s here for dependency-injection purposes (specifically, for testing).
# Extensions
- [URLSession](/URLSession)

View File

@ -0,0 +1,12 @@
# Extensions on URLSession
## Methods
### `dataTask(with:completionHandler:)`
``` swift
public func dataTask(
with request: URLRequest,
completionHandler: @escaping DataTaskResult
) -> URLSessionDataTaskProtocol
```

View File

@ -0,0 +1,15 @@
# URLSessionDataTaskProtocol
Define requirements for `URLSessionDataTask`s here for dependency-injection purposes (specifically, for testing).
``` swift
public protocol URLSessionDataTaskProtocol
```
## Requirements
### resume()
``` swift
func resume()
```

View File

@ -0,0 +1,21 @@
# URLSessionProtocol
Define requirements for `URLSession`s here for dependency-injection purposes (specifically, for testing).
``` swift
public protocol URLSessionProtocol
```
## Requirements
### DataTaskResult
``` swift
typealias DataTaskResult = (Data?, URLResponse?, Error?) -> Void
```
### dataTask(with:completionHandler:)
``` swift
func dataTask(with request: URLRequest, completionHandler: @escaping DataTaskResult) -> URLSessionDataTaskProtocol
```

View File

@ -0,0 +1,373 @@
# WFClient
``` swift
public class WFClient
```
## Initializers
### `init(for:with:)`
Initializes the WriteFreely client.
``` swift
public init(for instanceURL: URL, with session: URLSessionProtocol = URLSession.shared)
```
Required for connecting to the API endpoints of a WriteFreely instance.
#### Parameters
- instanceURL: The URL for the WriteFreely instance to which we're connecting, including the protocol.
- session: The URL session to use for connections; defaults to `URLSession.shared`.
## Properties
### `requestURL`
``` swift
public var requestURL: URL
```
### `user`
``` swift
public var user: WFUser?
```
## Methods
### `createCollection(token:withTitle:alias:completion:)`
Creates a new collection.
``` swift
public func createCollection(
token: String? = nil,
withTitle title: String,
alias: String? = nil,
completion: @escaping (Result<WFCollection, Error>) -> Void
)
```
If only a `title` is given, the server will generate and return an alias; in this case, clients should store
the returned `alias` for future operations.
#### Parameters
- token: The access token for the user creating the collection.
- title: The title of the new collection.
- alias: The alias of the collection.
- completion: A handler for the returned `WFCollection` on success, or `Error` on failure.
### `getCollection(token:withAlias:completion:)`
Retrieves a collection's metadata.
``` swift
public func getCollection(
token: String? = nil,
withAlias alias: String,
completion: @escaping (Result<WFCollection, Error>) -> Void
)
```
Collections can be retrieved without authentication. However, authentication is required for retrieving a
private collection or one with scheduled posts.
#### Parameters
- token: The access token for the user retrieving the collection.
- alias: The alias for the collection to be retrieved.
- completion: A handler for the returned `WFCollection` on success, or `Error` on failure.
### `deleteCollection(token:withAlias:completion:)`
Permanently deletes a collection.
``` swift
public func deleteCollection(
token: String? = nil,
withAlias alias: String,
completion: @escaping (Result<Bool, Error>) -> Void
)
```
Any posts in the collection are not deleted; rather, they are made anonymous.
#### Parameters
- token: The access token for the user deleting the collection.
- alias: The alias for the collection to be deleted.
- completion: A hander for the returned `Bool` on success, or `Error` on failure.
### `getPosts(token:in:completion:)`
Retrieves an array of posts.
``` swift
public func getPosts(
token: String? = nil,
in collectionAlias: String? = nil,
completion: @escaping (Result<[WFPost], Error>) -> Void
)
```
If the `collectionAlias` argument is provided, an array of all posts in that collection is retrieved; if
omitted, an array of all posts created by the user whose access token is provided is retrieved.
Collection posts can be retrieved without authentication; however, authentication is required for retrieving a
private collection or one with scheduled posts.
#### Parameters
- token: The access token for the user retrieving the posts.
- collectionAlias: The alias for the collection whose posts are to be retrieved.
- completion: A handler for the returned `[WFPost]` on success, or `Error` on failure.
### `movePost(token:postId:with:to:completion:)`
Moves a post to a collection.
``` swift
public func movePost(
token: String? = nil,
postId: String,
with modifyToken: String? = nil,
to collectionAlias: String?,
completion: @escaping (Result<Bool, Error>) -> Void
)
```
>
#### Parameters
- token: The access token for the user moving the post to a collection.
- postId: The ID of the post to add to the collection.
- modifyToken: The post's modify token; required if the post doesn't belong to the requesting user. If `collectionAlias` is `nil`, do not include a `modifyToken`.
- collectionAlias: The alias of the collection to which the post should be added; if `nil`, this removes the post from any collection.
- completion: A handler for the returned `Bool` on success, or `Error` on failure.
### `pinPost(token:postId:at:in:completion:)`
Pins a post to a collection.
``` swift
public func pinPost(
token: String? = nil,
postId: String,
at position: Int? = nil,
in collectionAlias: String,
completion: @escaping (Result<Bool, Error>) -> Void
)
```
Pinning a post to a collection adds it as a navigation item in the collection/blog home page header, rather
than on the blog itself. While the API endpoint can take an array of posts, this function only accepts a single
post.
#### Parameters
- token: The access token of the user pinning the post to the collection.
- postId: The ID of the post to be pinned.
- position: The numeric position in which to pin the post; if `nil`, will pin at the end of the list.
- collectionAlias: The alias of the collection to which the post should be pinned.
- completion: A handler for the `Bool` returned on success, or `Error` on failure.
### `unpinPost(token:postId:from:completion:)`
Unpins a post from a collection.
``` swift
public func unpinPost(
token: String? = nil,
postId: String,
from collectionAlias: String,
completion: @escaping (Result<Bool, Error>) -> Void
)
```
Removes the post from a navigation item and puts it back on the blog itself. While the API endpoint can take an
array of posts, this function only accepts a single post.
#### Parameters
- token: The access token of the user un-pinning the post from the collection.
- postId: The ID of the post to be un-pinned.
- collectionAlias: The alias of the collection to which the post should be un-pinned.
- completion: A handler for the `Bool` returned on success, or `Error` on failure.
### `createPost(token:post:in:completion:)`
Creates a new post.
``` swift
public func createPost(
token: String? = nil,
post: WFPost,
in collectionAlias: String? = nil,
completion: @escaping (Result<WFPost, Error>) -> Void
)
```
Creates a new post. If a `collectionAlias` is provided, the post is published to that collection; otherwise, it
is posted to the user's Drafts.
#### Parameters
- token: The access token of the user creating the post.
- post: The `WFPost` object to be published.
- collectionAlias: The collection to which the post should be published.
- completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `getPost(token:byId:completion:)`
Retrieves a post.
``` swift
public func getPost(
token: String? = nil,
byId postId: String,
completion: @escaping (Result<WFPost, Error>) -> Void
)
```
The `WFPost` object returned may include additional data, including page views and extracted tags.
#### Parameters
- token: The access token of the user retrieving the post.
- postId: The ID of the post to be retrieved.
- completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `getPost(token:bySlug:from:completion:)`
Retrieves a post from a collection.
``` swift
public func getPost(
token: String? = nil,
bySlug slug: String,
from collectionAlias: String,
completion: @escaping (Result<WFPost, Error>) -> Void
)
```
Collection posts can be retrieved without authentication. However, authentication is required for retrieving a
post from a private collection.
The `WFPost` object returned may include additional data, including page views and extracted tags.
#### Parameters
- token: The access token of the user retrieving the post.
- slug: The slug of the post to be retrieved.
- collectionAlias: The alias of the collection from which the post should be retrieved.
- completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `updatePost(token:postId:updatedPost:with:completion:)`
Updates an existing post.
``` swift
public func updatePost(
token: String? = nil,
postId: String,
updatedPost: WFPost,
with modifyToken: String? = nil,
completion: @escaping (Result<WFPost, Error>) -> Void
)
```
Note that if the `updatedPost` object is provided without a title, the original post's title will be removed.
>
#### Parameters
- token: The access token for the user updating the post.
- postId: The ID of the post to be updated.
- updatedPost: The `WFPost` object with which to update the existing post.
- modifyToken: The post's modify token; required if the post doesn't belong to the requesting user.
- completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `deletePost(token:postId:with:completion:)`
Deletes an existing post.
``` swift
public func deletePost(
token: String? = nil,
postId: String,
with modifyToken: String? = nil,
completion: @escaping (Result<Bool, Error>) -> Void
)
```
>
#### Parameters
- token: The access token for the user deleting the post.
- postId: The ID of the post to be deleted.
- modifyToken: The post's modify token; required if the post doesn't belong to the requesting user.
- completion: A handler for the `Bool` object returned on success, or `Error` on failure.
### `login(username:password:completion:)`
Logs the user in to their account on the WriteFreely instance.
``` swift
public func login(username: String, password: String, completion: @escaping (Result<WFUser, Error>) -> Void)
```
On successful login, the `WFClient`'s `user` property is set to the returned `WFUser` object; this allows
authenticated requests to be made without having to provide an access token.
It is otherwise not necessary to login the user if their access token is provided to the calling function.
#### Parameters
- username: The user's username.
- password: The user's password.
- completion: A handler for the `WFUser` object returned on success, or `Error` on failure.
### `logout(token:completion:)`
Invalidates the user's access token.
``` swift
public func logout(token: String? = nil, completion: @escaping (Result<Bool, Error>) -> Void)
```
#### Parameters
- token: The token to invalidate.
- completion: A handler for the `Bool` object returned on success, or `Error` on failure.
### `getUserData(token:completion:)`
Retrieves a user's basic data.
``` swift
public func getUserData(token: String? = nil, completion: @escaping (Result<Data, Error>) -> Void)
```
#### Parameters
- token: The access token for the user to fetch.
- completion: A handler for the `Data` object returned on success, or `Error` on failure.
### `getUserCollections(token:completion:)`
Retrieves a user's collections.
``` swift
public func getUserCollections(token: String? = nil, completion: @escaping (Result<[WFCollection], Error>) -> Void)
```
#### Parameters
- token: The access token for the user whose collections are to be retrieved.
- completion: A handler for the `[WFCollection]` object returned on success, or `Error` on failure.

View File

@ -1,7 +1,7 @@
# WFCollection # WFCollection
``` swift ``` swift
public struct WFCollection public struct WFCollection
``` ```
## Inheritance ## Inheritance
@ -15,7 +15,7 @@ public struct WFCollection
Creates a basic `WFCollection` object. Creates a basic `WFCollection` object.
``` swift ``` swift
public init(title: String, alias: String?) public init(title: String, alias: String?)
``` ```
This initializer creates a bare-minimum `WFCollection` object for sending to the server; use the decoder-based This initializer creates a bare-minimum `WFCollection` object for sending to the server; use the decoder-based
@ -25,22 +25,22 @@ If no `alias` parameter is provided, one will be generated by the server.
#### Parameters #### Parameters
- title: - title: The title to give the Collection. - title: The title to give the Collection.
- alias: - alias: The alias for the Collection. - alias: The alias for the Collection.
### `init(from:)` ### `init(from:)`
Creates a `WFCollection` object from the server response. Creates a `WFCollection` object from the server response.
``` swift ``` swift
public init(from decoder: Decoder) throws public init(from decoder: Decoder) throws
``` ```
Primarily used by the `WFClient` to create a `WFCollection` object from the JSON returned by the server. Primarily used by the `WFClient` to create a `WFCollection` object from the JSON returned by the server.
#### Parameters #### Parameters
- decoder: - decoder: The decoder to use for translating the server response to a Swift object. - decoder: The decoder to use for translating the server response to a Swift object.
#### Throws #### Throws
@ -51,47 +51,47 @@ Error thrown by the `try` attempt when decoding any given property.
### `alias` ### `alias`
``` swift ``` swift
var alias: String? public var alias: String?
``` ```
### `title` ### `title`
``` swift ``` swift
var title: String public var title: String
``` ```
### `description` ### `description`
``` swift ``` swift
var description: String? public var description: String?
``` ```
### `styleSheet` ### `styleSheet`
``` swift ``` swift
var styleSheet: String? public var styleSheet: String?
``` ```
### `isPublic` ### `isPublic`
``` swift ``` swift
var isPublic: Bool? public var isPublic: Bool?
``` ```
### `views` ### `views`
``` swift ``` swift
var views: Int? public var views: Int?
``` ```
### `email` ### `email`
``` swift ``` swift
var email: String? public var email: String?
``` ```
### `url` ### `url`
``` swift ``` swift
var url: String? public var url: String?
``` ```

View File

@ -0,0 +1,101 @@
# WFError
``` swift
public enum WFError: Int, Error
```
## Inheritance
`Error`, `Int`
## Enumeration Cases
### `badRequest`
``` swift
case badRequest = 400
```
### `unauthorized`
``` swift
case unauthorized = 401
```
### `forbidden`
``` swift
case forbidden = 403
```
### `notFound`
``` swift
case notFound = 404
```
### `methodNotAllowed`
``` swift
case methodNotAllowed = 405
```
### `gone`
``` swift
case gone = 410
```
### `preconditionFailed`
``` swift
case preconditionFailed = 412
```
### `tooManyRequests`
``` swift
case tooManyRequests = 429
```
### `internalServerError`
``` swift
case internalServerError = 500
```
### `badGateway`
``` swift
case badGateway = 502
```
### `serviceUnavailable`
``` swift
case serviceUnavailable = 503
```
### `unknownError`
``` swift
case unknownError = -1
```
### `couldNotComplete`
``` swift
case couldNotComplete = -2
```
### `invalidResponse`
``` swift
case invalidResponse = -3
```
### `invalidData`
``` swift
case invalidData = -4
```

51
docs/WFPost.md → .build/documentation/WFPost.md Executable file → Normal file
View File

@ -1,7 +1,7 @@
# WFPost # WFPost
``` swift ``` swift
public struct WFPost public struct WFPost
``` ```
## Inheritance ## Inheritance
@ -15,7 +15,14 @@ public struct WFPost
Creates a basic `WFPost` object. Creates a basic `WFPost` object.
``` swift ``` swift
public init(body: String, title: String? = nil, appearance: String? = nil, language: String? = nil, rtl: Bool? = nil, createdDate: Date? = nil) public init(
body: String,
title: String? = nil,
appearance: String? = nil,
language: String? = nil,
rtl: Bool? = nil,
createdDate: Date? = nil
)
``` ```
This initializer creates a bare-minimum `WFPost` object for sending to the server; use the decoder-based This initializer creates a bare-minimum `WFPost` object for sending to the server; use the decoder-based
@ -26,26 +33,26 @@ the server.
#### Parameters #### Parameters
- body: - body: The body text for the post. - body: The body text for the post.
- title: - title: The title for the post. - title: The title for the post.
- appearance: - appearance: The appearance for the post; one of `sans`, `serif`/`norm`, `wrap`, `mono`, or `code`. Defaults to `serif`. - appearance: The appearance for the post; one of `sans`, `serif`/`norm`, `wrap`, `mono`, or `code`. Defaults to `serif`.
- language: - language: An ISO 639-1 language code. - language: An ISO 639-1 language code.
- rtl: - rtl: Set to `true` to show content right-to-left. - rtl: Set to `true` to show content right-to-left.
- createdDate: - createdDate: The published date for the post. - createdDate: The published date for the post.
### `init(from:)` ### `init(from:)`
Creates a `WFPost` object from the server response. Creates a `WFPost` object from the server response.
``` swift ``` swift
public init(from decoder: Decoder) throws public init(from decoder: Decoder) throws
``` ```
Primarily used by the `WFClient` to create a `WFPost` object from the JSON returned by the server. Primarily used by the `WFClient` to create a `WFPost` object from the JSON returned by the server.
#### Parameters #### Parameters
- decoder: - decoder: The decoder to use for translating the server response to a Swift object. - decoder: The decoder to use for translating the server response to a Swift object.
#### Throws #### Throws
@ -56,71 +63,71 @@ Error thrown by the `try` attempt when decoding any given property.
### `postId` ### `postId`
``` swift ``` swift
var postId: String? public var postId: String?
``` ```
### `slug` ### `slug`
``` swift ``` swift
var slug: String? public var slug: String?
``` ```
### `appearance` ### `appearance`
``` swift ``` swift
var appearance: String? public var appearance: String?
``` ```
### `language` ### `language`
``` swift ``` swift
var language: String? public var language: String?
``` ```
### `rtl` ### `rtl`
``` swift ``` swift
var rtl: Bool? public var rtl: Bool?
``` ```
### `createdDate` ### `createdDate`
``` swift ``` swift
var createdDate: Date? public var createdDate: Date?
``` ```
### `updatedDate` ### `updatedDate`
``` swift ``` swift
var updatedDate: Date? public var updatedDate: Date?
``` ```
### `title` ### `title`
``` swift ``` swift
var title: String? public var title: String?
``` ```
### `body` ### `body`
``` swift ``` swift
var body: String public var body: String
``` ```
### `tags` ### `tags`
``` swift ``` swift
var tags: [String]? public var tags: [String]?
``` ```
### `views` ### `views`
``` swift ``` swift
var views: Int? public var views: Int?
``` ```
### `collectionAlias` ### `collectionAlias`
``` swift ``` swift
var collectionAlias: String? public var collectionAlias: String?
``` ```

20
docs/WFUser.md → .build/documentation/WFUser.md Executable file → Normal file
View File

@ -1,7 +1,7 @@
# WFUser # WFUser
``` swift ``` swift
public struct WFUser public struct WFUser
``` ```
## Inheritance ## Inheritance
@ -15,29 +15,29 @@ public struct WFUser
Creates a minimum `WFUser` object from a stored token. Creates a minimum `WFUser` object from a stored token.
``` swift ``` swift
public init(token: String, username: String?) public init(token: String, username: String?)
``` ```
Use this when the client has already logged in a user and only needs to reconstruct the type from saved properties. Use this when the client has already logged in a user and only needs to reconstruct the type from saved properties.
#### Parameters #### Parameters
- token: - token: The user's access token - token: The user's access token
- username: - username: The user's username (optional) - username: The user's username (optional)
### `init(from:)` ### `init(from:)`
Creates a `WFUser` object from the server response. Creates a `WFUser` object from the server response.
``` swift ``` swift
public init(from decoder: Decoder) throws public init(from decoder: Decoder) throws
``` ```
Primarily used by the `WFClient` to create a `WFUser` object from the JSON returned by the server. Primarily used by the `WFClient` to create a `WFUser` object from the JSON returned by the server.
#### Parameters #### Parameters
- decoder: - decoder: The decoder to use for translating the server response to a Swift object. - decoder: The decoder to use for translating the server response to a Swift object.
#### Throws #### Throws
@ -48,23 +48,23 @@ Error thrown by the `try` attempt when decoding any given property.
### `token` ### `token`
``` swift ``` swift
var token: String public var token: String
``` ```
### `username` ### `username`
``` swift ``` swift
var username: String? public var username: String?
``` ```
### `email` ### `email`
``` swift ``` swift
var email: String? public var email: String?
``` ```
### `createdDate` ### `createdDate`
``` swift ``` swift
var createdDate: Date? public var createdDate: Date?
``` ```

View File

@ -0,0 +1 @@
Generated at 2021-05-20T15:56:24-0400 using [swift-doc](https://github.com/SwiftDocOrg/swift-doc) 1.0.0-beta.6.

View File

@ -0,0 +1,25 @@
<details>
<summary>Types</summary>
- [WFClient](/WFClient)
- [WFCollection](/WFCollection)
- [WFError](/WFError)
- [WFPost](/WFPost)
- [WFUser](/WFUser)
</details>
<details>
<summary>Protocols</summary>
- [URLSessionDataTaskProtocol](/URLSessionDataTaskProtocol)
- [URLSessionProtocol](/URLSessionProtocol)
</details>
<details>
<summary>Extensions</summary>
- [URLSession](/URLSession)
</details>

View File

@ -1,7 +0,0 @@
# Types
- [WFClient](/WFClient)
- [WFCollection](/WFCollection)
- [WFError](/WFError)
- [WFPost](/WFPost)
- [WFUser](/WFUser)

View File

@ -1,329 +0,0 @@
# WFClient
``` swift
public class WFClient
```
## Initializers
### `init(for:)`
Initializes the WriteFreely client.
``` swift
public init(for instanceURL: URL)
```
Required for connecting to the API endpoints of a WriteFreely instance.
#### Parameters
- instanceURL: - instanceURL: The URL for the WriteFreely instance to which we're connecting, including the protocol.
## Properties
### `decoder`
``` swift
let decoder
```
### `requestURL`
``` swift
var requestURL: URL
```
### `user`
``` swift
var user: WFUser?
```
## Methods
### `createCollection(token:withTitle:alias:completion:)`
Creates a new collection.
``` swift
public func createCollection(token: String? = nil, withTitle title: String, alias: String? = nil, completion: @escaping (Result<WFCollection, Error>) -> Void)
```
If only a `title` is given, the server will generate and return an alias; in this case, clients should store
the returned `alias` for future operations.
#### Parameters
- token: - token: The access token for the user creating the collection.
- title: - title: The title of the new collection.
- alias: - alias: The alias of the collection.
- completion: - completion: A handler for the returned `WFCollection` on success, or `Error` on failure.
### `getCollection(token:withAlias:completion:)`
Retrieves a collection's metadata.
``` swift
public func getCollection(token: String? = nil, withAlias alias: String, completion: @escaping (Result<WFCollection, Error>) -> Void)
```
Collections can be retrieved without authentication. However, authentication is required for retrieving a
private collection or one with scheduled posts.
#### Parameters
- token: - token: The access token for the user retrieving the collection.
- alias: - alias: The alias for the collection to be retrieved.
- completion: - completion: A handler for the returned `WFCollection` on success, or `Error` on failure.
### `deleteCollection(token:withAlias:completion:)`
Permanently deletes a collection.
``` swift
public func deleteCollection(token: String? = nil, withAlias alias: String, completion: @escaping (Result<Bool, Error>) -> Void)
```
Any posts in the collection are not deleted; rather, they are made anonymous.
#### Parameters
- token: - token: The access token for the user deleting the collection.
- alias: - alias: The alias for the collection to be deleted.
- completion: - completion: A hander for the returned `Bool` on success, or `Error` on failure.
### `getPosts(token:in:completion:)`
Retrieves an array of posts.
``` swift
public func getPosts(token: String? = nil, in collectionAlias: String? = nil, completion: @escaping (Result<[WFPost], Error>) -> Void)
```
If the `collectionAlias` argument is provided, an array of all posts in that collection is retrieved; if
omitted, an array of all posts created by the user whose access token is provided is retrieved.
Collection posts can be retrieved without authentication; however, authentication is required for retrieving a
private collection or one with scheduled posts.
#### Parameters
- token: - token: The access token for the user retrieving the posts.
- collectionAlias: - collectionAlias: The alias for the collection whose posts are to be retrieved.
- completion: - completion: A handler for the returned `[WFPost]` on success, or `Error` on failure.
### `movePost(token:postId:with:to:completion:)`
Moves a post to a collection.
``` swift
public func movePost(token: String? = nil, postId: String, with modifyToken: String? = nil, to collectionAlias: String, completion: @escaping (Result<Bool, Error>) -> Void)
```
> Attention: - The closure should return a result type of \`\<\[WFPost\], Error\>\`.
> - The modifyToken for the post is currently ignored.
>
#### Parameters
- token: - token: The access token for the user moving the post to a collection.
- postId: - postId: The ID of the post to add to the collection.
- modifyToken: - modifyToken: The post's modify token; required if the post doesn't belong to the requesting user.
- collectionAlias: - collectionAlias: The alias of the collection to which the post should be added.
- completion: - completion: A handler for the returned `Bool` on success, or `Error` on failure.
### `pinPost(token:postId:at:in:completion:)`
Pins a post to a collection.
``` swift
public func pinPost(token: String? = nil, postId: String, at position: Int? = nil, in collectionAlias: String, completion: @escaping (Result<Bool, Error>) -> Void)
```
Pinning a post to a collection adds it as a navigation item in the collection/blog home page header, rather
than on the blog itself. While the API endpoint can take an array of posts, this function only accepts a single
post.
#### Parameters
- token: - token: The access token of the user pinning the post to the collection.
- postId: - postId: The ID of the post to be pinned.
- position: - position: The numeric position in which to pin the post; if `nil`, will pin at the end of the list.
- collectionAlias: - collectionAlias: The alias of the collection to which the post should be pinned.
- completion: - completion: A handler for the `Bool` returned on success, or `Error` on failure.
### `unpinPost(token:postId:from:completion:)`
Unpins a post from a collection.
``` swift
public func unpinPost(token: String? = nil, postId: String, from collectionAlias: String, completion: @escaping (Result<Bool, Error>) -> Void)
```
Removes the post from a navigation item and puts it back on the blog itself. While the API endpoint can take an
array of posts, this function only accepts a single post.
#### Parameters
- token: - token: The access token of the user un-pinning the post from the collection.
- postId: - postId: The ID of the post to be un-pinned.
- collectionAlias: - collectionAlias: The alias of the collection to which the post should be un-pinned.
- completion: - completion: A handler for the `Bool` returned on success, or `Error` on failure.
### `createPost(token:post:in:completion:)`
Creates a new post.
``` swift
public func createPost(token: String? = nil, post: WFPost, in collectionAlias: String? = nil, completion: @escaping (Result<WFPost, Error>) -> Void)
```
Creates a new post. If a `collectionAlias` is provided, the post is published to that collection; otherwise, it
is posted to the user's Drafts.
#### Parameters
- token: - token: The access token of the user creating the post.
- post: - post: The `WFPost` object to be published.
- collectionAlias: - collectionAlias: The collection to which the post should be published.
- completion: - completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `getPost(token:byId:completion:)`
Retrieves a post.
``` swift
public func getPost(token: String? = nil, byId postId: String, completion: @escaping (Result<WFPost, Error>) -> Void)
```
The `WFPost` object returned may include additional data, including page views and extracted tags.
#### Parameters
- token: - token: The access token of the user retrieving the post.
- postId: - postId: The ID of the post to be retrieved.
- completion: - completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `getPost(token:bySlug:from:completion:)`
Retrieves a post from a collection.
``` swift
public func getPost(token: String? = nil, bySlug slug: String, from collectionAlias: String, completion: @escaping (Result<WFPost, Error>) -> Void)
```
Collection posts can be retrieved without authentication. However, authentication is required for retrieving a
post from a private collection.
The `WFPost` object returned may include additional data, including page views and extracted tags.
#### Parameters
- token: - token: The access token of the user retrieving the post.
- slug: - slug: The slug of the post to be retrieved.
- collectionAlias: - collectionAlias: The alias of the collection from which the post should be retrieved.
- completion: - completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `updatePost(token:postId:updatedPost:with:completion:)`
Updates an existing post.
``` swift
public func updatePost(token: String? = nil, postId: String, updatedPost: WFPost, with modifyToken: String? = nil, completion: @escaping (Result<WFPost, Error>) -> Void)
```
Note that if the `updatedPost` object is provided without a title, the original post's title will be removed.
> Attention: - The modifyToken for the post is currently ignored.
>
#### Parameters
- token: - token: The access token for the user updating the post.
- postId: - postId: The ID of the post to be updated.
- updatedPost: - updatedPost: The `WFPost` object with which to update the existing post.
- modifyToken: - modifyToken: The post's modify token; required if the post doesn't belong to the requesting user.
- completion: - completion: A handler for the `WFPost` object returned on success, or `Error` on failure.
### `deletePost(token:postId:with:completion:)`
Deletes an existing post.
``` swift
public func deletePost(token: String? = nil, postId: String, with modifyToken: String? = nil, completion: @escaping (Result<Bool, Error>) -> Void)
```
> Attention: - The modifyToken for the post is currently ignored.
>
#### Parameters
- token: - token: The access token for the user deleting the post.
- postId: - postId: The ID of the post to be deleted.
- modifyToken: - modifyToken: The post's modify token; required if the post doesn't belong to the requesting user.
- completion: - completion: A handler for the `Bool` object returned on success, or `Error` on failure.
### `login(username:password:completion:)`
Logs the user in to their account on the WriteFreely instance.
``` swift
public func login(username: String, password: String, completion: @escaping (Result<WFUser, Error>) -> Void)
```
On successful login, the `WFClient`'s `user` property is set to the returned `WFUser` object; this allows
authenticated requests to be made without having to provide an access token.
It is otherwise not necessary to login the user if their access token is provided to the calling function.
#### Parameters
- username: - username: The user's username.
- password: - password: The user's password.
- completion: - completion: A handler for the `WFUser` object returned on success, or `Error` on failure.
### `logout(token:completion:)`
Invalidates the user's access token.
``` swift
public func logout(token: String? = nil, completion: @escaping (Result<Bool, Error>) -> Void)
```
#### Parameters
- token: - token: The token to invalidate.
- completion: - completion: A handler for the `Bool` object returned on success, or `Error` on failure.
### `getUserData(token:completion:)`
Retrieves a user's basic data.
``` swift
public func getUserData(token: String? = nil, completion: @escaping (Result<Data, Error>) -> Void)
```
#### Parameters
- token: - token: The access token for the user to fetch.
- completion: - completion: A handler for the `Data` object returned on success, or `Error` on failure.
### `getUserCollections(token:completion:)`
Retrieves a user's collections.
``` swift
public func getUserCollections(token: String? = nil, completion: @escaping (Result<[WFCollection], Error>) -> Void)
```
#### Parameters
- token: - token: The access token for the user whose collections are to be retrieved.
- completion: - completion: A handler for the `[WFCollection]` object returned on success, or `Error` on failure.
### `translateWFError(fromServerResponse:)`
``` swift
func translateWFError(fromServerResponse response: Data) -> WFError?
```

View File

@ -1,77 +0,0 @@
# WFError
``` swift
public enum WFError
```
## Inheritance
`Error`, `Int`
## Enumeration Cases
### `badRequest`
``` swift
case badRequest
```
### `unauthorized`
``` swift
case unauthorized
```
### `forbidden`
``` swift
case forbidden
```
### `notFound`
``` swift
case notFound
```
### `methodNotAllowed`
``` swift
case methodNotAllowed
```
### `gone`
``` swift
case gone
```
### `preconditionFailed`
``` swift
case preconditionFailed
```
### `tooManyRequests`
``` swift
case tooManyRequests
```
### `internalServerError`
``` swift
case internalServerError
```
### `badGateway`
``` swift
case badGateway
```
### `serviceUnavailable`
``` swift
case serviceUnavailable
```

View File

@ -1 +0,0 @@
Generated at 2020-08-31T10:27:33-0400 using [swift-doc](https://github.com/SwiftDocOrg/swift-doc) 1.0.0-beta.3.

View File

@ -1,10 +0,0 @@
<details>
<summary>Types</summary>
- [WFClient](/WFClient)
- [WFCollection](/WFCollection)
- [WFError](/WFError)
- [WFPost](/WFPost)
- [WFUser](/WFUser)
</details>