mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-23 08:09:41 +01:00
45 lines
1.1 KiB
Swift
45 lines
1.1 KiB
Swift
//
|
|
// URLRequest+ReaderAPI.swift
|
|
//
|
|
//
|
|
// Created by Brent Simmons on 4/6/24.
|
|
//
|
|
|
|
import Foundation
|
|
import Secrets
|
|
import Web
|
|
|
|
extension URLRequest {
|
|
|
|
init(url: URL, readerAPICredentials: Credentials?, conditionalGet: HTTPConditionalGetInfo? = nil) {
|
|
|
|
self.init(url: url)
|
|
|
|
guard let credentials = readerAPICredentials else {
|
|
return
|
|
}
|
|
|
|
let credentialsType = credentials.type
|
|
precondition(credentialsType == .readerBasic || credentialsType == .readerAPIKey)
|
|
|
|
if credentialsType == .readerBasic {
|
|
|
|
setValue(MimeType.formURLEncoded, forHTTPHeaderField: "Content-Type")
|
|
httpMethod = "POST"
|
|
var postData = URLComponents()
|
|
postData.queryItems = [
|
|
URLQueryItem(name: "Email", value: credentials.username),
|
|
URLQueryItem(name: "Passwd", value: credentials.secret)
|
|
]
|
|
httpBody = postData.enhancedPercentEncodedQuery?.data(using: .utf8)
|
|
|
|
} else if credentialsType == .readerAPIKey {
|
|
|
|
let auth = "GoogleLogin auth=\(credentials.secret)"
|
|
setValue(auth, forHTTPHeaderField: HTTPRequestHeader.authorization)
|
|
}
|
|
|
|
conditionalGet?.addRequestHeadersToURLRequest(&self)
|
|
}
|
|
}
|