Skip to content

Commit

Permalink
Merge pull request #37 from gionoa/develop
Browse files Browse the repository at this point in the history
Driver Info
  • Loading branch information
gionoa committed Jun 13, 2020
2 parents 4c48c6f + ff2447f commit 5993d5e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Sources/Formula1API/Formula1API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public enum Formula1API {
/// Fetches Formula 1 Circuits for a given year.
/// - Parameters:
/// - season: Season enum case, specified by an Int, which indicates to fetch data for a given year (1950-2020).
/// - limit: Optional property to specify number of items to return per request.
/// - offset: Optional property to indicate starting point of elements from API request.
/// - limit: Property to specify number of items to return per request.
/// - offset: Property to indicate starting point of elements from API request.
/// - completion: Asynchronous closure to inject functionality once the network interaction completes.
public static func circuits(for season: Season,
limit: String? = nil,
Expand Down Expand Up @@ -44,6 +44,23 @@ public enum Formula1API {
}
}

/// Fetches Formula 1 Drivers - either all, or for a given year.
/// - Parameters:
/// - season: Season enum case, specified by an Int, which indicates to fetch data for a given year (1950-2020).
/// - limit: Property to specify number of items to return per request.
/// - offset: Property to indicate starting point of elements from API request.
/// - completion: Asynchronous closure to inject functionality once the network interaction completes.
public static func drivers(for season: Season,
limit: String? = nil,
offset: String? = nil,
completion: @escaping (Result<Drivers, APIError>) -> Void) {

URLSession.shared.fetch(.drivers,
for: season) { result in
completion(result)
}
}

/// Fetches Formula 1 Seasons throughout history.
/// - Parameters:
/// - limit: Optional property to specify number of items to return per request.
Expand Down
1 change: 1 addition & 0 deletions Sources/Formula1API/Helpers/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ extension Path {
switch self {
case .circuits: return Circuits.self
case .constructors: return Constructors.self
case .drivers: return Drivers.self
case .driverStandings: return DriverStandings.self
case .finishingStatus: return FinishingStatus.self
case .lapTimes(_): return Laps.self
Expand Down
44 changes: 44 additions & 0 deletions Sources/Formula1API/Models/Drivers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// DriverInfo.swift
//
//
// Created by Giovanni Noa on 6/12/20.
//

import Foundation

public struct Drivers: Codable {
let data: DriversData

enum CodingKeys: String, CodingKey {
case data = "MRData"
}
}

struct DriversData: Codable {
let series: String
let url: String
let limit: String
let offset: String
let total: String
let driverTable: DriverTable

enum CodingKeys: String, CodingKey {
case series
case url
case limit
case offset
case total
case driverTable = "DriverTable"
}
}

struct DriverTable: Codable {
let season: String
let drivers: [Driver]

enum CodingKeys: String, CodingKey {
case season
case drivers = "Drivers"
}
}

0 comments on commit 5993d5e

Please sign in to comment.