diff --git a/Example/Shared/Global/Constants.swift b/Example/Shared/Global/Constants.swift index 83fb2d1..fd85bc5 100644 --- a/Example/Shared/Global/Constants.swift +++ b/Example/Shared/Global/Constants.swift @@ -19,7 +19,8 @@ import Foundation /// Global instance of Atom networking library. let atom: Atom = { - let configuration = ServiceConfiguration(multipathServiceType: .handover) + let timeout = ServiceConfiguration.Timeout(request: 60, resource: 60) + let configuration = ServiceConfiguration(multipathServiceType: .handover, timeout: timeout) let atom = Atom(serviceConfiguration: configuration) atom.log = true diff --git a/Framework/Atom/Service/ServiceConfiguration+Timeout.swift b/Framework/Atom/Service/ServiceConfiguration+Timeout.swift index 4c6dec9..974fd9f 100644 --- a/Framework/Atom/Service/ServiceConfiguration+Timeout.swift +++ b/Framework/Atom/Service/ServiceConfiguration+Timeout.swift @@ -16,13 +16,22 @@ import Foundation -internal extension ServiceConfiguration { +public extension ServiceConfiguration { /// Model object representing `URLSessionConfiguration` timeout intervals. struct Timeout { /// The timeout interval to use when waiting for additional data. - internal let request = 30.0 + internal var request: Double /// The maximum amount of time that a resource request should be allowed to take. - internal let resource = 30.0 + internal var resource: Double + + /// Object to set `URLSessionConfiguration` timeouts + /// - Parameters: + /// - request: Double - The timeout interval to use when waiting for additional data. + /// - resource: Double - The maximum amount of time that a resource request should be allowed to take. + public init(request: Double = 30.0, resource: Double = 30.0) { + self.request = request + self.resource = resource + } } } diff --git a/Framework/Atom/Service/ServiceConfiguration.swift b/Framework/Atom/Service/ServiceConfiguration.swift index b387ab2..dce92c6 100644 --- a/Framework/Atom/Service/ServiceConfiguration.swift +++ b/Framework/Atom/Service/ServiceConfiguration.swift @@ -74,13 +74,15 @@ public final class ServiceConfiguration { /// - decoder: The `JSONDecoder` for decoding data into models. /// - dispatchQueue: The queue to dispatch `Result` object on. /// - multipathServiceType: The service type that specifies the Multipath TCP connection policy for transmitting data over Wi-Fi and cellular interfaces. - public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, multipathServiceType: MultipathServiceType = .none) { + /// - timeout: Timeout interval needed for URLSessionConfiguration. + + public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, multipathServiceType: MultipathServiceType = .none, timeout: Timeout = Timeout()) { self.authenticationMethod = authenticationMethod self.configuration = configuration self.decoder = decoder self.dispatchQueue = dispatchQueue self.multipathServiceType = multipathServiceType - self.timeout = Timeout() + self.timeout = timeout } #else @@ -92,12 +94,13 @@ public final class ServiceConfiguration { /// - configuration: The `ServiceConfiguration.Configuration` - default value is `.ephemeral`. /// - decoder: The `JSONDecoder` for decoding data into models. /// - dispatchQueue: The queue to dispatch `Result` object on. - public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main) { + /// - timeout: Timeout interval needed for URLSessionConfiguration. + public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, timeout: Timeout = Timeout()) { self.authenticationMethod = authenticationMethod self.configuration = configuration self.decoder = decoder self.dispatchQueue = dispatchQueue - self.timeout = Timeout() + self.timeout = timeout } #endif } diff --git a/Framework/AtomTests/Models/ServiceConfigurationTests.swift b/Framework/AtomTests/Models/ServiceConfigurationTests.swift index 774bfe2..29d8712 100644 --- a/Framework/AtomTests/Models/ServiceConfigurationTests.swift +++ b/Framework/AtomTests/Models/ServiceConfigurationTests.swift @@ -26,4 +26,15 @@ internal class ServiceConfigurationTests: BaseCase { XCTAssertEqual(serviceConfiguration.dispatchQueue, .main) XCTAssertEqual(serviceConfiguration.configuration, .ephemeral) } + + internal func testServiceConfigurationInitializationWithTimeout() { + // Given, When + let timeout = ServiceConfiguration.Timeout(request: 60, resource: 60) + let serviceConfiguration = ServiceConfiguration(timeout: timeout) + + // Then + XCTAssertEqual(serviceConfiguration.timeout.request, 60) + XCTAssertEqual(serviceConfiguration.timeout.resource, 60) + } + }