A Monzo client that provides a simple Swift interface to the Monzo API. This package is targeted towards server side use on Linux; if you're looking for a Monzo client for iOS then have a look at MondoKit.
API documentation, user guides and setup information can be found at monzo.com/docs.
Note: the minimum required Swift version is DEVELOPMENT-SNAPSHOT-2016-11-08-a
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/marius-serban/monzo-swift.git"),
]
)
The library is compatible with Open Swift so you can use it with any server side framework that supports this standards. It relies upon a S4 Responder
to perform the HTTP calls over the network. Luckly, Vapor's Droplet
and Zewo's' Client
conform to this protocol for example.
let myHttpClient = ...
let monzo = Monzo.Client(httpClient: myHttpClient)
Create a URI that points to the Monzo login page for your app.
let uri = Monzo.Client.authorizationUri(clientId: "aClientId", redirectUri: "http://host.com/?param=[]#fragment", nonce: "abc123")
// redirect user to URI
let credentials = try monzo.authenticate(withCode: " ", clientId: " ", clientSecret: " ")
or
let newCredentials = try monzo.refreshAccessToken(refreshToken: oldCredentials.refreshToken, clientId: " ", clientSecret: " ")
do {
try monzo.ping()
} catch {
// try again later
}
let accessTokenInfo = try monzo.whoami(accessToken: "a_token")
let accounts = try monzo.accounts(accessToken: "a_token")
let balance = try monzo.balance(accessToken: "a_token", accountId: "an_account_id")
// list all transactions
let transactions = try monzo.transactions(accessToken: "a_token", accountId: "an_account_id")
// list transactions, filtered and paginated
let transactions = try monzo.transactions(accessToken: "a_token", accountId: "an_account_id", since: .transaction("txid1234"), before: referenceDate, limit: 20)
// get transaction details
let transactionDetails = try monzo.transaction(accessToken: "a_token", id: "txid1234")
try monzo.annotate(transaction: "txid1234", with metadata: ["key1": "value1", "key2": "value2"], accessToken: String)
// create simple feed item
try monzo.createFeedItem(accessToken: "a_token", accountId: "an_account", title: "Hello!", imageUrl: "http://images.domain/1")
// create fully customized feed item
try.createFeedItem(
accessToken: "a_token",
accountId: "an_account_id",
title: "happy days! 🕺🏽",
imageUrl: "http://images.domain/an-image.jpeg?param=j&other=k",
url: "http://my.website/?param1=1¶m2=2",
body: "this is a sample body",
backgroundColor: "#FFFFFF",
bodyColor: "#AAAAAA",
titleColor: "#BBBBBB"
)
// create
let webhook =try monzo.createWebhook(accessToken: "a_token", accountId: "account_id", url: "http://host.domain/path")
// list
let webhooks = try monzo.webhooks(accessToken: "a_token", accountId: "account_id")
// delete
try monzo.deleteWebhook(accessToken: "a_token", id: "account_id")
You can create a Github issue in this repository. When stating your issue be sure to add enough details about what's causing the problem and reproduction steps.
Also, you can get in touch with me on Twitter.
This project is released under the MIT license. See LICENSE for details.