LotsOfChanges
This commit is contained in:
@ -8,15 +8,12 @@
|
||||
import Foundation
|
||||
|
||||
final class NetworkManager {
|
||||
|
||||
//"https://webictis.sfedu.ru/schedule-api/?group=51.html&week=15"
|
||||
//MARK: Properties
|
||||
static let shared = NetworkManager()
|
||||
private let decoder = JSONDecoder()
|
||||
private let urlForGroup = "https://webictis.sfedu.ru/schedule-api/?query="
|
||||
private let urlForWeek = "https://webictis.sfedu.ru/schedule-api/?group=51.html&week=15"
|
||||
private var groupString: String = ""
|
||||
private var numOfGroup: String = ""
|
||||
private var numOfWeek: String = ""
|
||||
private let urlForWeek = "https://webictis.sfedu.ru/schedule-api/?group="
|
||||
|
||||
//MARK: Initializer
|
||||
private init() {
|
||||
@ -24,16 +21,33 @@ final class NetworkManager {
|
||||
}
|
||||
|
||||
//MARK: Methods
|
||||
func makeURL(_ group: String) -> String {
|
||||
func makeUrlForGroup(_ group: String) -> String {
|
||||
return urlForGroup + group
|
||||
}
|
||||
|
||||
func makeUrlForWeek(_ numOfWeek: Int, _ htmlNameOfGroup: String) -> String {
|
||||
return urlForWeek + htmlNameOfGroup + "&" + String(numOfWeek)
|
||||
}
|
||||
|
||||
func getSchedule(_ group: String) async throws -> Schedule {
|
||||
let newUrlForGroup = makeURL(group)
|
||||
let newUrlForGroup = makeUrlForGroup(group)
|
||||
guard let url = URL(string: newUrlForGroup) 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
|
||||
}
|
||||
}
|
||||
func getScheduleForOtherWeek(_ numOfWeek: Int, _ htmlNameOfGroup: String) async throws -> Schedule {
|
||||
let newUrlForWeek = makeUrlForWeek(numOfWeek, htmlNameOfGroup)
|
||||
guard let url = URL(string: newUrlForWeek) 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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user