TPGSwift

4.0.0

:bus: TPG OpenData Swift Library
yageek/TPGSwift

What's New

Swift 4.2

2019-02-19T11:47:39Z
  • Compatibility with Swift 4.2
  • Hide unnecessary information about Decodable

TPGSwift

Swift libary for the TPG Open Data.

For more explanation: TPG Open Data

Build Status

MIT License Carthage compatible CocoaPods Compatible Platform

Usage

import TPGSwift

// MARK: - Setting the key

// Set the API Key
API.Key = "MY_API_KEY"

// MARK: - Creating an API call url

// Get stops for the stop code "WTC0"
let getStops = API.getStops(stopCode: "WTC0", stopName: nil, line: nil, latitude: nil, longitude: nil)

print("API Stops: \(getStops.URL)")
// -> API Stops: https://prod.ivtr-od.tpg.ch/v1/GetStops.json?key=KEY&stopCode=WTC0

// MARK: - Decode

let json = JSONDecoder()
// This is mandatory
decoder.dateDecodingStrategy = .iso8601

do {
    let stops = try json.decode(Record<Stop>.self, from: data)
    print("Stops: \(stops)")
} catch let error {
    print("Error: \(error)")
}

Paw

You can find a basic Paw file which will help you to play with the API. Open TPGSwift.paw and change the KEY variable in the Production group with the one received from the TPG.

License

TPGSwift is released under the MIT license. See LICENSE for details.

Description

  • Swift Tools
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Oct 21 2024 19:00:49 GMT-0900 (Hawaii-Aleutian Daylight Time)