Questrade API written in Swift

Overview

QuestradeAPI

Getting Started

The QuestAPI is made up of two main concepts:

  1. ResponseProviders
  2. API

ResponseProviders

The job of the provider is to return data to API for a given request. QuestradeAPI comes with two providers, AuthProvider and FakeDataProvider. You can conform to ResponseProvider and build your own providers if you have extra custom behaviour that you need. To use a given provider just pass the provider to the initilization of API.

let api = API(provider: CustomProvider())

AuthProvider

The AuthProvider class requires a class or struct that conforms to Storable. The purpose of AuthProvider is for authorizing and deauthorizing requests for the API.

let auth = AuthProvider(tokenStore: TokenStore())

Token Store

The Storable protocol is for you to conform to so that you can choose how to securly store the api token.

class TokenStore: Storable {
    // func get() -> Data
    // func set(_ data: Data)
    // func delete()
}

FakeDataProvider

A ResponseProvider that loads fake responses from json files and supplies them as responses. This provider is used by default for API if none is provided on init.

API

The API class can be initilized with or without an authorizer(AuthProvider). If no authorizor is supplied on initilization, a default of FakeDataProvider will be used.

let api = API(provider: auth)

api.accounts { res in
    switch res {
    case .failure(let error): // log error
    case .success(let actResponse):
        let accounts = actResponse.accounts
    }
}

Full Init Code

class MyAPI {

    let loginLink = URL.questAuthURL(
        clientId: "aFsd42sf234FGsdf",
        callbackURL: URL(string: "https://myurl.com/auth-redirect")!
    )
    
    let authProvider = AuthProvider(tokenStore: TokenStore())
    lazy var api: API = { API(provider: authProvider) }()
    
    private(set) var accounts: Set<Account> = []
    
    init() {
        authProvider.delegate = self
    }

    func singIn() {
        // present loginLink
        // user goes through oAuth steps
        // once steps are completed 
        // recieve url from quests oAuth and pass to the authorize from url method.
        authProvider.authorize(from: url)
    }
    
}

extension MyAPI: AuthProviderDelegate {
    func didAuthorize(_ auth: AuthProvider){
        api.accounts{ res in
            do {
                self.accounts.update(try res.get().accounts)
            } catch {
                //TODO: handle error
            }
        }
    }
}

Author

License

This project is licensed under the MIT License - see the LICENSE.md file for details

You might also like...
An extensible monitoring framework written in Swift

XestiMonitors Overview Reference Documentation Requirements Installation CocoaPods Carthage Swift Package Manager Usage Core Location Monitors Core Mo

A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

Just another NES emulator written in Swift

SwiftNes This repo contains all the source code for my experimental 100 days of NES challenge. What is this all about? I'm planning to build a fully w

A Powerful , Extensible CSS Parser written in pure Swift.
A Powerful , Extensible CSS Parser written in pure Swift.

A Powerful , Extensible CSS Parser written in pure Swift.

Python VM written in Swift

Violet Violet is one of those Swift - Python interop thingies, except that this time we implement the whole language from scratch. Name comes from V

A (slow) ray tracer written in Swift.

Blitzlichtgewitter Blitzlichtgewitter is a (slow) ray tracer written in Swift. It loosely follows the steps described in The Ray Tracer Challenge by J

Readium Mobile is a toolkit for ebooks, audiobooks and comics written in Swift & Kotlin.

Readium Swift Toolkit Readium Mobile is a toolkit for ebooks, audiobooks and comics written in Swift & Kotlin. This toolkit is a modular project, whic

A simple, but efficient CSV Parser, written in Swift.

CSV CSV.swift is a powerful swift library for parsing CSV files that supports reading as [String], [String: String] and Decodable, without sacrificing

A parser combinator library written in the Swift programming language.

SwiftParsec SwiftParsec is a Swift port of the Parsec parser combinator library. It allows the creation of sophisticated parsers from a set of simple

Owner
Eli Slade
I love designing, building and testing digital products.
Eli Slade
Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway

Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway deployed on Graviton arm64 build swift:5.6.2-amazonlinux2-docker image

Furqan 2 Aug 16, 2022
Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️

Welcome to Codextended — a suite of extensions that aims to make Swift’s Codable API easier to use by giving it type inference-powered capabilities an

John Sundell 1.4k Jan 2, 2023
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022
This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to load remote images

iOS NOW ⭐ This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to loa

William Tristão de Paula 1 Dec 7, 2021
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
SpriteKit API reproducing UIView's spring animations with SKAction

SpriteKit-Spring SpriteKit-Spring is a set of extensions to perform spring animations with SpriteKit. Installation iOS 7 If you need to support iOS 7,

Alexis Taugeron 242 Dec 17, 2022
An SSH config parser library with a fancy API

The SshConfig makes it quick and easy to load, parse, and decode/encode the SSH configs. It also helps to resolve the properties by hostname and use them safely in your apps (thanks for Optional and static types in Swift).

Artem Labazin 8 Nov 25, 2022
Swift-HorizontalPickerView - Customizable horizontal picker view component written in Swift for UIKit/iOS

Horizontal Picker View Customizable horizontal picker view component written in

Afraz Siddiqui 8 Aug 1, 2022
A utility that reminds your iPhone app's users to review the app written in pure Swift.

SwiftRater SwiftRater is a class that you can drop into any iPhone app that will help remind your users to review your app on the App Store/in your ap

Takeshi Fujiki 289 Dec 12, 2022