Skip to content

Commit 52ea441

Browse files
Merge pull request #19 from writeas/add-local-WFUser-initializer
Adds a simple memberwise-ish initializer for stored token/username
2 parents 6485414 + fe873dc commit 52ea441

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed

Sources/WriteFreely/WFUser.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ extension WFUser: Decodable {
2323
case createdDate = "created"
2424
}
2525

26+
/// Creates a minimum `WFUser` object from a stored token.
27+
///
28+
/// Use this when the client has already logged in a user and only needs to reconstruct the type from saved properties.
29+
///
30+
/// - Parameter token: The user's access token
31+
/// - Parameter username: The user's username (optional)
32+
public init(token: String, username: String?) {
33+
self.token = token
34+
if let username = username {
35+
self.username = username
36+
}
37+
}
38+
2639
/// Creates a `WFUser` object from the server response.
2740
///
2841
/// Primarily used by the `WFClient` to create a `WFUser` object from the JSON returned by the server.

docs/Home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
- [WFClient](/WFClient)
44
- [WFCollection](/WFCollection)
5+
- [WFError](/WFError)
56
- [WFPost](/WFPost)
67
- [WFUser](/WFUser)

docs/WFError.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# WFError
2+
3+
``` swift
4+
public enum WFError
5+
```
6+
7+
## Inheritance
8+
9+
`Error`, `Int`
10+
11+
## Enumeration Cases
12+
13+
### `badRequest`
14+
15+
``` swift
16+
case badRequest
17+
```
18+
19+
### `unauthorized`
20+
21+
``` swift
22+
case unauthorized
23+
```
24+
25+
### `forbidden`
26+
27+
``` swift
28+
case forbidden
29+
```
30+
31+
### `notFound`
32+
33+
``` swift
34+
case notFound
35+
```
36+
37+
### `methodNotAllowed`
38+
39+
``` swift
40+
case methodNotAllowed
41+
```
42+
43+
### `gone`
44+
45+
``` swift
46+
case gone
47+
```
48+
49+
### `preconditionFailed`
50+
51+
``` swift
52+
case preconditionFailed
53+
```
54+
55+
### `tooManyRequests`
56+
57+
``` swift
58+
case tooManyRequests
59+
```
60+
61+
### `internalServerError`
62+
63+
``` swift
64+
case internalServerError
65+
```
66+
67+
### `badGateway`
68+
69+
``` swift
70+
case badGateway
71+
```
72+
73+
### `serviceUnavailable`
74+
75+
``` swift
76+
case serviceUnavailable
77+
```

docs/WFUser.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ public struct WFUser
1010

1111
## Initializers
1212

13+
### `init(token:username:)`
14+
15+
Creates a minimum `WFUser` object from a stored token.
16+
17+
``` swift
18+
public init(token: String, username: String?)
19+
```
20+
21+
Use this when the client has already logged in a user and only needs to reconstruct the type from saved properties.
22+
23+
#### Parameters
24+
25+
- token: - token: The user's access token
26+
- username: - username: The user's username (optional)
27+
1328
### `init(from:)`
1429

1530
Creates a `WFUser` object from the server response.

docs/_Footer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Generated at 2020-08-17T10:42:50-0400 using [swift-doc](https://github.com/SwiftDocOrg/swift-doc) 1.0.0-beta.3.
1+
Generated at 2020-08-31T10:27:33-0400 using [swift-doc](https://github.com/SwiftDocOrg/swift-doc) 1.0.0-beta.3.

docs/_Sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
- [WFClient](/WFClient)
55
- [WFCollection](/WFCollection)
6+
- [WFError](/WFError)
67
- [WFPost](/WFPost)
78
- [WFUser](/WFUser)
89

0 commit comments

Comments
 (0)