From 987e535269cfa3bcecc3e32cc1fbf92db9e3213b Mon Sep 17 00:00:00 2001 From: Yll Fejziu Date: Fri, 15 Nov 2024 13:13:28 +0100 Subject: [PATCH] Minor refactor --- .../Core/PersonNameComponents+Extension.swift | 37 +++++++++---------- Sources/Facebook/FacebookAuthenticator.swift | 5 ++- Sources/Google/GoogleAuthenticator.swift | 2 +- Sources/LinkedIn/LinkedInAuthenticator.swift | 5 ++- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Sources/Core/PersonNameComponents+Extension.swift b/Sources/Core/PersonNameComponents+Extension.swift index b0a0787..ec508e5 100644 --- a/Sources/Core/PersonNameComponents+Extension.swift +++ b/Sources/Core/PersonNameComponents+Extension.swift @@ -10,10 +10,10 @@ import Foundation public extension PersonNameComponents { var name: String? { - guard let givenName = givenName else { + guard let givenName else { return familyName } - guard let familyName = familyName else { + guard let familyName else { return givenName } return "\(givenName) \(familyName)" @@ -21,23 +21,20 @@ public extension PersonNameComponents { } public extension PersonNameComponents { - static func create( - namePrefix: String? = .none, - middleName: String? = .none, - givenName: String? = .none, - familyName: String? = .none, - nameSuffix: String? = .none, - nickname: String? = .none, - phoneticRepresentation: PersonNameComponents? = .none - ) -> PersonNameComponents { - var components = PersonNameComponents() - components.namePrefix = namePrefix - components.familyName = familyName - components.middleName = middleName - components.givenName = givenName - components.nameSuffix = nameSuffix - components.nickname = nickname - components.phoneticRepresentation = phoneticRepresentation - return components + init(namePrefix: String? = .none, + middleName: String? = .none, + givenName: String? = .none, + familyName: String? = .none, + nameSuffix: String? = .none, + nickname: String? = .none, + phoneticRepresentation: PersonNameComponents? = .none) { + self.init() + self.namePrefix = namePrefix + self.familyName = familyName + self.middleName = middleName + self.givenName = givenName + self.nameSuffix = nameSuffix + self.nickname = nickname + self.phoneticRepresentation = phoneticRepresentation } } diff --git a/Sources/Facebook/FacebookAuthenticator.swift b/Sources/Facebook/FacebookAuthenticator.swift index de4c1b2..f133815 100644 --- a/Sources/Facebook/FacebookAuthenticator.swift +++ b/Sources/Facebook/FacebookAuthenticator.swift @@ -110,7 +110,10 @@ private extension FacebookAuthenticator { let authResponse = Response( userId: object.id, token: token.tokenString, - nameComponents: .create(givenName: object.firstName, familyName: object.lastName), + nameComponents: PersonNameComponents( + givenName: object.firstName, + familyName: object.lastName + ), email: object.email, expiresAt: token.expirationDate ) diff --git a/Sources/Google/GoogleAuthenticator.swift b/Sources/Google/GoogleAuthenticator.swift index 25db965..367eb46 100644 --- a/Sources/Google/GoogleAuthenticator.swift +++ b/Sources/Google/GoogleAuthenticator.swift @@ -107,7 +107,7 @@ private extension GIDGoogleUser { idToken: idToken?.tokenString, accessToken: accessToken.tokenString, refreshToken: refreshToken.tokenString, - nameComponents: PersonNameComponents.create( + nameComponents: PersonNameComponents( givenName: profile?.givenName, familyName: profile?.familyName ), diff --git a/Sources/LinkedIn/LinkedInAuthenticator.swift b/Sources/LinkedIn/LinkedInAuthenticator.swift index 70afef5..e2a8aa1 100644 --- a/Sources/LinkedIn/LinkedInAuthenticator.swift +++ b/Sources/LinkedIn/LinkedInAuthenticator.swift @@ -42,7 +42,10 @@ extension LinkedInAuthenticator: Authenticator { return Response( userId: profileResponse.id, token: authResponse.accessToken, - nameComponents: .create(givenName: profileResponse.localizedFirstName, familyName: profileResponse.localizedLastName), + nameComponents: PersonNameComponents( + givenName: profileResponse.localizedFirstName, + familyName: profileResponse.localizedLastName + ), email: emailResponse.emailAddress, expiresAt: authResponse.expiresIn )