Skip to content

Commit

Permalink
Merge pull request #35 from gionoa/develop
Browse files Browse the repository at this point in the history
Driver Standings
  • Loading branch information
gionoa authored Jun 13, 2020
2 parents 9c73de3 + ac6f711 commit 4c48c6f
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 8 deletions.
74 changes: 74 additions & 0 deletions Sources/ErgastAPI/Models/DriverStandings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// DriverStandings.swift
//
//
// Created by Giovanni Noa on 6/12/20.
//

import Foundation

public struct DriverStandings: Codable {
let data: DriverStandingsData

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

struct DriverStandingsData: Codable {
let series: String
let url: String
let limit: String
let offset: String
let total: String
let standingsTable: StandingsTable

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

struct StandingsTable: Codable {
let season: String
let standingsLists: [StandingsList]

enum CodingKeys: String, CodingKey {
case season
case standingsLists = "StandingsLists"
}
}

struct StandingsList: Codable {
let season: String
let round: String
let driverStandings: [DriverStanding]

enum CodingKeys: String, CodingKey {
case season
case round
case driverStandings = "DriverStandings"
}
}

struct DriverStanding: Codable {
let position: String
let positionText: String
let points: String
let wins: String
let driver: Driver
let constructors: [Constructor]

enum CodingKeys: String, CodingKey {
case position
case positionText
case points
case wins
case driver = "Driver"
case constructors = "Constructors"
}
}
14 changes: 14 additions & 0 deletions Sources/Formula1API/Formula1API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public enum Formula1API {
}
}

public static func driverStandings(for season: Season,
limit: String? = nil,
offset: String? = nil,
completion: @escaping (Result<DriverStandings, APIError>) -> Void) {

URLSession.shared.fetch(.driverStandings,
for: season,
limit: limit,
offset: limit) { result in
completion(result)
}
}


/// Fetches Formula 1 Race Schedule for a given year.
/// - Parameters:
/// - season: Season enum case, specified by an Int, which indicates to fetch data for a given year (1950-2020).
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 .driverStandings: return DriverStandings.self
case .finishingStatus: return FinishingStatus.self
case .lapTimes(_): return Laps.self
case .seasons: return Seasons.self
Expand Down
73 changes: 73 additions & 0 deletions Sources/Formula1API/Models/DriverStandings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// DriverStandings.swift
//
//
// Created by Giovanni Noa on 6/12/20.
//

import Foundation

public struct DriverStandings: Codable {
let data: DriverStandingsData

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

// MARK: - MRData
struct DriverStandingsData: Codable {
let series: String
let url: String
let limit: String
let offset: String
let total: String
let standingsTable: StandingsTable

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

struct StandingsTable: Codable {
let season: String
let standingsLists: [StandingsList]

enum CodingKeys: String, CodingKey {
case season
case standingsLists = "StandingsLists"
}
}

struct StandingsList: Codable {
let season, round: String
let driverStandings: [DriverStanding]

enum CodingKeys: String, CodingKey {
case season, round
case driverStandings = "DriverStandings"
}
}

struct DriverStanding: Codable {
let position: String
let positionText: String
let points: String
let wins: String
let driver: Driver
let constructors: [Constructor]

enum CodingKeys: String, CodingKey {
case position
case positionText
case points
case wins
case driver = "Driver"
case constructors = "Constructors"
}
}
8 changes: 0 additions & 8 deletions Sources/Formula1API/Models/File.swift

This file was deleted.

0 comments on commit 4c48c6f

Please sign in to comment.