From 760c12f3ad18e37157db38db70fad16bd72384f2 Mon Sep 17 00:00:00 2001 From: sbertix Date: Sat, 15 May 2021 19:46:01 +0200 Subject: [PATCH 1/2] feat(models): add account type to `User` `access` --- .../Swiftagram/Models/Specialized/User.swift | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Sources/Swiftagram/Models/Specialized/User.swift b/Sources/Swiftagram/Models/Specialized/User.swift index 18ad85ac..8cddc3a7 100644 --- a/Sources/Swiftagram/Models/Specialized/User.swift +++ b/Sources/Swiftagram/Models/Specialized/User.swift @@ -25,7 +25,12 @@ public struct User: Wrapped { public static let `private`: Access = .init(rawValue: 1 << 0) /// A verified account. public static let verified: Access = .init(rawValue: 1 << 1) + /// A business account. + public static let business: Access = .init(rawValue: 1 << 2) + /// A creator account. + public static let creator: Access = .init(rawValue: 1 << 3) } + /// A `struct` representing a profile's `Counter`s. public struct Counter: Hashable, Codable { /// Posts. @@ -55,6 +60,8 @@ public struct User: Wrapped { public var name: String? { self["fullName"].string() } /// The biography. public var biography: String? { self["biography"].string() } + /// The category. + public var category: String? { self["category"].string() } /// A lower quality avatar. public var thumbnail: URL? { self["profilePicUrl"].url() } /// An higher quality avatar. @@ -72,18 +79,16 @@ public struct User: Wrapped { public var access: Access? { let isPrivate = self["isPrivate"].bool() let isVerified = self["isVerified"].bool() + let isBusiness = self["isBusiness"].bool() + let account = self["accountType"].int() // Deal with condition. - if isPrivate == true && isVerified == true { - return [.private, .verified] - } else if isPrivate == true { - return .private - } else if isVerified == true { - return .verified - } else if isPrivate == nil && isVerified == nil { - return nil - } else { - return [] - } + guard isPrivate != nil || isVerified != nil || isBusiness != nil || account != nil else { return nil } + var access: Access = [] + if isPrivate ?? false { access.formUnion(.private) } + if isVerified ?? false { access.formUnion(.verified) } + if (isBusiness ?? false) || account == 2 { access.formUnion(.business) } + if account == 3 { access.formUnion(.creator) } + return access } /// An optional friendship status. From b2f37d1f911507022290c0c6454887c278beaf3d Mon Sep 17 00:00:00 2001 From: sbertix Date: Sat, 15 May 2021 19:48:06 +0200 Subject: [PATCH 2/2] chore(docs): update docs reference in `README.md` --- docs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index ef3a43db..34ac717b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -63,17 +63,17 @@ Furthermore, with the integration of the **Swift Package Manager** in **Xcode 11
Targets

-- **Swiftagram** depends on [**ComposableRequest**](https://github.com/sbertix/ComposableRequest), an HTTP client originally integrated in **Swiftagram**.\ +- [**Swiftagram**](https://sbertix.github.io/Swiftagram/Swiftagram) depends on [**ComposableRequest**](https://github.com/sbertix/ComposableRequest), an HTTP client originally integrated in **Swiftagram**.\ It supports [`Combine`](https://developer.apple.com/documentation/combine) `Publisher`s and caching `Secret`s, through **ComposableStorage**, out-of-the-box. -- **SwiftagramCrypto**, depending on [**Swiftchain**](https//github.com/sbertix/Swiftchain) and a fork of [**SwCrypt**](https://github.com/sbertix/SwCrypt), can be imported together with **Swiftagram** to extend its functionality, accessing the safer `KeychainStorage` and encrypted `Endpoint`s (e.g. `Endpoint.Friendship.follow`, `Endpoint.Friendship.unfollow`). +- [**SwiftagramCrypto**](https://sbertix.github.io/Swiftagram/SwiftagramCrypto), depending on [**Swiftchain**](https//github.com/sbertix/Swiftchain) and a fork of [**SwCrypt**](https://github.com/sbertix/SwCrypt), can be imported together with **Swiftagram** to extend its functionality, accessing the safer `KeychainStorage` and encrypted `Endpoint`s (e.g. `Endpoint.Friendship.follow`, `Endpoint.Friendship.unfollow`).

## Usage -Check out our [Examples](Examples) or visit the (_auto-generated_) [Documentation](https://sbertix.github.io/Swiftagram) to learn about use cases. +Check out our [Examples](Examples) or visit the (_auto-generated_) documentation for [**Swiftagram**](https://sbertix.github.io/Swiftagram/Swiftagram) and [**SwiftagramCrypto**](https://sbertix.github.io/Swiftagram/SwiftagramCrypto) to learn about use cases. ### Authentication Authentication is provided through conformance to the `Authenticator` protocol, which, on success, returns a `Secret` containing all the cookies needed to sign an `Endpoint`'s request.