Initalier Commit
This commit is contained in:
31
Linkster/ApiClient.swift
Normal file
31
Linkster/ApiClient.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import Foundation
|
||||
|
||||
struct ApiClient {
|
||||
static let shared = ApiClient()
|
||||
|
||||
private let base = URL(string: "https://linkster.langhei.de/api")!
|
||||
|
||||
func resolve(url: String) async throws -> SongResult? {
|
||||
var components = URLComponents(url: base.appendingPathComponent("resolve"), resolvingAgainstBaseURL: false)!
|
||||
components.queryItems = [URLQueryItem(name: "url", value: url)]
|
||||
|
||||
let (data, _) = try await URLSession.shared.data(from: components.url!)
|
||||
let json = try JSONDecoder().decode(ResolveResponse.self, from: data)
|
||||
guard json.found else { return nil }
|
||||
|
||||
return SongResult(
|
||||
title: json.title ?? "",
|
||||
artist: json.artist ?? "",
|
||||
playlistName: json.playlist ?? "",
|
||||
providers: json.providers ?? [:]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private struct ResolveResponse: Decodable {
|
||||
let found: Bool
|
||||
let title: String?
|
||||
let artist: String?
|
||||
let playlist: String?
|
||||
let providers: [String: String]?
|
||||
}
|
||||
Reference in New Issue
Block a user