Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vespinola committed Jun 25, 2024
1 parent 8f259c4 commit d325fb8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 35 deletions.
2 changes: 2 additions & 0 deletions mobile-courier-app/Data/Networking/APIRequestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ final class APIRequestClient: NSObject, APIRequestClientProtocol {
private lazy var delegate: URLSessionDelegate? = CustomSessionDelegate()

func performRequest<T: Decodable>(endpoint: Endpoint, decoder: JSONDecoder = JSONDecoder()) async throws -> T {
#if DEBUG
if let mockfile = endpoint.mockFile, let fileUrl = Bundle.main.url(forResource: mockfile, withExtension: "json") {
decoder.keyDecodingStrategy = .convertFromSnakeCase
let decodedData = try decoder.decode(T.self, from: Data(contentsOf: fileUrl))
try? await Task.sleep(nanoseconds: 2 * 1_000_000_000)
return decodedData
}
#endif

guard let urlRequest = try? endpoint.asRequest() else {
throw APIErrorMessage.invalidRequest
Expand Down
24 changes: 0 additions & 24 deletions mobile-courier-app/Data/Networking/CustomSessionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@
import Foundation

final class CustomSessionDelegate: NSObject, URLSessionDataDelegate {
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
do {
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
let jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted])

if let jsonString = String(data: jsonData, encoding: .utf8) {
let urlString = dataTask.currentRequest?.url?.absoluteString ?? "Unknown URL"
print("Data received from '\(urlString)' ➡️ \n\(jsonString)")
}
} catch {
print("Failed to parse JSON: \(error.localizedDescription)")
}
}

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let error = error {
print("Error: \(error.localizedDescription)")
} else {
print("Request completed successfully.")
}
}
}

extension CustomSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
let serverTrust = challenge.protectionSpace.serverTrust else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension AddressEndpoints: Endpoint {
}

var path: String {
"/frontliner-middleware/api/direccion"
"/direccion"
}

var body: [AnyHashable: Any]? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension AuthEndpoints: Endpoint {

var requestType: RequestType {
switch self {
case .login(email: _, password: _):
case .login:
return .post
default:
return .get
Expand All @@ -29,8 +29,8 @@ extension AuthEndpoints: Endpoint {

var path: String {
switch self {
case .login(email: _, password: _):
return "/frontliner-middleware/api/ingresar"
case .login:
return "/ingresar"
default:
return ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protocol Endpoint {

extension Endpoint {
var scheme: String { "https" }
var host: String { "frontliner.com.py" }
var host: String { "justacourier.com.py" }
var port: Int { 8449 }
var headers: [String: String] {
var internalHeaders = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ enum PackageEndpoints {
extension PackageEndpoints: Endpoint {
var mockFile: String? {
switch self {
case .withdrawn:
"WithdrawnPackages"
case .forWithdrawl:
"PackagesForWithdrawl"
case .withdrawn:
"WithdrawnPackages"
case .forWithdrawl:
"PackagesForWithdrawl"
}
}

Expand All @@ -29,9 +29,9 @@ extension PackageEndpoints: Endpoint {
var path: String {
switch self {
case .withdrawn:
"/frontliner-middleware/api/paquetesRetirados"
"/paquetesRetirados"
case .forWithdrawl:
"/frontliner-middleware/api/paquetesPendientes"
"/paquetesPendientes"
}
}

Expand Down

0 comments on commit d325fb8

Please sign in to comment.