Skip to content

Commit

Permalink
chore(merge): merge #207 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix authored May 15, 2021
2 parents 4492b4a + b2f37d1 commit fd35c28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 16 additions & 11 deletions Sources/Swiftagram/Models/Specialized/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ Furthermore, with the integration of the **Swift Package Manager** in **Xcode 11
<details><summary><strong>Targets</strong></summary>
<p>

- **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`).
</p>
</details>

<p />

## 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.
Expand Down

0 comments on commit fd35c28

Please sign in to comment.