DefaultNetworkService refactor

This commit is contained in:
Alexey Gerasimov 2018-04-06 14:19:09 +03:00
parent c9697df89e
commit 6d51575c38
4 changed files with 13 additions and 48 deletions

View File

@ -1,5 +1,9 @@
# Changelog
### 0.2.6
- **Update**: `DefaultNetworkService` supported `NetworkServiceConfiguration`
### 0.2.5
- **Add**: Methods to notify when biometrics auth begins and ends.

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LeadKitAdditions"
s.version = "0.2.5"
s.version = "0.2.6"
s.summary = "iOS framework with a bunch of tools for rapid development"
s.homepage = "https://github.com/TouchInstinct/LeadKitAdditions"
s.license = "Apache License, Version 2.0"

View File

@ -6,9 +6,9 @@ PODS:
- IDZSwiftCommonCrypto (0.10.0)
- InputMask (3.0.0)
- KeychainAccess (3.1.0)
- LeadKit (0.7.5):
- LeadKit/Core (= 0.7.5)
- LeadKit/Core (0.7.5):
- LeadKit (0.7.6):
- LeadKit/Core (= 0.7.6)
- LeadKit/Core (0.7.6):
- CocoaLumberjack/Swift (~> 3.4)
- ObjectMapper (~> 3.0)
- RxAlamofire (~> 4.1)
@ -17,7 +17,7 @@ PODS:
- SwiftDate (~> 4.5)
- TableKit (~> 2.6)
- UIScrollView-InfiniteScroll (~> 1.0.0)
- LeadKit/Core-iOS-Extension (0.7.5):
- LeadKit/Core-iOS-Extension (0.7.6):
- CocoaLumberjack/Swift (~> 3.4)
- ObjectMapper (~> 3.0)
- RxAlamofire (~> 4.1)
@ -56,7 +56,7 @@ SPEC CHECKSUMS:
IDZSwiftCommonCrypto: 4eef2c46e262dfbcbc1fd76365e066336680ad7d
InputMask: 8b5c42acac19cd48fe664b739f30995103b75e75
KeychainAccess: 94c5540b32eabf7bc32bfb976a268e8ea05fd6da
LeadKit: 1295888d8ef6c9f58cbdb5cd7ba316362b111e19
LeadKit: 9e0a27cea8171a38b72bef7605ade92cd8a48217
ObjectMapper: 20505058f54e5c3ca69e1d6de9897d152a5369a6
PinLayout: a2bbe9057d49a1e326b13dc4fe8c14751f8c8844
RxAlamofire: 87a9c588541210cc3e4a1f843ccc3ecf3eb98b31

View File

@ -25,7 +25,7 @@ import LeadKit
import RxSwift
/// Default implementation of network service, which trust any server and use default timeout interval
@available(*, deprecated, message: "Use ConfigurableNetworkService protocol from LeadKit.")
@available(*, deprecated, message: "Use NetworkService from LeadKit.")
open class DefaultNetworkService: NetworkService {
open class var retryLimit: UInt {
@ -34,23 +34,8 @@ open class DefaultNetworkService: NetworkService {
private let disposeBag = DisposeBag()
/// Override to set base server url
open class var baseUrl: String {
fatalError("You should override this var: baseUrl")
}
/// Override to change timeout interval default value
open class var defaultTimeoutInterval: TimeInterval {
return 20.0
}
/// The default acceptable range 200299
open class var acceptableStatusCodes: [Int] {
return Alamofire.SessionManager.defaultAcceptableStatusCodes
}
public init(sessionManager: SessionManager) {
super.init(sessionManager: sessionManager, acceptableStatusCodes: DefaultNetworkService.acceptableStatusCodes)
public override init(configuration: NetworkServiceConfiguration) {
super.init(configuration: configuration)
// Fatal error: `drive*` family of methods can be only called from `MainThread`
DispatchQueue.main.async {
@ -58,28 +43,4 @@ open class DefaultNetworkService: NetworkService {
}
}
// MARK: - Default Values
/// Override to change server trust policies
open class var serverTrustPolicies: [String: ServerTrustPolicy] {
return [
baseUrl: .disableEvaluation
]
}
/// Override to change default urlSession configuration
open class var configuration: URLSessionConfiguration {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = defaultTimeoutInterval
return configuration
}
/// Override to configure alamofire session manager
open class var sessionManager: SessionManager {
let sessionManager = SessionManager(configuration: configuration,
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))
return sessionManager
}
}