writefreely-swift/docs/WFClient/index.html

1004 lines
38 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WriteFreely - WFClient</title>
<link rel="stylesheet" type="text/css" href="writefreely-swift/all.css" media="all" />
</head>
<body>
<header>
<a href="writefreely-swift">
<strong>
WriteFreely
</strong>
<span>Documentation</span>
</a>
<sup>Beta</sup>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#initializers">Initializers</a><ul><li class="initializer"><a href="#wfclient.init(for:with:)">init(for:with:)</a></li></ul></li><li><a href="#properties">Properties</a><ul><li class="variable"><a href="#wfclient.requesturl">requestURL</a></li><li class="variable"><a href="#wfclient.user">user</a></li></ul></li><li><a href="#methods">Methods</a><ul><li class="function"><a href="#wfclient.createcollection(token:withtitle:alias:completion:)">createCollection(token:withTitle:alias:completion:)</a></li><li class="function"><a href="#wfclient.getcollection(token:withalias:completion:)">getCollection(token:withAlias:completion:)</a></li><li class="function"><a href="#wfclient.deletecollection(token:withalias:completion:)">deleteCollection(token:withAlias:completion:)</a></li><li class="function"><a href="#wfclient.getposts(token:in:completion:)">getPosts(token:in:completion:)</a></li><li class="function"><a href="#wfclient.movepost(token:postid:with:to:completion:)">movePost(token:postId:with:to:completion:)</a></li><li class="function"><a href="#wfclient.pinpost(token:postid:at:in:completion:)">pinPost(token:postId:at:in:completion:)</a></li><li class="function"><a href="#wfclient.unpinpost(token:postid:from:completion:)">unpinPost(token:postId:from:completion:)</a></li><li class="function"><a href="#wfclient.createpost(token:post:in:completion:)">createPost(token:post:in:completion:)</a></li><li class="function"><a href="#wfclient.getpost(token:byid:completion:)">getPost(token:byId:completion:)</a></li><li class="function"><a href="#wfclient.getpost(token:byslug:from:completion:)">getPost(token:bySlug:from:completion:)</a></li><li class="function"><a href="#wfclient.updatepost(token:postid:updatedpost:with:completion:)">updatePost(token:postId:updatedPost:with:completion:)</a></li><li class="function"><a href="#wfclient.deletepost(token:postid:with:completion:)">deletePost(token:postId:with:completion:)</a></li><li class="function"><a href="#wfclient.login(username:password:completion:)">login(username:password:completion:)</a></li><li class="function"><a href="#wfclient.logout(token:completion:)">logout(token:completion:)</a></li><li class="function"><a href="#wfclient.getuserdata(token:completion:)">getUserData(token:completion:)</a></li><li class="function"><a href="#wfclient.getusercollections(token:completion:)">getUserCollections(token:completion:)</a></li></ul></li></ol>
</div>
</nav>
<main>
<article>
<h1>
<small>Class</small>
<code class="name">WFClient</code>
</h1>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">class</span> <span class="type">WFClient</span> </code></pre>
</div>
<section id="initializers">
<h2>Initializers</h2>
<div role="article" class="initializer" id="wfclient.init(for:with:)">
<h3>
<code>init(for:with:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">init</span>(<span class="variable">for</span> <span class="variable">instanceURL</span>: <span class="type">URL</span>, <span class="variable">with</span> <span class="variable">session</span>: <span class="type">URLSessionProtocol</span> = <span class="variable">URLSession</span>.<span class="variable">shared</span>) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Initializes the WriteFreely client.</p>
</div>
<div class="discussion">
<p>Required for connecting to the API endpoints of a WriteFreely instance.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>instanceURL</th>
<td><code class="type">URL</code></td>
<td><p>The URL for the WriteFreely instance to which we're connecting, including the protocol.</p>
</td>
</tr>
<tr>
<th>session</th>
<td><code class="type">URLSessionProtocol</code></td>
<td><p>The URL session to use for connections; defaults to <code>URLSession.shared</code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="properties">
<h2>Properties</h2>
<div role="article" class="variable" id="wfclient.requesturl">
<h3>
<code>requestURL</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">var</span> <span class="variable">requestURL</span>: <span class="type">URL</span></code></pre>
</div>
</div>
<div role="article" class="variable" id="wfclient.user">
<h3>
<code>user</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">var</span> <span class="variable">user</span>: <span class="type">WFUser</span>?</code></pre>
</div>
</div>
</section>
<section id="methods">
<h2>Methods</h2>
<div role="article" class="function" id="wfclient.createcollection(token:withtitle:alias:completion:)">
<h3>
<code>createCollection(token:withTitle:alias:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">createCollection</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">withTitle</span> <span class="variable">title</span>: <span class="type">String</span>,
<span class="variable">alias</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFCollection</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Creates a new collection.</p>
</div>
<div class="discussion">
<p>If only a <code>title</code> is given, the server will generate and return an alias; in this case, clients should store
the returned <code>alias</code> for future operations.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user creating the collection.</p>
</td>
</tr>
<tr>
<th>title</th>
<td><code class="type">String</code></td>
<td><p>The title of the new collection.</p>
</td>
</tr>
<tr>
<th>alias</th>
<td><code class="type">String?</code></td>
<td><p>The alias of the collection.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFCollection, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the returned <code>WFCollection</code> on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.getcollection(token:withalias:completion:)">
<h3>
<code>getCollection(token:withAlias:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">getCollection</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">withAlias</span> <span class="variable">alias</span>: <span class="type">String</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFCollection</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Retrieves a collection's metadata.</p>
</div>
<div class="discussion">
<p>Collections can be retrieved without authentication. However, authentication is required for retrieving a
private collection or one with scheduled posts.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user retrieving the collection.</p>
</td>
</tr>
<tr>
<th>alias</th>
<td><code class="type">String</code></td>
<td><p>The alias for the collection to be retrieved.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFCollection, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the returned <code>WFCollection</code> on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.deletecollection(token:withalias:completion:)">
<h3>
<code>deleteCollection(token:withAlias:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">deleteCollection</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">withAlias</span> <span class="variable">alias</span>: <span class="type">String</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Bool</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Permanently deletes a collection.</p>
</div>
<div class="discussion">
<p>Any posts in the collection are not deleted; rather, they are made anonymous.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user deleting the collection.</p>
</td>
</tr>
<tr>
<th>alias</th>
<td><code class="type">String</code></td>
<td><p>The alias for the collection to be deleted.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Bool, Error&gt;) -&gt; Void</code></td>
<td><p>A hander for the returned <code>Bool</code> on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.getposts(token:in:completion:)">
<h3>
<code>getPosts(token:in:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">getPosts</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">in</span> <span class="variable">collectionAlias</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;[<span class="type">WFPost</span>], <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Retrieves an array of posts.</p>
</div>
<div class="discussion">
<p>If the <code>collectionAlias</code> 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.</p>
<p>Collection posts can be retrieved without authentication; however, authentication is required for retrieving a
private collection or one with scheduled posts.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user retrieving the posts.</p>
</td>
</tr>
<tr>
<th>collectionAlias</th>
<td><code class="type">String?</code></td>
<td><p>The alias for the collection whose posts are to be retrieved.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;[WFPost], Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the returned <code>[WFPost]</code> on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.movepost(token:postid:with:to:completion:)">
<h3>
<code>movePost(token:postId:with:to:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">movePost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">postId</span>: <span class="type">String</span>,
<span class="variable">with</span> <span class="variable">modifyToken</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">to</span> <span class="variable">collectionAlias</span>: <span class="type">String</span>?,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Bool</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Moves a post to a collection.</p>
</div>
<div class="discussion">
<aside class="Attention">
<ul>
<li>The closure should return a result type of <code>&lt;[WFPost], Error&gt;</code>.</li>
<li>The modifyToken for the post is currently ignored.</li>
</ul>
</aside>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user moving the post to a collection.</p>
</td>
</tr>
<tr>
<th>postId</th>
<td><code class="type">String</code></td>
<td><p>The ID of the post to add to the collection.</p>
</td>
</tr>
<tr>
<th>modifyToken</th>
<td><code class="type">String?</code></td>
<td><p>The post's modify token; required if the post doesn't belong to the requesting user. If <code>collectionAlias</code> is <code>nil</code>, do not include a <code>modifyToken</code>.</p>
</td>
</tr>
<tr>
<th>collectionAlias</th>
<td><code class="type">String?</code></td>
<td><p>The alias of the collection to which the post should be added; if <code>nil</code>, this removes the post from any collection.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Bool, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the returned <code>Bool</code> on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.pinpost(token:postid:at:in:completion:)">
<h3>
<code>pinPost(token:postId:at:in:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">pinPost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">postId</span>: <span class="type">String</span>,
<span class="variable">at</span> <span class="variable">position</span>: <span class="type">Int</span>? = <span class="keyword">nil</span>,
<span class="variable">in</span> <span class="variable">collectionAlias</span>: <span class="type">String</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Bool</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Pins a post to a collection.</p>
</div>
<div class="discussion">
<p>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.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token of the user pinning the post to the collection.</p>
</td>
</tr>
<tr>
<th>postId</th>
<td><code class="type">String</code></td>
<td><p>The ID of the post to be pinned.</p>
</td>
</tr>
<tr>
<th>position</th>
<td><code class="type">Int?</code></td>
<td><p>The numeric position in which to pin the post; if <code>nil</code>, will pin at the end of the list.</p>
</td>
</tr>
<tr>
<th>collectionAlias</th>
<td><code class="type">String</code></td>
<td><p>The alias of the collection to which the post should be pinned.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Bool, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>Bool</code> returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.unpinpost(token:postid:from:completion:)">
<h3>
<code>unpinPost(token:postId:from:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">unpinPost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">postId</span>: <span class="type">String</span>,
<span class="variable">from</span> <span class="variable">collectionAlias</span>: <span class="type">String</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Bool</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Unpins a post from a collection.</p>
</div>
<div class="discussion">
<p>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.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token of the user un-pinning the post from the collection.</p>
</td>
</tr>
<tr>
<th>postId</th>
<td><code class="type">String</code></td>
<td><p>The ID of the post to be un-pinned.</p>
</td>
</tr>
<tr>
<th>collectionAlias</th>
<td><code class="type">String</code></td>
<td><p>The alias of the collection to which the post should be un-pinned.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Bool, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>Bool</code> returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.createpost(token:post:in:completion:)">
<h3>
<code>createPost(token:post:in:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">createPost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">post</span>: <span class="type">WFPost</span>,
<span class="variable">in</span> <span class="variable">collectionAlias</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFPost</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Creates a new post.</p>
</div>
<div class="discussion">
<p>Creates a new post. If a <code>collectionAlias</code> is provided, the post is published to that collection; otherwise, it
is posted to the user's Drafts.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token of the user creating the post.</p>
</td>
</tr>
<tr>
<th>post</th>
<td><code class="type">WFPost</code></td>
<td><p>The <code>WFPost</code> object to be published.</p>
</td>
</tr>
<tr>
<th>collectionAlias</th>
<td><code class="type">String?</code></td>
<td><p>The collection to which the post should be published.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFPost, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>WFPost</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.getpost(token:byid:completion:)">
<h3>
<code>getPost(token:byId:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">getPost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">byId</span> <span class="variable">postId</span>: <span class="type">String</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFPost</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Retrieves a post.</p>
</div>
<div class="discussion">
<p>The <code>WFPost</code> object returned may include additional data, including page views and extracted tags.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token of the user retrieving the post.</p>
</td>
</tr>
<tr>
<th>postId</th>
<td><code class="type">String</code></td>
<td><p>The ID of the post to be retrieved.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFPost, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>WFPost</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.getpost(token:byslug:from:completion:)">
<h3>
<code>getPost(token:bySlug:from:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">getPost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">bySlug</span> <span class="variable">slug</span>: <span class="type">String</span>,
<span class="variable">from</span> <span class="variable">collectionAlias</span>: <span class="type">String</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFPost</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Retrieves a post from a collection.</p>
</div>
<div class="discussion">
<p>Collection posts can be retrieved without authentication. However, authentication is required for retrieving a
post from a private collection.</p>
<p>The <code>WFPost</code> object returned may include additional data, including page views and extracted tags.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token of the user retrieving the post.</p>
</td>
</tr>
<tr>
<th>slug</th>
<td><code class="type">String</code></td>
<td><p>The slug of the post to be retrieved.</p>
</td>
</tr>
<tr>
<th>collectionAlias</th>
<td><code class="type">String</code></td>
<td><p>The alias of the collection from which the post should be retrieved.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFPost, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>WFPost</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.updatepost(token:postid:updatedpost:with:completion:)">
<h3>
<code>updatePost(token:postId:updatedPost:with:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">updatePost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">postId</span>: <span class="type">String</span>,
<span class="variable">updatedPost</span>: <span class="type">WFPost</span>,
<span class="variable">with</span> <span class="variable">modifyToken</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFPost</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Updates an existing post.</p>
</div>
<div class="discussion">
<p>Note that if the <code>updatedPost</code> object is provided without a title, the original post's title will be removed.</p>
<aside class="Attention">
<ul>
<li>The modifyToken for the post is currently ignored.</li>
</ul>
</aside>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user updating the post.</p>
</td>
</tr>
<tr>
<th>postId</th>
<td><code class="type">String</code></td>
<td><p>The ID of the post to be updated.</p>
</td>
</tr>
<tr>
<th>updatedPost</th>
<td><code class="type">WFPost</code></td>
<td><p>The <code>WFPost</code> object with which to update the existing post.</p>
</td>
</tr>
<tr>
<th>modifyToken</th>
<td><code class="type">String?</code></td>
<td><p>The post's modify token; required if the post doesn't belong to the requesting user.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFPost, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>WFPost</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.deletepost(token:postid:with:completion:)">
<h3>
<code>deletePost(token:postId:with:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">deletePost</span>(
<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">postId</span>: <span class="type">String</span>,
<span class="variable">with</span> <span class="variable">modifyToken</span>: <span class="type">String</span>? = <span class="keyword">nil</span>,
<span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Bool</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>
) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Deletes an existing post.</p>
</div>
<div class="discussion">
<aside class="Attention">
<ul>
<li>The modifyToken for the post is currently ignored.</li>
</ul>
</aside>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user deleting the post.</p>
</td>
</tr>
<tr>
<th>postId</th>
<td><code class="type">String</code></td>
<td><p>The ID of the post to be deleted.</p>
</td>
</tr>
<tr>
<th>modifyToken</th>
<td><code class="type">String?</code></td>
<td><p>The post's modify token; required if the post doesn't belong to the requesting user.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Bool, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>Bool</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.login(username:password:completion:)">
<h3>
<code>login(username:password:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">login</span>(<span class="variable">username</span>: <span class="type">String</span>, <span class="variable">password</span>: <span class="type">String</span>, <span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">WFUser</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Logs the user in to their account on the WriteFreely instance.</p>
</div>
<div class="discussion">
<p>On successful login, the <code>WFClient</code>'s <code>user</code> property is set to the returned <code>WFUser</code> object; this allows
authenticated requests to be made without having to provide an access token.</p>
<p>It is otherwise not necessary to login the user if their access token is provided to the calling function.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>username</th>
<td><code class="type">String</code></td>
<td><p>The user's username.</p>
</td>
</tr>
<tr>
<th>password</th>
<td><code class="type">String</code></td>
<td><p>The user's password.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;WFUser, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>WFUser</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.logout(token:completion:)">
<h3>
<code>logout(token:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">logout</span>(<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>, <span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Bool</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Invalidates the user's access token.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The token to invalidate.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Bool, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>Bool</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.getuserdata(token:completion:)">
<h3>
<code>getUserData(token:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">getUserData</span>(<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>, <span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;<span class="type">Data</span>, <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Retrieves a user's basic data.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user to fetch.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;Data, Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>Data</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div role="article" class="function" id="wfclient.getusercollections(token:completion:)">
<h3>
<code>getUserCollections(token:completion:)</code>
</h3>
<div class="declaration">
<pre class="highlight"><code><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">getUserCollections</span>(<span class="variable">token</span>: <span class="type">String</span>? = <span class="keyword">nil</span>, <span class="variable">completion</span>: <span class="attribute">@</span><span class="attribute">escaping</span> (<span class="type">Result</span>&lt;[<span class="type">WFCollection</span>], <span class="type">Error</span>&gt;) -&gt; <span class="type">Void</span>) </code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Retrieves a user's collections.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>token</th>
<td><code class="type">String?</code></td>
<td><p>The access token for the user whose collections are to be retrieved.</p>
</td>
</tr>
<tr>
<th>completion</th>
<td><code class="type">@escaping (Result&lt;[WFCollection], Error&gt;) -&gt; Void</code></td>
<td><p>A handler for the <code>[WFCollection]</code> object returned on success, or <code>Error</code> on failure.</p>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2021-05-27T16:29:07-0400">May 27, 2021</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-beta.6</span>.
</p>
</footer>
</body>
</html>