Skip to content

Commit

Permalink
update(26718): adding builder to instantiate SDK (#5)
Browse files Browse the repository at this point in the history
* update: adding build to instantiate SDK

* typo fixed

* typo fixed
  • Loading branch information
mejiagarcia committed Aug 22, 2022
1 parent 802df05 commit 70e355a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 42 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import TwilioVerifySNA
2. Instantiate the SDK

```swift
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNASession()
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNABuilder.build()
```

3. Process the SNA URL by calling the method:
Expand Down Expand Up @@ -156,7 +156,7 @@ import UIKit
import TwilioVerifySNA

class ViewController: UIViewController {
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNASession()
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNABuilder.build()

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -226,10 +226,10 @@ To be added once the sample backend gets released.
- CA - Bell, Rogers and Telus
- Set the country code (only US during pilot stage)
- Set your sample backend url
- Subit the form by using the CTA button
- Submit the form by using the CTA button

**Expected behavior:**
The app will ask the network carrier if the provided phone number is the same used on the network request, if the phone number is correct, then the app will redirect to a sucess screen.
The app will ask the network carrier if the provided phone number is the same used on the network request, if the phone number is correct, then the app will redirect to a success screen.

<a name='Errors'></a>

Expand Down
2 changes: 1 addition & 1 deletion Sources/Documentation.docc/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import UIKit
import TwilioVerifySNA

class ViewController: UIViewController {
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNASession()
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNABuilder.build()

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Domain/TwilioVerifySNA/TwilioVerifySNA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import Foundation

public typealias ProcessURLResult = Result<Void, TwilioVerifySNASession.Error>
public typealias ProcessURLResult = Result<Void, TwilioVerifySNAError>
public typealias ProcessURLCallback = (ProcessURLResult) -> Void

public protocol TwilioVerifySNA {
Expand Down
14 changes: 14 additions & 0 deletions Sources/Domain/TwilioVerifySNA/TwilioVerifySNABuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation
import SNANetworking

public class TwilioVerifySNABuilder {
public static func build(
requestManager: RequestManagerProtocol = RequestManager(
networkProvider: NetworkRequestProvider(
cellularSession: CellularSession()
)
)
) -> TwilioVerifySNA {
TwilioVerifySNASession(requestManager: requestManager)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,44 @@

import Foundation

// MARK: - Associated errors

extension TwilioVerifySNASession {

public enum Error: TwilioVerifySNAErrorProtocol, Equatable {
case cellularNetworkNotAvailable
case requestError(cause: RequestManager.RequestError)

public var description: String {
switch self {
case .requestError(let cause):
return """
public enum TwilioVerifySNAError: TwilioVerifySNAErrorProtocol, Equatable {
case cellularNetworkNotAvailable
case requestError(cause: RequestManager.RequestError)

public var description: String {
switch self {
case .requestError(let cause):
return """
Error processing the SNAURL request,
cause: \(cause.errorDescription ?? "Undefined")
"""

case .cellularNetworkNotAvailable:
return "Cellular network not available"
}
case .cellularNetworkNotAvailable:
return "Cellular network not available"
}
}

public var technicalError: String {
switch self {
case .requestError(let cause):
return """
public var technicalError: String {
switch self {
case .requestError(let cause):
return """
Request manager got an error processing the SNAURL request,
cause: \(cause.technicalError)
"""

case .cellularNetworkNotAvailable:
return """
case .cellularNetworkNotAvailable:
return """
"The network monitor established that a cellular network is not available,
if you are running on a simulator or a device with no sim card for development
use the `setEnvironment()` method.
"""
}
}
}

public static func == (
lhs: TwilioVerifySNASession.Error,
rhs: TwilioVerifySNASession.Error
) -> Bool {
String(describing: lhs) == String(describing: rhs)
}
public static func == (
lhs: TwilioVerifySNAError,
rhs: TwilioVerifySNAError
) -> Bool {
String(describing: lhs) == String(describing: rhs)
}
}
10 changes: 4 additions & 6 deletions Sources/Domain/TwilioVerifySNA/TwilioVerifySNASession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation
import Network
import SNANetworking

open class TwilioVerifySNASession: TwilioVerifySNA {
final class TwilioVerifySNASession: TwilioVerifySNA {

// MARK: - Properties

Expand Down Expand Up @@ -58,9 +58,7 @@ open class TwilioVerifySNASession: TwilioVerifySNA {

// MARK: - Class lifecycle

/// Initializer: You could inject your own dependencies here, although this is only recommended for unit testing,
/// if you change any of the implementations down here, we can't guarantee the proper functionality of the SDK.
public init(
init(
requestManager: RequestManagerProtocol = RequestManager(
networkProvider: NetworkRequestProvider(
cellularSession: CellularSession()
Expand All @@ -82,7 +80,7 @@ open class TwilioVerifySNASession: TwilioVerifySNA {
/// - Parameters:
/// - url: SNA URL provided by your backend.
/// - onComplete: Closure with `Result<Void, TwilioVerifySNASession.Error>`.
public func processURL(
func processURL(
_ url: String,
onComplete: @escaping ProcessURLCallback
) {
Expand All @@ -93,7 +91,7 @@ open class TwilioVerifySNASession: TwilioVerifySNA {

/// `processURL` method async support.
@available(iOS 13, *)
public func processURL(_ url: String) async -> ProcessURLResult {
func processURL(_ url: String) async -> ProcessURLResult {
return await withCheckedContinuation { continuation in
processURL(url) { result in
continuation.resume(returning: result)
Expand Down
4 changes: 3 additions & 1 deletion Tests/Domain/TwilioVerifySNASessionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class TwilioVerifySNASessionTests: XCTestCase {

func test_invalidNetworkStatus_shouldResponseWithExpectedError() async {
// Arrange
let expectedError: TwilioVerifySNASession.Error = .cellularNetworkNotAvailable
let expectedError: TwilioVerifySNAError = .cellularNetworkNotAvailable
let mockUrl = "https://google.com"
sut.set(networkStatus: .disconnected)

Expand Down Expand Up @@ -66,6 +66,8 @@ final class TwilioVerifySNASessionTests: XCTestCase {
case .failure(.requestError(let cause)):
// Assert
XCTAssertEqual(cause, expectedError)
XCTAssertFalse(expectedError.description.isEmpty)
XCTAssertFalse(expectedError.technicalError.isEmpty)

default:
XCTFail("Unexpected error received ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class PhoneNumberViewController: UIViewController {
in the best practices you will probably create
this instance on your ViewModel/Presenter or logic layer
*/
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNASession()
private lazy var twilioVerify: TwilioVerifySNA = TwilioVerifySNABuilder.build()

/**
Network layer to communicate with the backend: (not required for your SDK implementation)
Expand Down

0 comments on commit 70e355a

Please sign in to comment.