Skip to content

Commit

Permalink
Fixup - reorder & rename constructURL methods in APIClient
Browse files Browse the repository at this point in the history
  • Loading branch information
scannillo committed Aug 16, 2023
1 parent 4abe12e commit 0695f72
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Sources/CorePayments/Networking/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class APIClient {

/// :nodoc:
public func fetch(request: RESTRequest) async throws -> HTTPResponse {
let url = try constructURL(path: request.path, queryParameters: request.queryParameters ?? [:])
let url = try constructRestURL(path: request.path, queryParameters: request.queryParameters ?? [:])

let base64EncodedCredentials = Data(coreConfig.clientID.appending(":").utf8).base64EncodedString()

Expand Down Expand Up @@ -71,19 +71,7 @@ public class APIClient {

// MARK: - Private Methods

private func constructGraphQLURL(queryName: String? = nil) throws -> URL {
guard let queryName else {
return coreConfig.environment.graphQLURL
}

if let url = URL(string: coreConfig.environment.graphQLURL.absoluteString + "?" + queryName) {
return url
} else {
throw CorePaymentsError.urlEncodingFailed
}
}

private func constructURL(path: String, queryParameters: [String: String]) throws -> URL {
private func constructRestURL(path: String, queryParameters: [String: String]) throws -> URL {
let urlString = coreConfig.environment.baseURL.appendingPathComponent(path)
var urlComponents = URLComponents(url: urlString, resolvingAgainstBaseURL: false)

Expand All @@ -97,4 +85,16 @@ public class APIClient {

return url
}

private func constructGraphQLURL(queryName: String? = nil) throws -> URL {
guard let queryName else {
return coreConfig.environment.graphQLURL
}

if let url = URL(string: coreConfig.environment.graphQLURL.absoluteString + "?" + queryName) {
return url
} else {
throw CorePaymentsError.urlEncodingFailed
}
}
}

0 comments on commit 0695f72

Please sign in to comment.