Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit cd2c73d

Browse files
committed
💄 Run Swiftlint
1 parent cb37ba6 commit cd2c73d

File tree

7 files changed

+60
-84
lines changed

7 files changed

+60
-84
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
.library(
1212
name: "OpenGoogleSignInSDK",
1313
targets: ["OpenGoogleSignInSDK"]
14-
),
14+
)
1515
],
1616
dependencies: [],
1717
targets: [
@@ -22,6 +22,6 @@ let package = Package(
2222
.testTarget(
2323
name: "OpenGoogleSignInSDKTests",
2424
dependencies: ["OpenGoogleSignInSDK"]
25-
),
25+
)
2626
]
2727
)

Sources/OpenGoogleSignInSDK/Model/GoogleSignInError.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,20 @@ public enum GoogleSignInError: Error, Equatable {
55
case authenticationError(Error)
66
case invalidCode
77
case invalidResponse
8-
case invalidTokenRequest
98
case networkError(Error)
109
case tokenDecodingError(Error)
1110
case userCancelledSignInFlow
1211
case noProfile(Error)
1312
}
1413

15-
extension GoogleSignInError: LocalizedError {
16-
public var errorDescription: String? {
17-
switch self {
18-
case let .authenticationError(error):
19-
return "authenticationError, underlying error \(error.localizedDescription)"
20-
case .invalidCode:
21-
return "invalidCode"
22-
case .invalidResponse:
23-
return "invalidResponse"
24-
case .invalidTokenRequest:
25-
return "invalidTokenRequest"
26-
case let .networkError(error):
27-
return "network, underlying error \(error.localizedDescription)"
28-
case let .tokenDecodingError(error):
29-
return "tokenDecoding, underlying error \(error.localizedDescription)"
30-
case .userCancelledSignInFlow:
31-
return "userCancelledSignInFlow"
32-
case let .noProfile(error):
33-
return "noProfile, underlying error \(error.localizedDescription)"
34-
}
35-
}
36-
}
37-
3814
public func == (lhs: Error, rhs: Error) -> Bool {
3915
guard type(of: lhs) == type(of: rhs) else { return false }
4016
let error1 = lhs as NSError
4117
let error2 = rhs as NSError
4218
return error1.domain == error2.domain && error1.code == error2.code && "\(lhs)" == "\(rhs)"
4319
}
4420

