Skip to content

Commit

Permalink
Merge pull request #7 from AyanTech/1.2.2
Browse files Browse the repository at this point in the history
1.2.2
  • Loading branch information
sepbehroozi authored Aug 19, 2018
2 parents e0a75d8 + 79d71c3 commit 9969d52
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion AyanTechNetworkingLibrary.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "AyanTechNetworkingLibrary"
spec.version = "1.1.0"
spec.version = "1.2.2"
spec.summary = "Networking library for comunicate AyanTech web services"
spec.homepage = "https://github.com/AyanTech/AyanTechNetworkingLibrary-iOS"
spec.license = { type: 'MIT', file: 'LICENSE' }
Expand Down
12 changes: 9 additions & 3 deletions AyanTechNetworkingLibrary/Model/ATRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class ATRequest {
var body: Data?
var task: URLSessionTask?

var contentType: ContentType = .applicationJson {
public var contentType: ContentType = .applicationJson {
didSet {
self.headers["Content-Type"] = self.contentType.rawValue
}
}

enum ContentType: String {
public enum ContentType: String {
case applicationJson = "application/json"
case textPlain = "text/plain"
case textHtml = "text/html"
Expand All @@ -40,6 +40,7 @@ public class ATRequest {
let result = ATRequest()
result.url = url
result.method = method
result.headers = ATRequest.Configuration.defaultHeaders
return result
}

Expand All @@ -49,7 +50,7 @@ public class ATRequest {
}

@discardableResult public func setJsonBody(body: JSONObject) -> Self {
self.body = body.toJsonData()
self.body = Configuration.parametersCreator(body).toJsonData()
self.contentType = .applicationJson
return self
}
Expand Down Expand Up @@ -79,4 +80,9 @@ public class ATRequest {
responseHandler?(atResponse)
}
}

public class Configuration {
public static var defaultHeaders: [String: String] = [:]
public static var parametersCreator: (JSONObject) -> JSONObject = { input in return input}
}
}
4 changes: 2 additions & 2 deletions AyanTechNetworkingLibrary/Model/ATResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class ATResponse {
}

public class Status {
var errorCodeString: String?
var description: String?
public var errorCodeString: String?
public var description: String?

public var isSuccess: Bool {
return self.errorCodeString == kResponseSuccessCode
Expand Down
13 changes: 7 additions & 6 deletions AyanTechNetworkingLibrary/Model/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ class Server {
req.task = URLSession.shared.dataTask(with: r as URLRequest) { (data, response, error) in
Utils.runOnMainThread {
UIApplication.shared.isNetworkActivityIndicatorVisible = false

if let responseString = String.init(data: data ?? Data(), encoding: .utf8) {
ATLog("RESPONSE", logData: "\(responseString)")
}

req.task = nil
responseHandler(data, response, error)
}
if let responseString = String.init(data: data ?? Data(), encoding: .utf8) {
ATLog("RESPONSE", logData: "\(responseString)")
}

req.task = nil
responseHandler(data, response, error)
}
req.task?.resume()
}
Expand Down

0 comments on commit 9969d52

Please sign in to comment.