Schedule-ICTIS/Schedule ICTIS/Network/NetworkManager.swift
Vladimir Dubovik 0410575c8d Commit
2024-12-03 14:32:38 +03:00

37 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// NetworkManager.swift
// Schedule ICTIS
//
// Created by Mironov Egor on 18.11.2024.
//
import Foundation
final class NetworkManager {
//MARK: Properties
static let shared = NetworkManager()
private let decoder = JSONDecoder()
private let urlForGroup = "https://webictis.sfedu.ru/schedule-api/?query=ктбо2-6"
private let urlForWeek = "https://webictis.sfedu.ru/schedule-api/?group=51.html&week=15"
//MARK: Initializer
private init() {
decoder.dateDecodingStrategy = .iso8601
}
//MARK: Methods
func getSchedule() async throws -> Schedule {
guard let url = URL(string: urlForGroup) else { throw NetworkError.invalidUrl}
let (data, response) = try await URLSession.shared.data(from: url)
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {throw NetworkError.invalidResponse}
do {
return try decoder.decode(Schedule.self, from: data)
}
catch {
throw NetworkError.invalidData
}
}
}