-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add full support for iOS 13, tvOS 13, macOS 11, and watchOS 6
- Loading branch information
1 parent
ad3e1d8
commit 8be869a
Showing
5 changed files
with
379 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Rudrank Riyam on 03/10/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension QuoteKit { | ||
static func authorImage(with slug: String, size: Int = 700) -> URL { | ||
QuotableEndpoint(.authorProfile(size, slug), host: .images).url | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func author(id: String) async throws -> Author? { | ||
try await execute(with: QuotableEndpoint(.author(id))) | ||
} | ||
|
||
static func author(id: String, completion: @escaping (Result<Author?, Error>) -> ()) { | ||
execute(with: QuotableEndpoint(.author(id)), completion: completion) | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func authors(slugs: [String]? = nil, | ||
sortBy: AuthorsAndTagsSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
limit: Int = 20, | ||
page: Int = 1) async throws -> Authors? { | ||
|
||
let queryItems = authorsParameters(slugs: slugs, sortBy: sortBy, order: order, limit: limit, page: page) | ||
|
||
return try await execute(with: QuotableEndpoint(.authors, queryItems: queryItems)) | ||
} | ||
|
||
static func authors(slugs: [String]? = nil, | ||
sortBy: AuthorsAndTagsSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
limit: Int = 20, | ||
page: Int = 1, | ||
completion: @escaping (Result<Authors?, Error>) -> ()) { | ||
|
||
let queryItems = authorsParameters(slugs: slugs, sortBy: sortBy, order: order, limit: limit, page: page) | ||
|
||
return execute(with: QuotableEndpoint(.authors, queryItems: queryItems), completion: completion) | ||
} | ||
|
||
private static func authorsParameters(slugs: [String]? = nil, | ||
sortBy: AuthorsAndTagsSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
limit: Int = 20, | ||
page: Int = 1) -> [URLQueryItem] { | ||
|
||
var queryItems: [URLQueryItem] = [] | ||
|
||
queryItems.append(.limit(limit)) | ||
queryItems.append(.page(page)) | ||
|
||
if let slugs = slugs { | ||
queryItems.append(.slugs(slugs)) | ||
} | ||
|
||
if let sortBy = sortBy { | ||
queryItems.append(.sortBy(sortBy)) | ||
} | ||
|
||
if let order = order { | ||
queryItems.append(.order(order)) | ||
} | ||
|
||
return queryItems | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Rudrank Riyam on 03/10/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension QuoteKit { | ||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func quote(id: String) async throws -> Quote? { | ||
try await execute(with: QuotableEndpoint(.quote(id))) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func quote(id: String, completion: @escaping (Result<Quote?, Error>) -> ()) { | ||
execute(with: QuotableEndpoint(.quote(id)), completion: completion) | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func quotes(minLength: Int? = nil, | ||
maxLength: Int? = nil, | ||
tags: [String]? = nil, | ||
type: URLQueryItemListType = .all, | ||
authors: [String]? = nil, | ||
sortBy: QuotesSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
limit: Int = 20, | ||
page: Int = 1) async throws -> Quotes? { | ||
|
||
let queryItems = quotesParameter(minLength: minLength, | ||
maxLength: maxLength, | ||
tags: tags, | ||
type: type, | ||
authors: authors, | ||
sortBy: sortBy, | ||
order: order, | ||
limit: limit, | ||
page: page) | ||
|
||
return try await execute(with: QuotableEndpoint(.quotes, queryItems: queryItems)) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func quotes(minLength: Int? = nil, | ||
maxLength: Int? = nil, | ||
tags: [String]? = nil, | ||
type: URLQueryItemListType = .all, | ||
authors: [String]? = nil, | ||
sortBy: QuotesSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
limit: Int = 20, | ||
page: Int = 1, | ||
completion: @escaping (Result<Quotes?, Error>) -> ()) { | ||
|
||
let queryItems = quotesParameter(minLength: minLength, | ||
maxLength: maxLength, | ||
tags: tags, | ||
type: type, | ||
authors: authors, | ||
sortBy: sortBy, | ||
order: order, | ||
limit: limit, | ||
page: page) | ||
|
||
return execute(with: QuotableEndpoint(.quotes, queryItems: queryItems), completion: completion) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static private func quotesParameter(minLength: Int? = nil, | ||
maxLength: Int? = nil, | ||
tags: [String]? = nil, | ||
type: URLQueryItemListType = .all, | ||
authors: [String]? = nil, | ||
sortBy: QuotesSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
limit: Int = 20, | ||
page: Int = 1) -> [URLQueryItem] { | ||
|
||
var queryItems: [URLQueryItem] = [] | ||
|
||
queryItems.append(.limit(limit)) | ||
queryItems.append(.page(page)) | ||
|
||
if let minLength = minLength { | ||
queryItems.append(.minLength(minLength)) | ||
} | ||
|
||
if let maxLength = maxLength { | ||
queryItems.append(.maxLength(maxLength)) | ||
} | ||
|
||
if let tags = tags { | ||
queryItems.append(.tags(tags, type)) | ||
} | ||
|
||
if let authors = authors { | ||
queryItems.append(.authors(authors)) | ||
} | ||
|
||
if let sortBy = sortBy { | ||
queryItems.append(.sortQuotesBy(sortBy)) | ||
} | ||
|
||
if let order = order { | ||
queryItems.append(.order(order)) | ||
} | ||
|
||
return queryItems | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func quotes() async throws -> Quotes? { | ||
try await execute(with: QuotableEndpoint(.quotes)) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func quotes(completion: @escaping (Result<Quotes?, Error>) -> ()) { | ||
execute(with: QuotableEndpoint(.quotes), completion: completion) | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func randomQuote(minLength: Int? = nil, | ||
maxLength: Int? = nil, | ||
tags: [String]? = nil, | ||
type: URLQueryItemListType = .all, | ||
authors: [String]? = nil) async throws -> Quote? { | ||
|
||
let queryItems = randomQuoteParameters(minLength: minLength, | ||
maxLength: maxLength, | ||
tags: tags, | ||
type: type, | ||
authors: authors) | ||
|
||
return try await execute(with: QuotableEndpoint(.randomQuote, queryItems: queryItems)) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func randomQuote(minLength: Int? = nil, | ||
maxLength: Int? = nil, | ||
tags: [String]? = nil, | ||
type: URLQueryItemListType = .all, | ||
authors: [String]? = nil, | ||
completion: @escaping (Result<Quote?, Error>) -> ()) { | ||
|
||
let queryItems = randomQuoteParameters(minLength: minLength, | ||
maxLength: maxLength, | ||
tags: tags, | ||
type: type, | ||
authors: authors) | ||
|
||
return execute(with: QuotableEndpoint(.randomQuote, queryItems: queryItems), completion: completion) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static private func randomQuoteParameters(minLength: Int? = nil, | ||
maxLength: Int? = nil, | ||
tags: [String]? = nil, | ||
type: URLQueryItemListType = .all, | ||
authors: [String]? = nil) -> [URLQueryItem] { | ||
|
||
var queryItems: [URLQueryItem] = [] | ||
|
||
if let minLength = minLength { | ||
queryItems.append(.minLength(minLength)) | ||
} | ||
|
||
if let maxLength = maxLength { | ||
queryItems.append(.maxLength(maxLength)) | ||
} | ||
|
||
if let tags = tags { | ||
queryItems.append(.tags(tags, type)) | ||
} | ||
|
||
if let authors = authors { | ||
queryItems.append(.authors(authors)) | ||
} | ||
|
||
return queryItems | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Rudrank Riyam on 03/10/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension QuoteKit { | ||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func searchQuotes(for query: String, | ||
limit: Int = 20, | ||
page: Int = 1) async throws -> Quotes? { | ||
try await search(path: .searchQuotes, query: query, limit: limit, page: page) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func searchQuotes(for query: String, | ||
limit: Int = 20, | ||
page: Int = 1, | ||
completion: @escaping (Result<Quotes?, Error>) -> ()) { | ||
search(path: .searchQuotes, query: query, completion: completion) | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func searchAuthors(for query: String, | ||
limit: Int = 20, | ||
page: Int = 1) async throws -> Authors? { | ||
try await search(path: .searchAuthors, query: query, limit: limit, page: page) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func searchAuthors(for query: String, | ||
limit: Int = 20, | ||
page: Int = 1, | ||
completion: @escaping (Result<Authors?, Error>) -> ()) { | ||
search(path: .searchAuthors, query: query, completion: completion) | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
private static func search<Model: Decodable>(path: QuotableEndpointPath, | ||
query: String, | ||
limit: Int = 20, | ||
page: Int = 1) async throws -> Model { | ||
|
||
let queryItems = searchParameters(query: query, limit: limit, page: page) | ||
|
||
return try await execute(with: QuotableEndpoint(path, queryItems: queryItems)) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
private static func search<Model: Decodable>(path: QuotableEndpointPath, | ||
query: String, | ||
limit: Int = 20, | ||
page: Int = 1, | ||
completion: @escaping (Result<Model, Error>) -> ()) { | ||
|
||
let queryItems = searchParameters(query: query, limit: limit, page: page) | ||
|
||
return execute(with: QuotableEndpoint(path, queryItems: queryItems), completion: completion) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
private static func searchParameters(query: String, | ||
limit: Int = 20, | ||
page: Int = 1) -> [URLQueryItem] { | ||
var queryItems: [URLQueryItem] = [] | ||
|
||
queryItems.append(.search(query)) | ||
queryItems.append(.limit(limit)) | ||
queryItems.append(.page(page)) | ||
|
||
return queryItems | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Rudrank Riyam on 03/10/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension QuoteKit { | ||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
static func tags(sortBy: AuthorsAndTagsSortType? = nil, | ||
order: QuotableListOrder? = nil) async throws -> Tags? { | ||
|
||
let queryItems = tagsParameters(sortBy: sortBy, order: order) | ||
|
||
return try await execute(with: QuotableEndpoint(.tags, queryItems: queryItems)) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
static func tags(sortBy: AuthorsAndTagsSortType? = nil, | ||
order: QuotableListOrder? = nil, | ||
completion: @escaping (Result<Tags?, Error>) -> ()) { | ||
|
||
let queryItems = tagsParameters(sortBy: sortBy, order: order) | ||
|
||
return execute(with: QuotableEndpoint(.tags, queryItems: queryItems), completion: completion) | ||
} | ||
|
||
@available(iOS 13.0, macOS 11.0, tvOS 13.0, watchOS 6.0, *) | ||
private static func tagsParameters(sortBy: AuthorsAndTagsSortType? = nil, | ||
order: QuotableListOrder? = nil) -> [URLQueryItem] { | ||
|
||
var queryItems: [URLQueryItem] = [] | ||
|
||
if let sortBy = sortBy { | ||
queryItems.append(.sortBy(sortBy)) | ||
} | ||
|
||
if let order = order { | ||
queryItems.append(.order(order)) | ||
} | ||
|
||
return queryItems | ||
} | ||
} |
Oops, something went wrong.