Skip to content

Commit

Permalink
Headers update.
Browse files Browse the repository at this point in the history
  • Loading branch information
borut-t committed May 27, 2024
1 parent 70d9456 commit dd8a2bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Sources/LinkedIn/API/LinkedInAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public extension LinkedInAPI {
let response = try await client.request(
method: "POST",
url: url,
headers: [.init(name: "Content-Type", value: "application/x-www-form-urlencoded")]
headers: ["Content-Type": "application/x-www-form-urlencoded"]
)

let decoder = JSONDecoder()
Expand All @@ -61,7 +61,7 @@ public extension LinkedInAPI {
let response = try await client.request(
method: "GET",
url: url,
headers: [.init(name: "Authorization", value: "Bearer \(request.token)")]
headers: ["Authorization": "Bearer \(request.token)"]
)

let decoder = JSONDecoder()
Expand All @@ -78,7 +78,7 @@ public extension LinkedInAPI {
let response = try await client.request(
method: "GET",
url: url,
headers: [.init(name: "Authorization", value: "Bearer \(request.token)")]
headers: ["Authorization": "Bearer \(request.token)"]
)

let decoded = try JSONDecoder().decode(LinkedInEmailResponse.self, from: response)
Expand Down
13 changes: 2 additions & 11 deletions Sources/LinkedIn/Core/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import Foundation

struct HttpClient {
func request(method: String, url: URL, headers: [Header]) async throws -> Data {
func request(method: String, url: URL, headers: [String: String]?) async throws -> Data {
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = method
headers.forEach {
urlRequest.setValue($0.value, forHTTPHeaderField: $0.name)
}
urlRequest.allHTTPHeaderFields = headers

let (data, response) = try await URLSession.shared.data(for: urlRequest)

Expand All @@ -26,10 +24,3 @@ struct HttpClient {
return data
}
}

extension HttpClient {
struct Header {
let name: String
let value: String
}
}

0 comments on commit dd8a2bc

Please sign in to comment.