From bc6bab6f5926297e61f4a686a76d5bf8d7865df2 Mon Sep 17 00:00:00 2001 From: Rudrank Riyam Date: Sun, 12 Jun 2022 04:11:20 +0530 Subject: [PATCH] Update MusicDataDeleteRequest, MusicDataPostRequest, and MusicDataPutRequest --- .../MusicDataDeleteRequest.swift | 5 ++-- .../Add Resources/MusicDataPostRequest.swift | 4 +-- .../Add Resources/MusicDataPutRequest.swift | 5 ++-- .../Add Resources/MusicTokenRequest.swift | 28 ------------------- .../Add Resources/MusicTokenResponse.swift | 19 ------------- 5 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 Sources/MusadoraKit/Add Resources/MusicTokenRequest.swift delete mode 100644 Sources/MusadoraKit/Add Resources/MusicTokenResponse.swift diff --git a/Sources/MusadoraKit/Add Resources/MusicDataDeleteRequest.swift b/Sources/MusadoraKit/Add Resources/MusicDataDeleteRequest.swift index 29ab5276b..640822047 100644 --- a/Sources/MusadoraKit/Add Resources/MusicDataDeleteRequest.swift +++ b/Sources/MusadoraKit/Add Resources/MusicDataDeleteRequest.swift @@ -6,6 +6,7 @@ // import Foundation +import MusicKit public struct MusicDataDeleteRequest { /// The URL for the data request. @@ -18,11 +19,11 @@ public struct MusicDataDeleteRequest { /// Uploads data the Apple Music API endpoint that /// the URL request defines. - public func response() async throws -> MusicDataPostResponse { + public func response() async throws -> MusicDataResponse { var urlRequest = URLRequest(url: url) urlRequest.httpMethod = "DELETE" - var request = MusicTokenRequest(urlRequest: urlRequest) + let request = MusicDataRequest(urlRequest: urlRequest) let response = try await request.response() return response } diff --git a/Sources/MusadoraKit/Add Resources/MusicDataPostRequest.swift b/Sources/MusadoraKit/Add Resources/MusicDataPostRequest.swift index 305b75597..c0ea37883 100644 --- a/Sources/MusadoraKit/Add Resources/MusicDataPostRequest.swift +++ b/Sources/MusadoraKit/Add Resources/MusicDataPostRequest.swift @@ -20,11 +20,11 @@ public struct MusicDataPostRequest { /// Uploads data the Apple Music API endpoint that /// the URL request defines. - public func response() async throws -> MusicDataPostResponse { + public func response() async throws -> MusicDataResponse { var urlRequest = URLRequest(url: url) urlRequest.httpMethod = "POST" - var request = MusicTokenRequest(urlRequest: urlRequest) + let request = MusicDataRequest(urlRequest: urlRequest) let response = try await request.response() return response } diff --git a/Sources/MusadoraKit/Add Resources/MusicDataPutRequest.swift b/Sources/MusadoraKit/Add Resources/MusicDataPutRequest.swift index cfd86182b..b6ea96b83 100644 --- a/Sources/MusadoraKit/Add Resources/MusicDataPutRequest.swift +++ b/Sources/MusadoraKit/Add Resources/MusicDataPutRequest.swift @@ -6,6 +6,7 @@ // import Foundation +import MusicKit public struct MusicDataPutRequest { /// The URL for the data request. @@ -22,12 +23,12 @@ public struct MusicDataPutRequest { /// Uploads data the Apple Music API endpoint that /// the URL request defines. - public func response() async throws -> MusicDataPostResponse { + public func response() async throws -> MusicDataResponse { var urlRequest = URLRequest(url: url) urlRequest.httpMethod = "PUT" urlRequest.httpBody = data - var request = MusicTokenRequest(urlRequest: urlRequest) + let request = MusicDataRequest(urlRequest: urlRequest) let response = try await request.response() return response } diff --git a/Sources/MusadoraKit/Add Resources/MusicTokenRequest.swift b/Sources/MusadoraKit/Add Resources/MusicTokenRequest.swift deleted file mode 100644 index 535d52934..000000000 --- a/Sources/MusadoraKit/Add Resources/MusicTokenRequest.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// MusicTokenRequest.swift -// MusicTokenRequest -// -// Created by Rudrank Riyam on 18/05/22. -// - -import Foundation -import MusicKit - -public struct MusicTokenRequest { - public var urlRequest: URLRequest - - public init(urlRequest: URLRequest) { - self.urlRequest = urlRequest - } - - public mutating func response() async throws -> MusicDataPostResponse { - let developerToken = try await MusicDataRequest.tokenProvider.developerToken(options: .ignoreCache) - let userToken = try await MusicDataRequest.tokenProvider.userToken(for: developerToken, options: .ignoreCache) - - urlRequest.addValue("Bearer \(developerToken)", forHTTPHeaderField: "Authorization") - urlRequest.addValue(userToken, forHTTPHeaderField: "Music-User-Token") - - let (data, response) = try await URLSession.shared.data(for: urlRequest) - return MusicDataPostResponse(data: data, urlResponse: response as! HTTPURLResponse) - } -} diff --git a/Sources/MusadoraKit/Add Resources/MusicTokenResponse.swift b/Sources/MusadoraKit/Add Resources/MusicTokenResponse.swift deleted file mode 100644 index 67a65dd86..000000000 --- a/Sources/MusadoraKit/Add Resources/MusicTokenResponse.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// MusicTokenResponse.swift -// MusicTokenResponse -// -// Created by Rudrank Riyam on 18/05/22. -// - -import Foundation - -/// An object containing results for a post data request. -public struct MusicDataPostResponse { - /// The raw data returned by the Apple Music API endpoint - /// for the originating data request. - public let data: Data - - /// The URL response returned by the Apple Music API endpoint - /// for the originating data request. - public let urlResponse: HTTPURLResponse -}