🚘 ParkKit

Travis Version License Platform Docs Codecov

这是一个对 ParkAPI 提供的 API 的封装,适用于任何用 Swift 编写的项目。它的主要目的是被 ParkenDD 使用。

示例

let park = ParkKit() // uses the default server at parkendd.de
// let park = ParkKit(withURL: URL(string: "https://your_server.com")!) // uses your server
park.fetchCities { result in
    guard let response = result.success else { return }
    print(response.cities)
}

// ▿ 13 elements
//   ▿ ParkKit.City
//     - name: "Aarhus"
//     ▿ coordinate: __C.CLLocationCoordinate2D
//       - latitude: 56.153005
//       - longitude: 10.203201
//       ...
park.fetchLots(forCity: "Dresden") { result in
    guard let response = result.success else { return }
    print(response.lots)
}

// ▿ 48 elements
//   ▿ ParkKit.Lot
//     ▿ address: Optional("Wilsdruffer Straße")
//       ...
let centrum = "dresdencentrumgalerie"
let dresden = "Dresden"

// Fetch forecast info for today
park.fetchForecast(forLot: centrum, inCity: dresden) { result in
    guard let response = result.success else { return }
    print(response.forecast)
}

park.fetchForecast(forLot: centrum, inCity: dresden, forDay: .today) { _ in
    // Same as above, `forDay` accepts either `.today`, `.offsetFromToday(Int)` 
    // or any `Date` value which will be used to infer the day.
}

// You can also specify a custom start and end day if you want more than a single day's worth of data:

let startingDate = Date()
let endingDate = startingDate.addingTimeInterval(7 * 24 * 60 * 60) // one week from now

park.fetchForecast(forLot: centrum, inCity: dresden, startingAt: startingDate, endingAt: endingDate) { _ in
    // ...
}

// ▿ 97 elements
//   ▿ (2 elements)
//     - .0: 2017-01-11 00:00:00 +0000
//     - .1: 13
//   ▿ (2 elements)
//     - .0: 2017-01-11 00:15:00 +0000
//     - .1: 12
//   ...

要求

如果您正在托管您自己的 ParkAPI 服务器版本,并在 iOS 上使用它,如果您没有通过 HTTPS 提供数据,您可能需要设置 ATS 例外。

如果您计划执行大量请求(例如,通过多个客户端应用程序),绝对建议您使用自己的服务器。

安装

ParkKit 可以通过 Cocoapods、Carthage/Punic 和 Swift Package Manager 安装,任您选择。

Podfile 中的复制粘贴

pod "ParkKit"

Cartfile

github "kiliankoe/ParkKit"

Package.swift

.Package(url: "https://github.com/kiliankoe/ParkKit", majorVersion: 0)

贡献者

Kilian Koeltzsch, @kiliankoe

许可

ParkKit 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。