45-
extension Equatable where Self : Error {
21+
extension Equatable where Self: Error {
4622
public static func == (lhs: Self, rhs: Self) -> Bool {
4723
lhs as Error == rhs as Error
4824
}

Sources/OpenGoogleSignInSDK/Model/GoogleUser.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,44 @@ import Foundation
22

33
/// Google sign-in user account.
44
public struct GoogleUser: Codable, Equatable {
5-
5+
66
/// User's profile info.
77
///
88
/// All the properties are optional according
99
/// to the [documentation](https://googleapis.dev/nodejs/googleapis/latest/oauth2/interfaces/Schema$Userinfo.html#info).
1010
public struct Profile: Codable, Equatable {
11-
11+
1212
/// The obfuscated ID of the user.
1313
public let id: String?
14-
14+
1515
/// The user's email address.
1616
public let email: String?
17-
17+
1818
/// Boolean flag which is true if the email address is verified.
1919
/// Always verified because we only return the user's primary email address.
2020
public let verifiedEmail: Bool?
21-
21+
2222
/// The user's full name.
2323
public let name: String?
24-
24+
2525
/// The user's first name.
2626
public let givenName: String?
27-
27+
2828
/// The user's last name.
2929
public let familyName: String?
30-
30+
3131
/// The user's gender.
3232
public let gender: String?
33-
33+
3434
/// URL of the profile page.
3535
public let link: URL?
36-
36+
3737
/// URL of the user's picture image.
3838
public let picture: URL?
39-
39+
4040
/// The hosted domain e.g. example.com if the user is Google apps user.
4141
public let hd: String?
42-
42+
4343
/// The user's preferred locale.
4444
public let locale: String?
4545
}

Sources/OpenGoogleSignInSDK/OpenGoogleSignInSDK.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,38 @@ public final class OpenGoogleSignIn: NSObject {
2121
// MARK: - Public properties
2222

2323
public weak var delegate: OpenGoogleSignInDelegate?
24-
24+
2525
/// The client ID of the app.
2626
/// It is required for communication with Google API to work.
2727
public var clientID: String = ""
28-
28+
2929
public var audience: String?
3030

3131
/// Client secret.
3232
/// It is only used when exchanging the authorization code for an access token.
3333
public var clientSecret: String = ""
34-
34+
3535
/// `URLSession` used to perform data tasks.
3636
public var session: URLSession = URLSession.shared
37-
37+
3838
/// Shared `OpenGoogleSignIn` instance
3939
public static let shared: OpenGoogleSignIn = OpenGoogleSignIn()
40-
40+
4141
/// API scopes requested by the app
4242
public var scopes: Set<GoogleSignInScope> = [.email, .openID, .profile]
43-
43+
4444
/// View controller to present Google sign-in flow.
4545
/// Needs to be set for presenting to work correctly.
46-
public weak var presentingViewController: ViewController? = nil
47-
46+
public weak var presentingViewController: ViewController?
47+
4848
// MARK: - Private properties
4949

5050
/// Session used to authenticate a user with Google sign-in.
51-
private var authenticationSession: ASWebAuthenticationSession? = nil
52-
51+
private var authenticationSession: ASWebAuthenticationSession?
52+
5353
/// Google API OAuth 2.0 token url.
5454
private static let tokenURL: URL? = URL(string: "https://www.googleapis.com/oauth2/v4/token")
55-
55+
5656
/// Google API profile url
5757
private static let profileURL: URL? = URL(string: "https://www.googleapis.com/oauth2/v1/userinfo?alt=json")
5858

@@ -79,7 +79,7 @@ public final class OpenGoogleSignIn: NSObject {
7979
URLQueryItem(name: "client_id", value: clientID),
8080
URLQueryItem(name: "redirect_uri", value: redirectURI),
8181
URLQueryItem(name: "response_type", value: "code"),
82-
URLQueryItem(name: "scope", value: scopes),
82+
URLQueryItem(name: "scope", value: scopes)
8383
]
8484

8585
return components.url!
@@ -144,7 +144,7 @@ public final class OpenGoogleSignIn: NSObject {
144144
}
145145

146146
// MARK: - Private helpers
147-
147+
148148
/// Decodes `GoogleUser` from OAuth 2.0 response.
149149
private func decodeUser(from data: Data) throws -> GoogleUser {
150150
try JSONDecoder.app.decode(GoogleUser.self, from: data)
@@ -195,7 +195,7 @@ public final class OpenGoogleSignIn: NSObject {
195195
let profile = try? JSONDecoder.app.decode(GoogleUser.Profile.self, from: data)
196196
user.profile = profile
197197
completion(.success(user))
198-
198+
199199
case let .failure(error):
200200
completion(.failure(.noProfile(error)))
201201
}
@@ -219,14 +219,14 @@ public final class OpenGoogleSignIn: NSObject {
219219
}
220220
task.resume()
221221
}
222-
222+
223223
/// Returns `code` parsed from provided `redirectURL`.
224224
private func parseCode(from redirectURL: URL) -> String? {
225225
let components = URLComponents(url: redirectURL, resolvingAgainstBaseURL: false)
226226

227227
return components?.queryItems?.first(where: { $0.name == "code" })?.value
228228
}
229-
229+
230230
/// Returns `URLRequest` to retrieve Google sign-in OAuth 2.0 token using arameters provided by the app.
231231
private func makeTokenRequest(with code: String) -> URLRequest? {
232232
guard let tokenURL = OpenGoogleSignIn.tokenURL else { return nil }
@@ -242,7 +242,7 @@ public final class OpenGoogleSignIn: NSObject {
242242
"grant_type": "authorization_code",
243243
"redirect_uri": redirectURI
244244
]
245-
245+
246246
if let audience = audience {
247247
parameters["audience"] = audience
248248
}
@@ -252,7 +252,7 @@ public final class OpenGoogleSignIn: NSObject {
252252
.joined(separator: "&")
253253

254254
request.httpBody = body.data(using: .utf8)
255-
255+
256256
return request
257257
}
258258

Tests/OpenGoogleSignInSDKTests/Mocks/MockOpenGoogleSignInDelegate.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import XCTest
44
final class MockOpenGoogleSignInDelegate: OpenGoogleSignInDelegate {
55
var user: GoogleUser?
66
var error: GoogleSignInError?
7-
7+
88
private var expectation: XCTestExpectation?
99
private let testCase: XCTestCase
10-
10+
1111
init(testCase: XCTestCase) {
1212
self.testCase = testCase
1313
}
14-
14+
1515
func expectSignInFinish() {
1616
expectation = testCase.expectation(description: "Expect sign-in flow to finish")
1717
}
18-
18+
1919
// MARK: - OAuthGoogleSignInDelegate
20-
20+
2121
func sign(didSignInFor user: GoogleUser?, withError error: GoogleSignInError?) {
2222
self.user = user
2323
self.error = error

Tests/OpenGoogleSignInSDKTests/Mocks/MockURLSession.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import Foundation
33
final class MockURLSession: URLSession {
44
var data: Data?
55
var error: Error?
6-
6+
77
override func dataTask(
88
with request: URLRequest,
99
completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void
1010
) -> URLSessionDataTask {
1111
let data = self.data
1212
let error = self.error
13-
13+
1414
return MockURLSessionDataTask {
1515
completionHandler(data, nil, error)
1616
}

Tests/OpenGoogleSignInSDKTests/OpenGoogleSignInSDKTests.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,45 @@ final class OpenGoogleSignInTests: XCTestCase {
55
var sharedInstance: OpenGoogleSignIn!
66
var mockDelegate: MockOpenGoogleSignInDelegate!
77
var session: MockURLSession!
8-
8+
99
override func setUp() {
1010
super.setUp()
1111

1212
sharedInstance = OpenGoogleSignIn.shared
13-
13+
1414
mockDelegate = MockOpenGoogleSignInDelegate(testCase: self)
1515
sharedInstance.delegate = mockDelegate
16-
16+
1717
session = MockURLSession()
1818
}
19-
19+
2020
override func tearDown() {
2121
session = nil
2222

2323
super.tearDown()
2424
}
25-
25+
2626
func test_invalidCodeError_isThrown() {
2727
// Given
2828
let url = URL(string: "https://google.com")!
2929
mockDelegate.expectSignInFinish()
30-
30+
3131
// When
3232
sharedInstance.handle(url)
3333
waitForExpectations(timeout: 0.5)
34-
34+
3535
// Then
3636
XCTAssertEqual(mockDelegate.error, GoogleSignInError.invalidCode)
3737
XCTAssertNil(mockDelegate.user)
3838
}
39-
39+
4040
func test_invalidResponseError_isThrown() {
4141
// Given
4242
let url = URL(string: "https://google.com?code=1234")!
4343
mockDelegate.expectSignInFinish()
4444
session.data = nil
4545
sharedInstance.session = session
46-
46+
4747
// When
4848
sharedInstance.handle(url)
4949
waitForExpectations(timeout: 0.5)
@@ -52,52 +52,52 @@ final class OpenGoogleSignInTests: XCTestCase {
5252
XCTAssertEqual(mockDelegate.error, GoogleSignInError.invalidResponse)
5353
XCTAssertNil(mockDelegate.user)
5454
}
55-
55+
5656
func test_validUserIsReceived() {
5757
// Given
5858
let url = URL(string: "https://google.com?code=1234")!
5959
mockDelegate.expectSignInFinish()
60-
60+
6161
let user = mockUser()
6262
let encoder = JSONEncoder()
6363
guard let data = try? encoder.encode(user) else { return }
64-
64+
6565
session.data = data
6666
sharedInstance.session = session
67-
67+
6868
// When
6969
sharedInstance.handle(url)
7070
waitForExpectations(timeout: 0.5)
71-
71+
7272
// Then
7373
XCTAssertNil(mockDelegate.error)
7474
XCTAssertNotNil(mockDelegate.user)
7575
}
76-
76+
7777
// Since `URL` has optional initializer we need to
7878
// check if the URL provided by us is valid and
7979
// therefore we don't need to worry about this edge case.
8080
func test_tokenRequest_isValid() {
8181
// When
8282
let request = sharedInstance.makeTokenRequest(with: "code")
83-
83+
8484
// Then
8585
XCTAssertNotNil(request)
8686
}
87-
87+
8888
// Since `URL` has optional initializer we need to
8989
// check if the URL provided by us is valid and
9090
// therefore we don't need to worry about this edge case.
9191
func test_profileRequest_isValid() {
9292
// Given
9393
let user = mockUser()
94-
94+
9595
// Then
9696
XCTAssertNotNil(sharedInstance.makeProfileRequest(user: user))
9797
}
98-
98+
9999
// MARK: - Private helpers
100-
100+
101101
private func mockUser() -> GoogleUser {
102102
GoogleUser(
103103
accessToken: "accessToken",

0 commit comments

Comments
 (0)