-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
2,123 additions
and
1,152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
.swiftpm/xcode/xcuserdata/sqeezelemon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
.swiftpm/xcode/xcuserdata/sqeezelemon.xcuserdatad/xcschemes/xcschememanagement.plist
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) 2021-2022 Alexander Nikitin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,65 @@ | ||
# SwiftyLiveApi | ||
# SwiftyLiveAPI | ||
|
||
SwiftyLiveApi is a simple package to work with Infinite Flight Live API. It features support for all available endpoints, safety mechanisms against exceeding request limits, Live API error types, beautiful documentation right in XCode and support up to Swift 3. | ||
SwiftyLiveApi is a wrapper around Infinite Flight Live API. | ||
|
||
## Usage | ||
|
||
Setup is as easy as initializing an instance of ```LiveApiClient``` with your API key. If needed, you can set the ```requestLimitPerMinute``` value both in the initializer and later as just a value of the class. Please remember that just like on the road, unless you know what you're doing you shouldn't go over 100. Results have different extensions which transform stuff like ```Int``` frequency type into a nice enum. For your convenience, all functions are named almost exactly as the pages on them in the User Guide. | ||
The package is available for following platforms: | ||
| Platform | Min. Version | | ||
| -------- | ------------ | | ||
| iOS | 10 | | ||
| TvOS | 10 | | ||
| MacOS | 10.12 | | ||
|
||
## Reporting bugs | ||
I tested it on random flights from expert server to the point I didn't get errors, but I could have easily missed an optional somewhere or misspelled a value. If you stumble upon something, just PM me your problem and a copy of the JSON response that causes problems on Discord or [IFC](https://community.infiniteflight.com/u/Alexander_Nikitin). | ||
### Installation | ||
|
||
This package is available with the Swift Package Manager in XCode. | ||
|
||
To install it manually, insert this in your `Package.swift`: | ||
```swift | ||
.package(url: "https://github.com/sqeezelemon/SwiftyLiveApi.git", from: "3.0.0") | ||
``` | ||
|
||
and then add it to your target, for example, like this: | ||
|
||
```swift | ||
.target(name: "YourTarget", dependencies: [ | ||
.product(name: "SwiftyLiveApi", package: "SwiftyLiveApi") | ||
], | ||
``` | ||
|
||
### Getting started | ||
|
||
[**Live API Docs**](https://infiniteflight.com/guide/developer-reference/live-api/) | ||
|
||
All SwiftyLiveApi types have a `LA` prefix, just like the big boy libraries. | ||
To get started, import `SwiftyConnectApi`, create an instance of `LAClient` and get straight into coding. | ||
The methods are named in accordance to their Developer Manual names. For example, the `Get Sessions` method becomes `getSessions()`. | ||
Some structures were changed and some variables were renamed for better uniformity and readability. In places where this might get confusing, variable aliases were added to help. | ||
|
||
```swift | ||
// 1) Import the package | ||
import SwiftyLiveApi | ||
|
||
// 2) Initialise the client | ||
let client = LAClient("your api key") | ||
|
||
// 3) Ready to rock! | ||
let sessions = try client.getSessions() | ||
``` | ||
|
||
### Running tests | ||
|
||
In order for tests to work, please insert your Live API key into `Tests/SwiftyLiveApiTests/apikey.txt`, without any preceding whitespace. After that, the tests should run with your API key. | ||
To ignore changes to the file to avoid accidentally pushing your API key, use this command: | ||
|
||
```bash | ||
git update-index --skip-worktree Tests/SwiftyLiveApiTests/apikey.txt | ||
``` | ||
|
||
### Reporting bugs | ||
|
||
If you encounter a bug, please file an issue with the reproduction steps and/or the json or request that caused problems. | ||
|
||
## Contacts | ||
[**@sqeezelemon** on IFC](https://community.infiniteflight.com/u/sqeezelemon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SwiftyLiveApi | ||
// ↳ LAAtcFacility.swift | ||
// | ||
// Created by: | ||
// Alexander Nikitin - @sqeezelemon | ||
|
||
import Foundation | ||
|
||
/// Metadata about an ATC facility. | ||
public struct LAAtcFacility: Decodable { | ||
public init(id: String, icao: String? = nil, type: LAFacilityType, latitude: Double, longitude: Double) { | ||
self.id = id | ||
self.icao = icao | ||
self.type = type | ||
self.latitude = latitude | ||
self.longitude = longitude | ||
} | ||
|
||
/// Unique identifier for the facility. | ||
public var id: String | ||
/// ICAO code of the airport. `null` if center. | ||
public var icao: String? | ||
/// Facility type. | ||
public var type: LAFacilityType | ||
/// Latitude of the facility. | ||
public var latitude: Double | ||
/// Longitude of the facility. | ||
public var longitude: Double | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case id | ||
case icao = "airportIcao" | ||
case type = "frequencyType" | ||
case latitude, longitude | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SwiftyLiveApi | ||
// ↳ LAAtcFrequency.swift | ||
// | ||
// Created by: | ||
// Alexander Nikitin - @sqeezelemon | ||
|
||
import Foundation | ||
|
||
/// An active ATC frequency. | ||
public struct LAAtcFrequency: Decodable { | ||
public init(facility: LAAtcFacility, userId: String, username: String? = nil, virtualOrganization: String? = nil, startTime: Date) { | ||
self.facility = facility | ||
self.userId = userId | ||
self.username = username | ||
self.virtualOrganization = virtualOrganization | ||
self.startTime = startTime | ||
} | ||
|
||
/// Information about the facility. | ||
public var facility: LAAtcFacility | ||
/// Unique identifier of the user controlling the frequency. | ||
public var userId: String | ||
/// User's forum username, `nil` if not linked or anonymous. | ||
public var username: String? | ||
/// User's forum VA/VO, `nil` if not linked, not set or anonymous. | ||
public var virtualOrganization: String? | ||
/// Time at which the frequency was opened. | ||
@LADate | ||
public var startTime: Date | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case frequencyId, airportName, type, latitude, longitude | ||
case userId, username, virtualOrganization, startTime | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
userId = try values.decode(String.self, forKey: .userId) | ||
username = try values.decode(String?.self, forKey: .username) | ||
virtualOrganization = try values.decode(String?.self, forKey: .virtualOrganization) | ||
_startTime = try values.decode(LADate.self, forKey: .startTime) | ||
|
||
facility = LAAtcFacility(id: try values.decode(String.self, forKey: .frequencyId), | ||
icao: try values.decode(String?.self, forKey: .frequencyId), | ||
type: try values.decode(LAFacilityType.self, forKey: .type), | ||
latitude: try values.decode(Double.self, forKey: .latitude), | ||
longitude: try values.decode(Double.self, forKey: .longitude)) | ||
} | ||
} | ||
|
||
extension LAAtcFrequency { | ||
/// Unique identifier for the facility. | ||
public var frequencyId: String { | ||
get { facility.id } | ||
set { facility.id = newValue } | ||
} | ||
|
||
/// ICAO code of the airport. `null` if center. | ||
public var airportName: String? { | ||
get { facility.icao } | ||
set { facility.icao = newValue } | ||
} | ||
|
||
/// Facility type. | ||
public var type: LAFacilityType { | ||
get { facility.type } | ||
set { facility.type = newValue } | ||
} | ||
|
||
/// Latitude of the facility. | ||
public var latitude: Double { | ||
get { facility.latitude } | ||
set { facility.latitude = newValue } | ||
} | ||
|
||
/// Longitude of the facility. | ||
public var longitude: Double { | ||
get { facility.longitude } | ||
set { facility.longitude = newValue } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SwiftyLiveApi | ||
// ↳ LAAtcRank.swift | ||
// | ||
// Created by: | ||
// Alexander Nikitin - @sqeezelemon | ||
|
||
import Foundation | ||
|
||
/// User ATC rank, defaults to `.observer` if `null`. | ||
public enum LAAtcRank: Int { | ||
case observer = 0 | ||
case trainee = 1 | ||
case apprentice = 2 | ||
case specialist = 3 | ||
case officer = 4 | ||
case supervisor = 5 | ||
case recruiter = 6 | ||
case manager = 7 | ||
|
||
/// Undocumented facility type, please file a report on GitHub if encountered. | ||
case undocumented | ||
} | ||
|
||
extension LAAtcRank: Decodable { | ||
public init(from decoder: Decoder) throws { | ||
let value = try decoder.singleValueContainer().decode(RawValue?.self) | ||
self = .init(rawValue: value ?? LAAtcRank.observer.rawValue) ?? .undocumented | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SwiftyLiveApi | ||
// ↳ LAFacilityType.swift | ||
// | ||
// Created by: | ||
// Alexander Nikitin - @sqeezelemon | ||
|
||
import Foundation | ||
|
||
/// ATC facility type. | ||
public enum LAFacilityType: Int { | ||
case ground = 0 | ||
case tower = 1 | ||
case unicom = 2 | ||
case clearance = 3 | ||
case approach = 4 | ||
case departure = 5 | ||
case center = 6 | ||
case atis = 7 | ||
case aircraft = 8 | ||
case recorded = 9 | ||
case unknown = 10 | ||
case unused = 11 | ||
|
||
/// Undocumented facility type, please file a report on GitHub if encountered. | ||
case undocumented | ||
} | ||
|
||
extension LAFacilityType: Decodable { | ||
public init(from decoder: Decoder) throws { | ||
let value = try decoder.singleValueContainer().decode(RawValue.self) | ||
self = .init(rawValue: value) ?? .undocumented | ||
} | ||
} |
Oops, something went wrong.