func callAsFunction()

in Sources/UberAuth/Authorize/AuthorizationCodeResponseParser.swift [76:98]


    func callAsFunction(url: URL) -> Result<Client, UberAuthError> {
        guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
            return .failure(.invalidResponse)
        }
        
        if let authorizationCode = components.queryItems?.first(where: {
            $0.name == "code"
        })?.value {
            return .success(
                Client(authorizationCode: authorizationCode)
            )
        }
        
        let error: UberAuthError
        if let errorString = components.queryItems?.first(where: { $0.name == "error" })?.value,
           let oAuthError = OAuthError(rawValue: errorString) {
            error = .oAuth(oAuthError)
        } else {
            error = .invalidAuthCode
        }
        
        return .failure(error)
    }