The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey.

Overview

QuoteKit Logo

QuoteKit

Twitter Follow

The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey. It uses the latest async/await syntax for easy access and contains all the APIs like fetching a random quote, all quotes, authors, tags and searching quotes and authors.

Requirements

As it uses the async/await feature of Swift 5.5, the platforms currently supported are iOS 15.0+, macOS 12.0+, watchOS 8.0+ and tvOS 15.0+. There's a PR merged in Swift language related to back deployment, and the framework will be updated accordingly to support the older OSes.

Edit: While waiting and hoping for the backport to happen, the framework now supports iOS 13.0+, macOS 11.0+, watchOS 6.0+ and tvOS 13.0+

Installation

To add QuoteKit in your project, the best way is via the Swift Package Manager.

dependencies: [
    .package(url: "https://github.com/rudrankriyam/QuoteKit.git")
]

Usage

The struct QuoteKit contains static methods you can call for fetching the revelant data. For example, to get the list of quotes -

do {
    var quotes: Quotes?
    quotes = try await QuoteKit.quotes()
} catch {
    print(error)
}

The examples given below are similar to the ones in Quotable's README.

Random Quote

Returns a single random Quote object from the /random API.

var randomQuote: Quote?
randomQuote = try await QuoteKit.randomQuote()

You can customise the request by adding query parameters like minimum and maximum length of the quote or the tag associated with it. You can also get a random quote by a specific author(s).

Few examples:

Random Quote with tags "technology" AND "famous-quotes" -

try await QuoteKit.randomQuote(tags: [.technology, .famousQuotes], type: .all)

Random Quote with tags "History" OR "Civil Rights" -

try await QuoteKit.randomQuote(tags: [.history, .civilRights], type: .either)

Random Quote with a maximum length of 50 characters -

try await QuoteKit.randomQuote(maxLength: 150)

Random Quote with a length between 100 and 140 characters -

try await QuoteKit.randomQuote(minLength: 100, maxLength: 140)

Random Quote by the author "Aesop" and "Stephen Hawking" -

try await QuoteKit.randomQuote(authors: ["aesop", "stephen-hawking"])

List Quotes

Returns the Quotes object based on the given queries from the /quotes API. By default, the list contains 20 Quote in one page.

var quotes: Quotes?
quotes = try await QuoteKit.quotes()

Few examples:

Get all quotes with a maximum length of 50 characters -

try await QuoteKit.quotes(maxLength: 150)

Get all quotes with a length between 100 and 140 characters -

try await QuoteKit.quotes(minLength: 100, maxLength: 140)

Get the first page of quotes, with 20 results per page -

try await QuoteKit.quotes(page: 1)

Get the second page of quotes, with 20 results per page, with a limit of 10 quotes -

try await QuoteKit.quotes(limit: 10, page: 2)

Get all quotes with the tags love OR happiness -

try await QuoteKit.quotes(tags: [.love, .happiness], type: .either)

Get all quotes with the tags technology AND famous-quotes -

try await QuoteKit.quotes(tags: [.technology, .famousQuotes], type: .all)

Get all quotes by author, using the author's slug -

try await QuoteKit.quotes(authors: ["albert-einstein"])

Get all quotes sorted by author -

try await QuoteKit.quotes(sortBy: .author)

Get all quotes sorted by content, in descending order -

try await QuoteKit.quotes(sortBy: .content, order: .descending)

Quote By ID

If there is one, return a single Quote object for the given id from the /quotes/:id API.

var quote: Quote?
quote = try await QuoteKit.quote(id: "2xpHvSOQMD")

List Authors

Returns the Authors object matching the given queries from the /authors API. By default, the list contains 20 Author in one page. You can filter multiple authors by providing their slugs in the query parameter.

var authors: Authors?
authors = try await QuoteKit.authors()

Few examples:

Get the first page of authors, with 20 results per page -

try await QuoteKit.authors(page: 1)

Get the second page of authors, with 20 results per page, with a limit of 10 authors -

try await QuoteKit.authors(limit: 10, page: 2)

Get all authors, sorted alphabetically by name -

try await QuoteKit.authors(sortBy: .name)

Get all authors, sorted by number of quotes in descending order -

try await QuoteKit.authors(sortBy: .quoteCount, order: .descending)

Get a single author by slug -

