Skip to content

Commit

Permalink
Classes became open
Browse files Browse the repository at this point in the history
  • Loading branch information
ks committed Jan 21, 2020
1 parent b7a0312 commit 523e280
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SKHTTPClient.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Sources/SKHTTPClient/Model/HTTPClientError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public class HTTPClientError<T: Codable>: Error {
public final class HTTPClientError<T: Codable>: Error {

let statusCode: Int?
let type: Code
Expand Down
18 changes: 9 additions & 9 deletions Sources/SKHTTPClient/SKHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

import Foundation

@objc public class HTTPClient: NSObject {
@objc open class HTTPClient: NSObject {

//MARK: - Properties

public var session: URLSession { URLSession(configuration: .default) }
open var session: URLSession { URLSession(configuration: .default) }

public var serverURL: URL { URL(string: "")! }
open var serverURL: URL { URL(string: "")! }

public var printResponse: Bool { true }
open var printResponse: Bool { true }

public private(set) var token: String? = nil
open private(set) var token: String? = nil

//MARK: - Functionality

public func setTokenInHeaders(withKey key: String, andValue value: String?) {
open func setTokenInHeaders(withKey key: String, andValue value: String?) {
if var httpAdditionalHeaders = session.configuration.httpAdditionalHeaders {
httpAdditionalHeaders[key] = value
} else {
Expand All @@ -31,7 +31,7 @@ import Foundation
token = value
}

public func createURLRequest(endPoint: URL, method: HTTPClientConfigurations.Method, urlParams: [String: Any] = [:], headers: [String: String]? = nil, body: [String: Any]? = nil) -> URLRequest? {
open func createURLRequest(endPoint: URL, method: HTTPClientConfigurations.Method, urlParams: [String: Any] = [:], headers: [String: String]? = nil, body: [String: Any]? = nil) -> URLRequest? {
var request = URLRequest(url: endPoint.appendingQueryParameters(urlParams))

request.httpMethod = method.rawValue
Expand All @@ -44,7 +44,7 @@ import Foundation
return request
}

public func performURLDataTask<T: Codable, U: Codable>(with request: URLRequest?, completion: @escaping(T?, HTTPClientError<U>?) -> Void) {
open func performURLDataTask<T: Codable, U: Codable>(with request: URLRequest?, completion: @escaping(T?, HTTPClientError<U>?) -> Void) {
guard let request = request else { completion(nil, HTTPClientError(type: .invalidResponse)) ; return }

session.dataTask(with: request) { (data, urlResponse, error) in
Expand Down Expand Up @@ -76,7 +76,7 @@ import Foundation
}.resume()
}

public func performURLDataTask(with url: URL, completion: @escaping(Data?) -> Void) {
open func performURLDataTask(with url: URL, completion: @escaping(Data?) -> Void) {
session.dataTask(with: url) { (data, response, error) in
guard let data = data, error == nil else { print(error.debugDescription) ; completion(nil) ; return }
completion(data)
Expand Down

0 comments on commit 523e280

Please sign in to comment.