Giter VIP home page Giter VIP logo

emealkit's Introduction

๐ŸŒฏ EmealKit

Swift library for accessing some of the meal related data the Studentenwerk Dresden has to offer.

Quick Start

Current meals or available canteens

let meals = try await Meal.for(canteen: .alteMensa, on: Date())
for meal in meals {
    print(meal.name)
}

let canteens = try await Canteen.all()
for canteen in canteens {
    print(canteen.name)
}

A completion block based API and one built on Combine are also available.

Cardservice

Talk to the Cardservice to acquire data about your Emeal card. You will need to have registered for Autoload to have the necessary authentication details.

let cardservice = try await Cardservice.login(username: "1234567890", password: "hunter2")
let carddata = try await cardservice.carddata()
print(carddata)

let ninetyDaysAgo = Date().addingTimeInterval(-60 * 60 * 24 * 90)
let transactions = try await cardservice.transactions(begin: ninetyDaysAgo)
print(transactions)

NFC Scanning

EmealKit also handles scanning the Emeal card via NFC if your device supports it. Just create an Emeal object, conform to EmealDelegate and call beginNFCSession.

class YourEmealHandler: EmealDelegate {
    let emeal: Emeal
  
    init() {
        let strings = LocalizedEmealStrings(/*...*/)
        emeal = Emeal(localizedStrings: strings)
        emeal.delegate = self
        
        // Call this to start the NFC session.
        emeal.beginNFCSession()
    }
  
    func readData(currentBalance: Double, lastTransaction: Double) {
        // Gets called on a successful scan.
    }
  
    func invalidate(with error: Error) {
        // Called on errors.
    }
}

It's even easier if you use ObservableEmeal in your SwiftUI views. It could look something like this.

struct MyView: View {
    @StateObject private var emeal = ObservableEmeal(localizedStrings: .init(/* ... */))
    
    var body: some View {
        VStack {
            Text("Balance: \(emeal.currentBalance ?? 0.0)")
            Text("Last Transaction: \(emeal.lastTransaction ?? 0.0)")
                
            if let error = emeal.error {
                Text(error.localizedDescription)
                    .foregroundColor(.red)
            }
            
            Button(action: emeal.beginNFCSession) {
                Text("Scan Emeal")
            }
        }
    }
}

Installation

EmealKit is available through Swift Package Manager.

.package(url: "https://github.com/kiliankoe/EmealKit.git", from: "<#latest#>")

Used by

This library is currently being used in the following applications:

Know of any others? Please open a PR and add it to the list! ๐Ÿ˜Š

emealkit's People

Contributors

kiliankoe avatar welljsjs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

emealkit's Issues

Rate Limiting?

I've seen a HTTP 429 here and there. Could that be what the client registration is for?

Consolidate error types

For historical reasons there's still two different error types with some overlap left here. Would be nice to throw them together.

Add SwiftUI UI modules

It could possibly make sense to move some of that stuff here, especially the Emeal card view.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.