Skip to content

Commit fc14b9d

Browse files
Merge pull request #12 from AppcentMobile/release/1.1.1
🎷 [UPDATE] Release 1.1.1, plist updated.
2 parents 5479373 + a7b4cc1 commit fc14b9d

File tree

6 files changed

+61
-34
lines changed

6 files changed

+61
-34
lines changed

ACMNetworking.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "ACMNetworking"
3-
spec.version = "1.1.0"
3+
spec.version = "1.1.1"
44
spec.summary = "ACMNetworking iOS Library"
55
spec.description = <<-DESC
66
ACMNetworking is a package that help developers to make requests easily.
@@ -14,4 +14,4 @@ Pod::Spec.new do |spec|
1414
spec.swift_version = '5.0'
1515
spec.source = { :git => "https://github.com/AppcentMobile/ACMNetworking.git", :tag => "#{spec.version}" }
1616
spec.source_files = "Sources/**/*.{h,m,swift}"
17-
end
17+
end

Sources/ACMNetworking/Library/Manager/ACMBaseEndpoint.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import Foundation
88
///
99
/// Base endpoint struct for holding endpoint information
1010
public struct ACMBaseEndpoint {
11+
// MARK: Config
12+
13+
var config: ACMPlistModel?
14+
1115
// MARK: Override fetching config file
1216

1317
var configOverride: Bool = false
@@ -98,31 +102,26 @@ public struct ACMBaseEndpoint {
98102
return urlRequest
99103
}
100104

101-
private var config: ACMPlistModel {
102-
guard let model = ACMPlistUtils.shared.config else {
103-
return emptyConfig
104-
}
105-
return model
106-
}
107-
108-
var emptyConfig: ACMPlistModel {
109-
ACMPlistModel(baseURL: "", timeout: 0, isLogEnabled: false)
110-
}
111-
112105
func session(delegate: URLSessionDelegate) -> URLSession {
113106
let configuration = URLSessionConfiguration.default
114-
configuration.timeoutIntervalForRequest = config.timeout
115-
configuration.timeoutIntervalForResource = config.timeout
107+
configuration.timeoutIntervalForRequest = config?.timeout ?? 0
108+
configuration.timeoutIntervalForResource = config?.timeout ?? 0
116109

117110
return URLSession(configuration: configuration, delegate: delegate, delegateQueue: OperationQueue.main)
118111
}
119112

120-
init(configOverride: Bool, host: String? = nil, scheme: ACMBaseScheme, path: String = "", queryItems: [URLQueryItem]? = nil, params: [String: Any?]? = nil, headers: NSMutableDictionary? = nil, method: ACMBaseMethod, authHeader: String? = nil, mediaData: NSMutableData? = nil, retryCount: Int? = nil) {
113+
init(config: ACMPlistModel? = nil, configOverride: Bool, host: String? = nil, scheme: ACMBaseScheme, path: String = "", queryItems: [URLQueryItem]? = nil, params: [String: Any?]? = nil, headers: NSMutableDictionary? = nil, method: ACMBaseMethod, authHeader: String? = nil, mediaData: NSMutableData? = nil, retryCount: Int? = nil) {
114+
if let config = config {
115+
self.config = config
116+
} else {
117+
self.config = ACMPlistUtils.shared.config()
118+
}
119+
ACMBaseLogger.shared.config = self.config
121120
ACMNetworkingConstants.configOverride = configOverride
122121
if let host = host {
123122
self.host = host
124123
} else {
125-
self.host = config.baseURL
124+
self.host = self.config?.baseURL
126125
}
127126
self.scheme = scheme
128127
self.path = path

Sources/ACMNetworking/Library/Manager/ACMBaseLogger.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ final class ACMBaseLogger {
99
/// shared instance
1010
static var shared = ACMBaseLogger()
1111

12+
var config: ACMPlistModel?
13+
1214
private init() {}
1315

1416
/// is BaseLoggerging enable
1517
var isEnabled: Bool {
16-
return ACMPlistUtils.shared.config?.isLogEnabled ?? false
18+
return config?.isLogEnabled ?? false
1719
}
1820

1921
/// BaseLogger for success. Will add ✅ emoji to see better

Sources/ACMNetworking/Library/Manager/ACMEndpoint.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public final class ACMEndpoint {
1313
/// Init method for creating new object
1414
public init() {}
1515

16+
var config: ACMPlistModel?
1617
var configOverride: Bool = false
1718
var host: String?
1819
var scheme: ACMBaseScheme = .https
@@ -28,6 +29,18 @@ public final class ACMEndpoint {
2829
var mediaData: NSMutableData?
2930
var retryCount: Int?
3031

32+
/// Set config model
33+
///
34+
/// - Parameters:
35+
/// - config: ACMPlistModel
36+
///
37+
/// - Returns
38+
/// - Self
39+
public func set(config: ACMPlistModel) -> Self {
40+
self.config = config
41+
return self
42+
}
43+
3144
/// Update override plist
3245
///
3346
/// - Parameters:
@@ -300,6 +313,6 @@ public final class ACMEndpoint {
300313
/// - Returns
301314
/// - Self
302315
public func build() -> ACMBaseEndpoint {
303-
return ACMBaseEndpoint(configOverride: configOverride, host: host, scheme: scheme, path: path, queryItems: queryItems, params: params, headers: headers, method: method, authHeader: authHeader, mediaData: mediaData, retryCount: retryCount)
316+
return ACMBaseEndpoint(config: config, configOverride: configOverride, host: host, scheme: scheme, path: path, queryItems: queryItems, params: params, headers: headers, method: method, authHeader: authHeader, mediaData: mediaData, retryCount: retryCount)
304317
}
305318
}

Sources/ACMNetworking/Library/Models/ACMPlistModel.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@
55
/// ACMPlistModel
66
///
77
/// A struct that holds the plist
8-
struct ACMPlistModel: Codable {
8+
open class ACMPlistModel: Codable {
99
var baseURL: String
1010
var timeout: Double
1111
var isLogEnabled: Bool
12+
13+
enum CodingKeys: CodingKey {
14+
case baseURL
15+
case timeout
16+
case isLogEnabled
17+
}
18+
19+
open func encode(to encoder: Encoder) throws {
20+
var container = encoder.container(keyedBy: CodingKeys.self)
21+
try container.encode(baseURL, forKey: .baseURL)
22+
try container.encode(timeout, forKey: .timeout)
23+
try container.encode(isLogEnabled, forKey: .isLogEnabled)
24+
}
1225
}

Sources/ACMNetworking/Library/Utils/Plist/ACMPlistUtils.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ import Foundation
77
/// ACMPlistUtils
88
///
99
/// Utility class for plist
10-
final class ACMPlistUtils {
11-
static let shared = ACMPlistUtils()
10+
public final class ACMPlistUtils {
11+
public static let shared = ACMPlistUtils()
1212

13-
var config: ACMPlistModel? {
13+
public func config<T: Codable>(type _: T.Type? = ACMPlistModel) -> T? {
14+
guard let data = getData(), let plist = getList(with: data, type: T.self) else {
15+
throwFatalError(with: ACMPropertyListSerializationError.fileNotParsed)
16+
return nil
17+
}
18+
return plist
19+
}
20+
21+
private func getData() -> Data? {
1422
guard let path = Bundle.main.path(forResource: ACMPListContants.fileName, ofType: ACMPListContants.fileExtension) else {
1523
throwFatalError(with: ACMPropertyListSerializationError.fileNotFound)
1624
return nil
1725
}
1826
let url = URL(fileURLWithPath: path)
1927

2028
do {
21-
let data = try Data(contentsOf: url)
22-
23-
guard let plist = getList(with: data) else {
24-
throwFatalError(with: ACMPropertyListSerializationError.fileNotParsed)
25-
return nil
26-
}
27-
28-
return plist
29+
return try Data(contentsOf: url)
2930
} catch {
3031
throwFatalError(with: ACMPropertyListSerializationError.dataNotAvailable)
3132
return nil
3233
}
3334
}
3435

35-
private func getList(with data: Data) -> ACMPlistModel? {
36+
private func getList<T: Codable>(with data: Data, type: T.Type) -> T? {
3637
let decoder = PropertyListDecoder()
3738
do {
38-
let model = try decoder.decode(ACMPlistModel.self, from: data)
39-
return model
39+
return try decoder.decode(T.self, from: data)
4040
} catch let DecodingError.dataCorrupted(context) {
4141
throwFatalError(with: ACMPropertyListSerializationError.dataCorrupted(context: context))
4242
return nil

0 commit comments

Comments
 (0)