-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore/Remove PovioKit dependency (#30)
- Loading branch information
Showing
10 changed files
with
118 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// HttpClient.swift | ||
// PovioKitAuth | ||
// | ||
// Created by Borut Tomazin on 22/05/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct HttpClient { | ||
func request<D: Decodable>( | ||
method: String, | ||
url: URL, | ||
headers: [String: String]?, | ||
decodeTo decode: D.Type, | ||
with decoder: JSONDecoder = .init() | ||
) async throws -> D { | ||
var urlRequest = URLRequest(url: url) | ||
urlRequest.httpMethod = method | ||
urlRequest.allHTTPHeaderFields = headers | ||
|
||
let (data, response) = try await URLSession.shared.data(for: urlRequest) | ||
|
||
if let httpResponse = response as? HTTPURLResponse, | ||
!(200...299).contains(httpResponse.statusCode) { | ||
throw NSError(domain: "HTTP Error", code: httpResponse.statusCode, userInfo: nil) | ||
} | ||
|
||
return try decoder.decode(decode, from: data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// URL+PovioKitAuth.swift | ||
// PovioKitAuth | ||
// | ||
// Created by Borut Tomazin on 22/05/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension URL: ExpressibleByStringLiteral { | ||
public init(stringLiteral value: String) { | ||
guard let url = URL(string: value) else { | ||
fatalError("Invalid URL string!") | ||
} | ||
self = url | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters