Skip to content

Commit

Permalink
chore(merge): merge #211 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix authored May 18, 2021
2 parents fd35c28 + 8d32043 commit 70ab032
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
.library(name: "SwiftagramCrypto",
targets: ["SwiftagramCrypto"])],
// Package dependencies.
dependencies: [.package(url: "https://github.com/sbertix/ComposableRequest", .upToNextMinor(from: "5.0.9")),
dependencies: [.package(url: "https://github.com/sbertix/ComposableRequest", .upToNextMinor(from: "5.1.0")),
.package(url: "https://github.com/sbertix/SwCrypt.git", .upToNextMinor(from: "5.1.0"))],
// All targets.
targets: [.target(name: "Swiftagram",
Expand Down
15 changes: 11 additions & 4 deletions Sources/Swiftagram/Authentication/Authenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import Foundation

import ComposableStorage

/// A `typealias` for `ComposableStorage.UserDefaultsStorage`.
///
/// - note:
/// We prefer this to `import @_exported`, as we can't guarantee `@_exported`
/// to stick with future versions of **Swift**.
public typealias UserDefaultsStorage = ComposableStorage.UserDefaultsStorage

/// A `struct` defining an instance capable of
/// starting the authentication flow for a given user.
public struct Authenticator {
Expand Down Expand Up @@ -38,14 +45,14 @@ public extension Authenticator {

/// The default user defaults-backed `Authenticator`.
static var userDefaults: Authenticator {
userDefaults(.standard)
userDefaults(.init(userDefaults: .standard))
}

/// A user defaults-backed `Authenticator` with a specific `Client`.
///
/// - parameter userDefaults: A valid `UserDefaults`.
/// - parameter userDefaultsStorage: A valid `UserDefaultsStorage`.
/// - returns: A valid `Authenticator.`
static func userDefaults(_ userDefaults: UserDefaults) -> Authenticator {
.init(storage: UserDefaultsStorage(userDefaults: userDefaults))
static func userDefaults(_ userDefaultsStorage: UserDefaultsStorage<Secret>) -> Authenticator {
self.init(storage: userDefaultsStorage)
}
}
4 changes: 2 additions & 2 deletions Sources/Swiftagram/Endpoints/Archived/Endpoint+Archived.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public extension Endpoint.Group.Archived {
Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.feed
Expand All @@ -48,7 +48,7 @@ public extension Endpoint.Group.Archived {
Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.version1
Expand Down
4 changes: 2 additions & 2 deletions Sources/Swiftagram/Endpoints/Explore/Endpoint+Explore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public extension Endpoint.Group.Explore {
.publish(with: session)
.map(\.data)
.wrap()
.iterateFirst(stoppingAt: $0) { $0?.nextMaxId.string(converting: true) }
.iterateFirst(stoppingAt: $0) { $0.flatMap { $0.nextMaxId.string(converting: true) }.flatMap(Instruction.load) ?? .stop }
}
.eraseToAnyPublisher()
}
Expand All @@ -57,7 +57,7 @@ public extension Endpoint.Group.Explore {
.publish(with: session)
.map(\.data)
.wrap()
.iterateFirst(stoppingAt: $0) { $0?.nextMaxId.string(converting: true) }
.iterateFirst(stoppingAt: $0) { $0.flatMap { $0.nextMaxId.string(converting: true) }.flatMap(Instruction.load) ?? .stop }
}
.eraseToAnyPublisher()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Swiftagram/Endpoints/Media/Endpoint+Media.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public extension Endpoint.Group.Media {
Swift.Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.media(self)
Expand All @@ -163,7 +163,7 @@ public extension Endpoint.Group.Media {
Swift.Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.media(self)
Expand Down Expand Up @@ -203,7 +203,7 @@ public extension Endpoint.Group.Media {
Swift.Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.media(self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftagram/Endpoints/Posts/Endpoint+Posts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public extension Endpoint.Group.Posts {
Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.feed
Expand Down
27 changes: 14 additions & 13 deletions Sources/Swiftagram/Endpoints/Recent/Endpoint+Recent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public extension Endpoint.Group.Recent {
var posts: Endpoint.Paginated<Wrapper, RankedOffset<String?, String?>, Error> {
.init { secret, session, pages -> AnyPublisher<Wrapper, Error> in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages.count, offset: pages.offset.offset) {
Request.feed
Expand Down Expand Up @@ -82,20 +82,21 @@ public extension Endpoint.Group.Recent {
.iterateFirst(stoppingAt: $0) {
switch $0?.nextMaxId.string(converting: true) {
case .none:
return nil
return .stop
case "feed_recs_head_load":
return $0?.feedItems
.array()?
.last?
.endOfFeedDemarcator
.groupSet
.groups
.array()?
.first(where: { $0.id.string(converting: true) == "past_posts" })?
.nextMaxId
.string()
return ($0?.feedItems
.array()?
.last?
.endOfFeedDemarcator
.groupSet
.groups
.array()?
.first(where: { $0.id.string(converting: true) == "past_posts" })?
.nextMaxId
.string())
.flatMap(Instruction.load) ?? .stop
case let cursor?:
return cursor
return .load(cursor)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Swiftagram/Endpoints/User/Endpoint+User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public extension Endpoint.Group.User {
Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.version1
Expand Down Expand Up @@ -278,7 +278,7 @@ fileprivate extension Endpoint.Group.User {
matching query: String?) -> Endpoint.Paginated<Swiftagram.User.Collection, RankedOffset<String?, String?>, Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.friendship(self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftagram/Endpoints/User/Endpoint+Users.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public extension Endpoint {
Error> {
.init { secret, session, pages in
// Persist the rank token.
let rank = pages.rank ?? String(Int.random(in: 1_000..<10_000))
let rank = pages.rank ?? UUID().uuidString
// Prepare the actual pager.
return Pager(pages) {
Request.users
Expand Down
6 changes: 6 additions & 0 deletions Sources/Swiftagram/Models/Specialized/Conversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public struct Conversation: Wrapped {
public extension Conversation {
/// A `struct` representing a `Conversation` single response.
struct Unit: Specialized, Paginatable {
/// The associated offset.
public typealias Offset = String?

/// The underlying `Response`.
public var wrapper: () -> Wrapper

Expand All @@ -60,6 +63,9 @@ public extension Conversation {

/// A `struct` representing a `Conversation` collection.
struct Collection: Specialized, Paginatable {
/// The associated offset.
public typealias Offset = String?

/// The underlying `Response`.
public var wrapper: () -> Wrapper

Expand Down
6 changes: 6 additions & 0 deletions Sources/Swiftagram/Models/Specialized/SavedCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public struct SavedCollection: Wrapped {
public extension SavedCollection {
/// A `struct` defining a collection of `SavedCollection`.
struct Collection: Specialized, Paginatable {
/// The associated offset.
public typealias Offset = String?

/// The underlying `Response`.
public var wrapper: () -> Wrapper

Expand All @@ -63,6 +66,9 @@ public extension SavedCollection {

/// A `struct` defining a single `SavedCollection` response.
struct Unit: Specialized, Paginatable {
/// The associated offset.
public typealias Offset = String?

/// The underlying `Response`.
public var wrapper: () -> Wrapper

Expand Down
3 changes: 3 additions & 0 deletions Sources/Swiftagram/Models/Specialized/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public extension Section {

/// A `struct` defining a collection of `Section`s.
struct Collection: Specialized, Paginatable {
/// The associated offset.
public typealias Offset = Section.Offset?

/// The underlying `Response`.
public var wrapper: () -> Wrapper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Foundation

import ComposableStorageCrypto

/// A `typealias` for `ComposableStorageCrypto.Keychain`.
/// A `typealias` for `ComposableStorageCrypto.KeychainStorage`.
///
/// - note:
/// We prefer this to `import @_exported`, as we can't guarantee `@_exported`
/// to stick with future versions of **Swift**.
public typealias Keychain = ComposableStorageCrypto.Keychain
public typealias KeychainStorage = ComposableStorageCrypto.KeychainStorage

public extension Authenticator {
/// The default keychain-backed `Authenticator`.
Expand All @@ -24,13 +24,9 @@ public extension Authenticator {

/// A keychain-backed `Authenticator`.
///
/// - parameter keychain: A valid `Keychain`. Defaults to `.init()`.
/// - parameter keychain: A valid `KeychainStorage`.
/// - returns: A valid `Authenticator.`
static func keychain(_ keychain: Keychain = .init()) -> Authenticator {
.init(storage: KeychainStorage(service: keychain.service,
group: keychain.group,
accessibility: keychain.accessibility,
authentication: keychain.authentication,
isSynchronizable: keychain.isSynchronizable))
static func keychain(_ keychainStorage: KeychainStorage<Secret>) -> Authenticator {
self.init(storage: keychainStorage)
}
}
Loading

0 comments on commit 70ab032

Please sign in to comment.