try await QuoteKit.authors(slugs: ["albert-einstein"])

Get multiple authors by slug -

try await QuoteKit.authors(slugs: ["albert-einstein", "abraham-lincoln"])

Author By ID

If there is one, return a single Author object for the given id from the /authors/:id API.

var author: Author?
author = try await QuoteKit.author(id: "XYxYtSeixS-o")

Author Profile Image URL

Returns the image URL for given author slug. You can specify the image size as well. The default image size is 700x700.

var authorImageURL: URL?
authorImageURL = QuoteKit.authorProfile(size: 1000, slug: "aesop")

List Tags

Returns the Tags object containing the list of all tags from the /tags API. You can sort it and order the sorted results.

var tags: Tags?
tags = try await QuoteKit.tags()

Get all tags, sorted alphabetically by name -

try await QuoteKit.tags(sortBy: .name)

Get all tags, sorted by number of quotes in descending order -

try await QuoteKit.tags(sortBy: .quoteCount, order: .descending)

Search Quotes

Returns the Quotes object based on the search query from the /search/quotes API. By default, the list contains 20 Quote in one page.

var quotes: Quotes?
quotes = try await QuoteKit.searchQuotes(for: "love")

Get the first page of searched quotes, with 20 results per page -

try await QuoteKit.searchQuotes(for: "love", page: 1)

Get the second page of searched quotes, with 20 results per page, with a limit of 10 quotes -

try await QuoteKit.searchQuotes(for: "love", limit: 10, page: 2)

Search Authors

Returns the Authors object based on the search query from the /search/authors API. By default, the list contains 20 Author in one page.

var quotes: Quotes?
quotes = try await QuoteKit.searchAuthors(for: "kalam")

Get the first page of searched authors, with 20 results per page -

try await QuoteKit.searchAuthors(for: "kalam", page: 1)

Get the second page of searched authors, with 20 results per page, with a limit of 10 authors -

try await QuoteKit.searchAuthors(for: "kalam", limit: 10, page: 2)

Data Models

There are many different data models for using this framework.

  • Quote

The object represents a single quote. You can get the content of the quote using the content variable. The tags is an array of the relevant tag associated with the quote. To get the number of characters in the quote, use length.

struct Quote: Decodable, Identifiable {
    var id: String
    var tags: [String]
    var content: String
    var author: String
    var authorSlug: String
    var length: Int
    var dateAdded: String
    var dateModified: String
    
    enum CodingKeys: String, CodingKey {
        case id = "_id"
        case tags, content, author, authorSlug, length, dateAdded, dateModified
    }
}
  • Author

The object represents a single author. You can get the link to their Wikipedia page or their official website using link. bio contains a brief, one paragraph about the author. Use description instead to get a shorter description of the person's occupation or what they're known for. quotes contains an array of the author's quote.

Bool { lhs.id == rhs.id } } ">
struct Author: Decodable, Identifiable {
    var id: String
    var link: String
    var bio: String
    var description: String
    var name: String
    var quoteCount: Int
    var slug: String
    var dateAdded: String
    var dateModified: String
    var quotes: [Quote]?
    
    enum CodingKeys: String, CodingKey {
        case link, bio, description
        case id = "_id"
        case name, quoteCount, slug
        case dateAdded, dateModified
        case quotes
    }
}

extension Author: Equatable {
    static func ==(lhs: Author, rhs: Author) -> Bool {
        lhs.id == rhs.id
    }
}
You might also like...
Project 03 I created for
Project 03 I created for "iOS & Swift - The Complete iOS App Development Bootcamp"

Dicee This is the third project I created for "iOS & Swift - The Complete iOS App Development Bootcamp" Our Goal The objective of this tutorial is to

Spiro - Swift Playgrounds 4 app created on the iPad
Spiro - Swift Playgrounds 4 app created on the iPad

Spiro Swift Playgrounds 4 app created on the iPad^. ^ Xcode also used as explain

🛠 A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern.
🛠 A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern.

Model-View-Presenter template A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern. This

A movie api created using Vapor, Fluent (ORM) and Postgres

A movie api created using Vapor, Fluent (ORM) and Postgres

This is a fully functioning Guess The Flag game I created as part of my 100 days of SwiftUI course with Paul Hudson.
This is a fully functioning Guess The Flag game I created as part of my 100 days of SwiftUI course with Paul Hudson.

