// // Pagination.swift // Pachyderm // // Created by Shadowfacts on 9/9/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import Foundation public struct Pagination { public let older: RequestRange? public let newer: RequestRange? } extension Pagination { init(string: String) { let links = string.components(separatedBy: ",").compactMap(Item.init) self.older = links.first(where: { $0.kind == .next })?.range self.newer = links.first(where: { $0.kind == .prev })?.range } } extension Pagination { struct Item { let kind: Kind let id: String let limit: Int? var range: RequestRange { switch kind { case .next: return .after(id: id, count: limit) case .prev: return .before(id: id, count: limit) } } init?(string: String) { let segments = string.components(separatedBy: .whitespaces).filter { !$0.isEmpty }.joined().components(separatedBy: ";") let url = segments.first.flatMap { str in String(str[str.index(after: str.startIndex)..