Skip to content

Commit 9969d52

Browse files
authored
Merge pull request #7 from AyanTech/1.2.2
1.2.2
2 parents e0a75d8 + 79d71c3 commit 9969d52

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

AyanTechNetworkingLibrary.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "AyanTechNetworkingLibrary"
3-
spec.version = "1.1.0"
3+
spec.version = "1.2.2"
44
spec.summary = "Networking library for comunicate AyanTech web services"
55
spec.homepage = "https://github.com/AyanTech/AyanTechNetworkingLibrary-iOS"
66
spec.license = { type: 'MIT', file: 'LICENSE' }

AyanTechNetworkingLibrary/Model/ATRequest.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public class ATRequest {
1818
var body: Data?
1919
var task: URLSessionTask?
2020

21-
var contentType: ContentType = .applicationJson {
21+
public var contentType: ContentType = .applicationJson {
2222
didSet {
2323
self.headers["Content-Type"] = self.contentType.rawValue
2424
}
2525
}
2626

27-
enum ContentType: String {
27+
public enum ContentType: String {
2828
case applicationJson = "application/json"
2929
case textPlain = "text/plain"
3030
case textHtml = "text/html"
@@ -40,6 +40,7 @@ public class ATRequest {
4040
let result = ATRequest()
4141
result.url = url
4242
result.method = method
43+
result.headers = ATRequest.Configuration.defaultHeaders
4344
return result
4445
}
4546

@@ -49,7 +50,7 @@ public class ATRequest {
4950
}
5051

5152
@discardableResult public func setJsonBody(body: JSONObject) -> Self {
52-
self.body = body.toJsonData()
53+
self.body = Configuration.parametersCreator(body).toJsonData()
5354
self.contentType = .applicationJson
5455
return self
5556
}
@@ -79,4 +80,9 @@ public class ATRequest {
7980
responseHandler?(atResponse)
8081
}
8182
}
83+
84+
public class Configuration {
85+
public static var defaultHeaders: [String: String] = [:]
86+
public static var parametersCreator: (JSONObject) -> JSONObject = { input in return input}
87+
}
8288
}

AyanTechNetworkingLibrary/Model/ATResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class ATResponse {
5252
}
5353

5454
public class Status {
55-
var errorCodeString: String?
56-
var description: String?
55+
public var errorCodeString: String?
56+
public var description: String?
5757

5858
public var isSuccess: Bool {
5959
return self.errorCodeString == kResponseSuccessCode

AyanTechNetworkingLibrary/Model/Server.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ class Server {
2828
req.task = URLSession.shared.dataTask(with: r as URLRequest) { (data, response, error) in
2929
Utils.runOnMainThread {
3030
UIApplication.shared.isNetworkActivityIndicatorVisible = false
31+
32+
if let responseString = String.init(data: data ?? Data(), encoding: .utf8) {
33+
ATLog("RESPONSE", logData: "\(responseString)")
34+
}
35+
36+
req.task = nil
37+
responseHandler(data, response, error)
3138
}
32-
if let responseString = String.init(data: data ?? Data(), encoding: .utf8) {
33-
ATLog("RESPONSE", logData: "\(responseString)")
34-
}
35-
36-
req.task = nil
37-
responseHandler(data, response, error)
3839
}
3940
req.task?.resume()
4041
}

0 commit comments

Comments
 (0)