GuessTheFlag This is a fully functioning Guess The Flag game that was a part of my 100 days of SwiftUI course with Paul Hudson. In this app my challen

🏀 iOS and Android NBA app created with React Native
🏀 iOS and Android NBA app created with React Native

Swish An iOS and Android NBA app created with React Native. If you would like to request a feature, find a bug, have a question, or would like to leav

Are you sure the chemical compounds of your daily use are 100% safe? Use Chem-Aware, identify them right now!
Are you sure the chemical compounds of your daily use are 100% safe? Use Chem-Aware, identify them right now!

View Project On Devpost: Built With: PubChem's REST API How To Install Chem Aware: Prerequiste: Latest Version of Xcode and Simulators installed The a

How to use swiftlint to identify unused code or unused imports in a Swift codebase

Swift compilation database This repository demonstrates how to use swiftlint to identify unused code or unused imports in a Swift codebase. How to run

Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.
Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and Andres

Releases(1.2.0)
  • 1.2.0(Oct 31, 2021)

    Hi there! This update contains backward compatibility of Swift's new concurrency system! In simple terms, you can use async/await syntax targeting iOS 13, macOS Catalina, watchOS 6, and tvOS 13!

    Do note you have to use Xcode 13.2+

    Happy coding!

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Oct 3, 2021)

    While we wait and hope that the new async/await is backported to support the older version of iOS and other platforms, I modified QuoteKit to support completion handlers so that you can use it for iOS 13, macOS 11, tvOS 13 and watchOS 6!

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Sep 25, 2021)

    This release contains more tests and all the APIs for you to create wonderful quote apps! It is currently being used in my app "Quoting" that I plan to release soon for iOS 15!

    Enjoy!

    Source code(tar.gz)
    Source code(zip)
  • 0.1.2(Sep 1, 2021)

  • 0.1.1(Aug 30, 2021)

    The RRQuotableKit is a framework to use the free APIs provided by Quotable. It uses the latest async/await syntax for easy access and contains all the APIs like fetching a random quote, all quotes, authors and tags.

    Source code(tar.gz)
    Source code(zip)
Owner
rryam
rryam
This is a Swift Package bundling different Train APIs into one simple Swift interface.

This is a Swift Package bundling different Train APIs into one simple Swift interface.

ICE Buddy 8 Jul 5, 2022
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Dec 31, 2022
Package that extends Combine with some useful APIs

CombineExpanded Package that extends Combine with some useful APIs. New API: then shareReplay Future.deferred then Wait for completion of self, then f

Cogniteq 1 Nov 24, 2021
You can monitor your APIs and websites on your menubar. Gives you status code 🎉 Cool & good

Hope not. Monitor your APIs and websites on your menubar. For macOS. Right now! YyeeeHav!

Steven J. Selcuk 10 Nov 29, 2022
Free Monads in swift

This repo is based on my blog post on Free Monads in swift.

null 0 Nov 15, 2021
A free and open source xkcd comic reader for iOS.

A free, ad-free, open-source, native, and universal xkcd.com reader for iOS. Download it from the app store now! Architecture AFNetworking for network

Mike 249 Dec 12, 2022
Tutorials from sparrowcode.io website. You can add new, translate or fix typos. Also you can add your apps from App Store for free.

Tutorials from sparrowcode.io website. You can add new, translate or fix typos. Also you can add your apps from App Store for free.

Sparrow Code 31 Jan 3, 2023
Tutorials from sparrowcode.io website. You can add new, translate or fix typos. Also you can add your apps from App Store for free.

Страницы доступны на sparrowcode.io/en & sparrowcode.io/ru Как добавить свое приложение Добавьте элемент в json /ru/apps/apps.json. Если ваше приложен

Sparrow Code 30 Nov 25, 2022
Free and open source manga reader for iOS and iPadOS.

Aidoku A free and open source manga reading application for iOS and iPadOS. Features Ad free Robust WASM source system Online reading through external

null 421 Jan 2, 2023
ESP source code for Free Fire (iOS jailbreak)

ESP FreeFire ESP source code for Free Fire (iOS jailbreak, Free Fire version: 1.93.1). This source is for learning purpose only, please do not use it

Huy Nguyen 11 Dec 25, 2022