Swiftpack.co - Package - WeirdMath/TimetableSDK

TimetableSDK

Build Status codecov Cocoapods

Simple SDK for macOS, iOS and watchOS that allows you to get the data you need from timetable.spbu.ru.

Requirements

  • Swift 3
  • iOS 8.0+
  • macOS 10.10+
  • tvOS 9.0+
  • watchOS 2.0+

Installation

CocoaPods

For the latest release in CocoaPods add the following to your Podfile:

use_frameworks!

pod 'TimetableSDK'

Swift Package Manager

Add TimetableSDK as a dependency to your Package.swift. For example:

let package = Package(
    name: "YourPackageName",
    dependencies: [
        .Package(url: "https://github.com/WeirdMath/TimetableSDK.git", majorVersion: 3)
    ]
)

Usage

You can use the SDK for getting data directly from timetable.spbu.ru:

import TimetableSDK

let timetable = Timetable()

timetable.fetchDivisions() { result in
    
    switch result {
    case .success(let divisions):
        
        let physics = divisions[19]
        
        print(physics.name)
        // "Физика"
        
        physics.fetchStudyLevels(){ result in
            
            switch result {
            case .success(let studyLevels):
                
                print(studyLevels[0].specializations[0].name)
                // "Информационные технологии и численные методы"
                
            case .failure(let error):
                print(error)
            }
        }
    case .failure(let error):
        print(error)
    }
}

Or — if you want to just test your app and don't need networking — the data can be deserialized from JSON files:

import Foundation
import TimetableSDK

let timetable = Timetable()

let url = Bundle.main.url(forResource: "divisions", withExtension: "json")!
let jsonData = try! Data(contentsOf: url)

timetable.fetchDivisions(using: jsonData) { result in
    // ...
}

You can specify a dispatch queue if you need to:

import Dispatch
import TimetableSDK

timetable.fetchDivisions(dispatchQueue: .global(qos: .background)) { result in
    // ...
}

You can use promises!

import TimetableSDK
import PromiseKit

let timetable = Timetable()

timetable.fetchDivisions().then { divisions -> Promise<[StudyLevel]> in
    
    let physics = divisions[19]
    
    print(physics.name)
    // "Физика"
    
    return physics.fetchStudyLevels()
    
}.then { studyLevels in

    print(studyLevels[0].specializations[0].name)
    // "Информационные технологии и численные методы"
    
}.catch { error in
    print(error)
}

Contributing

In order to generate an Xcode project for TimetableSDK execute the following command in the root directory of the project:

$ swift package generate-xcodeproj

Github

link
Stars: 0
Help us keep the lights on

Used By

Total: 0

Releases

3.1.2 - May 9, 2017

  • Set DateFormatters' locale to "en_US_POSIX". This prevents those formatters from returning nil when converting a string to Date.

3.1.1 - Apr 17, 2017

  • Fixed not setting the studentGroup property for fetched next and previous weeks

3.1.0 - Apr 8, 2017

  • Now when calling a fetching method, you can disable force reloading. I. e. if somthing has already been fetched and saved to a property of a class that provides the fetching method, calling that method with forceReload: false returns the contents of that property.
  • You can now fetch extracurricular events for a division (currently Liberal Arts and Science only).

3.0.0 - Mar 19, 2017

  • Dropped Alamofire and DefaultStringConvertible dependencies.

  • Result type in now implemented as follows:

    public enum Result<Value> {
        case success(Value)
        case failure(TimetableError)
    }
    

2.2.0 - Mar 7, 2017

Implemented features:

  • Created Address and Room entities.
  • Location can now fetch the room that it refers to, if one can be found (which is not guaranteed even if there actually is such room, but its address does not match exactly to the location's address).
  • Some docs fixed.
  • Fixed not setting the timetable property for some entities.
  • Event and Location were made classes.