{"id":21469726,"url":"https://github.com/jmargenberg/swiftptv","last_synced_at":"2025-03-17T06:33:23.795Z","repository":{"id":33941672,"uuid":"161910270","full_name":"jmargenberg/SwiftPTV","owner":"jmargenberg","description":"An API adaptor for the PTV Timetable API written in Swift for iOS ","archived":false,"fork":false,"pushed_at":"2022-10-06T03:27:53.000Z","size":3726,"stargazers_count":2,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T03:01:58.469Z","etag":null,"topics":["api-client","ios","rest-api","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmargenberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-15T14:00:23.000Z","updated_at":"2021-05-27T01:07:20.000Z","dependencies_parsed_at":"2022-08-07T23:30:51.506Z","dependency_job_id":null,"html_url":"https://github.com/jmargenberg/SwiftPTV","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2FSwiftPTV","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2FSwiftPTV/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2FSwiftPTV/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2FSwiftPTV/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmargenberg","download_url":"https://codeload.github.com/jmargenberg/SwiftPTV/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243987247,"owners_count":20379503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","ios","rest-api","swift"],"created_at":"2024-11-23T09:17:49.444Z","updated_at":"2025-03-17T06:33:23.745Z","avatar_url":"https://github.com/jmargenberg.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PTV\n\n[![Build Status](https://travis-ci.org/jmargenberg/SwiftPTV.svg?branch=master)](https://travis-ci.org/jmargenberg/SwiftPTV) [![](https://img.shields.io/cocoapods/v/PTV.svg)](https://cocoapods.org/pods/PTV)\n\nAPI adaptor for the [PTV Timetable API v3](https://timetableapi.ptv.vic.gov.au/swagger/ui/index) written in Swift for iOS.\n\n## Installation\nThis library can be installed using [cocoapods](https://cocoapods.org/pods/PTV).\n\nJust add `pod 'PTV', '~\u003e 0.2'` to your podfile and run `pod install`.\n\n## Adapter Classes\n\n### Modelled Adapter\n```\nimport PTV\n\nlet ptv = PTV.ModelledAdapter(devid: \"12345678\", key: \"12345678901234567890\")\n```\n\nProvides functions for specific api calls with successfull calls calling a `completion` closure with predefined `Codable` structs and failing calls calling a `failure` closure with `CallFailReason`  enum (e.g.  `.AccessDenied` or `.NoNetworkConnection`) and `message` string\n\nI've only implemented the subset of the PTV API calls that I needed to complete my project. If you need to use any other calls you should be able to follow how the existing calls are implemented to implement new functions for these calls. If you do so, please feel free to create a PR and I'll merge it in.\n\n#### Implemented Functions\n##### Routes\n*  `getRouteTypes(failure: Adapter.FailureHandler) { routeTypes: [RouteType]) in _ }`\n*  `getRoutes(failure: Adapter.FailureHandler) { routes: [Route] in _ }`\n*  `getRoutes(forRouteTypeID: Int, failure: Adapter.FailureHandler) { routes: [Route]) in _ }`\n*  `getRoutes(forRouteTypeIDs: [Int], failure: Adapter.FailureHandler) { routes: [Route]) in _ }`\n\n##### Stops\n\n*  `getStops(nearLocation: CLLocationCoordinate2D, forRouteTypes: [Int], maxResults: Int, maxDistance: Int, failure: Adapter.FailureHandler) { stops: [StopGeosearch]) in _ }`\n*  `getStops(onRoute: Int, forRouteType: Int, failure: Adapter.FailureHandler) { stops: [StopOnRoute]) in _ }`\n*  `getStopDetails(forStop: Int, forRouteType: Int, failure: Adapter.FailureHandler) {stop: StopDetails in _ }`\n\n##### Departures and Stopping Patterns\n*  `getDepartures(forStop: Int, withRouteType: Int, failure: Adapter.FailureHandler) { departures: [Departure] in _ }`\n*  `getStoppingPattern(forRun: Int, withRouteType: Int, failure: Adapter.FailureHandler) {stoppingPattern: StoppingPattern) in _ }`\n\nNote that `Adapter.FailureHandler` is a typealias for the function type `(_ callFailReason: CallFailReason, _ message: String?) -\u003e ()`\n\n###  Caching Adapter\n```\nimport PTV\n\nlet ptv = PTV.CachingAdapter(devid: \"1234567\", key: \"12345678901234567890\")\n```\n\nSubclas of  `PTV.ModelledAdapter` where any 'static' data that is returned is cached for easy retrieval later.\n\nFor example an already encountered route can be retrieved with `getRouteFromCache(forRouteId: 9);` without having to make an actual api call.\n\nThis is especially useful when using `getDeparture(forStop, withRouteType, failure, completion)` as any directions, runs, routes or stops referenced in the returned departures are cached for cheap retrieval later.\n\n### Plain Adapter\n```\nimport PTV\n\nlet ptv = PTV.Adapter(devid: \"1234567\", key: \"12345678901234567890\")\n```\n\nAllows you to directly call the PTV API based on the api name, search string and parameters as defined in the [PTV API documentation](https://timetableapi.ptv.vic.gov.au/swagger/ui/index).\n\nYou should only need to use this if you need an api call not covered by `ModelledAdapter` or `CachingAdapter`.\n\nHandles the [(kind of unusual) request signing](https://static.ptv.vic.gov.au/PTV/PTV%20docs/API/1475462320/PTV-Timetable-API-key-and-signature-document.RTF) required to authenticate to the PTV API.\n\nIf successful, calls a `completion` closure with the response deocded to a `Codable` type, otherwise calls a `failure` closure with a `CallFailReason` e.g. `.AccessDenied` or `.NoNetworkConnection`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmargenberg%2Fswiftptv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmargenberg%2Fswiftptv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmargenberg%2Fswiftptv/lists"}