Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yllfejziu committed Nov 15, 2024
1 parent 4cf6b2f commit 987e535
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
37 changes: 17 additions & 20 deletions Sources/Core/PersonNameComponents+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,31 @@ 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)"
}
}

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
}
}
5 changes: 4 additions & 1 deletion Sources/Facebook/FacebookAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Google/GoogleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
5 changes: 4 additions & 1 deletion Sources/LinkedIn/LinkedInAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 987e535

Please sign in to comment.