Skip to content

Commit

Permalink
fix: deprecate method of passing organization name via login config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-londar authored Oct 31, 2023
1 parent ec3a265 commit ef999aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private let URLSchemeDocumentationLink = "https://developer.apple.com/documentat
var clientSecret: String
var scope: String
var redirectURI: String
var organizationName: String?

public convenience init(clientId: String, clientSecret: String, scope: String) throws {
guard let redirectURI = Bundle.main.urlSchemes?.first else { throw NSError(domain: "Application do not support any URL Scheme. To setup it, please check - \(URLSchemeDocumentationLink)", code: defaultCrowdinErrorCode, userInfo: nil) }
Expand All @@ -24,7 +25,18 @@ private let URLSchemeDocumentationLink = "https://developer.apple.com/documentat
try self.init(with: clientId, clientSecret: clientSecret, scope: scope, redirectURI: redirectURI)
}

private init(with clientId: String, clientSecret: String, scope: String, redirectURI: String) throws {
@available(*, deprecated)
public convenience init(clientId: String, clientSecret: String, scope: String, organizationName: String? = nil) throws {
guard let redirectURI = Bundle.main.urlSchemes?.first else { throw NSError(domain: "Application do not support any URL Scheme. To setup it, please check - \(URLSchemeDocumentationLink)", code: defaultCrowdinErrorCode, userInfo: nil) }
try self.init(with: clientId, clientSecret: clientSecret, scope: scope, redirectURI: redirectURI, organizationName: organizationName)
}

@available(*, deprecated)
public convenience init(clientId: String, clientSecret: String, scope: String, redirectURI: String, organizationName: String? = nil) throws {
try self.init(with: clientId, clientSecret: clientSecret, scope: scope, redirectURI: redirectURI, organizationName: organizationName)
}

private init(with clientId: String, clientSecret: String, scope: String, redirectURI: String, organizationName: String? = nil) throws {
guard !clientId.isEmpty else { throw NSError(domain: "clientId could not be empty.", code: defaultCrowdinErrorCode, userInfo: nil) }
self.clientId = clientId
guard !clientSecret.isEmpty else { throw NSError(domain: "clientSecret could not be empty.", code: defaultCrowdinErrorCode, userInfo: nil) }
Expand All @@ -34,5 +46,6 @@ private let URLSchemeDocumentationLink = "https://developer.apple.com/documentat
guard !redirectURI.isEmpty else { throw NSError(domain: "redirectURI could not be empty.", code: defaultCrowdinErrorCode, userInfo: nil) }
guard let urlSchemes = Bundle.main.urlSchemes, urlSchemes.contains(redirectURI) else { throw NSError(domain: "Application supported url schemes should contain \(redirectURI)", code: defaultCrowdinErrorCode, userInfo: nil) }
self.redirectURI = redirectURI
self.organizationName = organizationName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ extension CrowdinSDKConfig {
}
}

public func with(loginConfig: CrowdinLoginConfig) -> Self {
self.loginConfig = loginConfig
public func with(loginConfig: CrowdinLoginConfig) -> Self {
self.loginConfig = loginConfig
if let organizationName = loginConfig.organizationName {
self.crowdinProviderConfig?.organizationName = organizationName
}
return self
}
}

0 comments on commit ef999aa

Please sign in to comment.