Skip to content

Commit

Permalink
access modifier changed
Browse files Browse the repository at this point in the history
  • Loading branch information
rushisangani committed Jan 17, 2024
1 parent 44c4bdf commit 4008c0e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Sources/NetworkKit/APIRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol RequestHandler {
public struct APIRequestHandler: RequestHandler {
let session: URLSession

init(session: URLSession = .shared) {
public init(session: URLSession = .shared) {
self.session = session
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/NetworkKit/APIResponseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import Combine

// MARK: - ResponseHandler

protocol ResponseHandler {
public protocol ResponseHandler {
func getResponse<T: Decodable>(from response: Data) throws -> T
}

// MARK: - APIResponseHandler

struct APIResponseHandler: ResponseHandler {
public struct APIResponseHandler: ResponseHandler {
let decoder: JSONDecoder

init(decoder: JSONDecoder = JSONDecoder()) {
public init(decoder: JSONDecoder = JSONDecoder()) {
self.decoder = decoder
}

func getResponse<T: Decodable>(from data: Data) throws -> T {
public func getResponse<T: Decodable>(from data: Data) throws -> T {
do {
return try decoder.decode(T.self, from: data)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import Foundation

extension Bundle {

func jsonFilePath(forName fileName: String) -> String {
public func jsonFilePath(forName fileName: String) -> String {
path(forResource: fileName, ofType: "json") ?? ""
}

func fileData(forResource resource: String) throws -> Data {
public func fileData(forResource resource: String) throws -> Data {
let filePath = jsonFilePath(forName: resource)

var url: URL
if #available(iOS 16.0, *) {
if #available(iOS 16.0, watchOS 9.0, macOS 13.0, *) {
url = URL(filePath: filePath)
} else {
url = URL(fileURLWithPath: filePath)
}
return try Data(contentsOf: url)
}

func decodableObject<T: Decodable>(forResource resource: String, type: T.Type) throws -> T {
public func decodableObject<T: Decodable>(forResource resource: String, type: T.Type) throws -> T {
let data = try fileData(forResource: resource)
return try JSONDecoder().decode(T.self, from: data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

import Foundation

class MockURLProtocol: URLProtocol {
static var error: Error?
static var requestHandler: ((URLRequest) throws -> (Data, HTTPURLResponse))?
public final class MockURLProtocol: URLProtocol {
public static var error: Error?
public static var requestHandler: ((URLRequest) throws -> (Data, HTTPURLResponse))?

override class func canInit(with request: URLRequest) -> Bool {
public override class func canInit(with request: URLRequest) -> Bool {
true
}

override class func canonicalRequest(for request: URLRequest) -> URLRequest {
public override class func canonicalRequest(for request: URLRequest) -> URLRequest {
request
}

override func startLoading() {
public override func startLoading() {
if let error = MockURLProtocol.error {
client?.urlProtocol(self, didFailWithError: error)
return
Expand All @@ -40,13 +40,13 @@ class MockURLProtocol: URLProtocol {
}
}

override func stopLoading() {
public override func stopLoading() {
}
}

extension URLSession {

static var mock: URLSession {
public static var mock: URLSession {
let configuration: URLSessionConfiguration = .ephemeral
configuration.protocolClasses = [MockURLProtocol.self]
return URLSession(configuration: configuration)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkKit/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class NetworkManager: NetworkHandler {
var requestHandler: RequestHandler
var responseHandler: ResponseHandler

init(requestHandler: RequestHandler = APIRequestHandler(),
public init(requestHandler: RequestHandler = APIRequestHandler(),
responseHandler: ResponseHandler = APIResponseHandler()
) {
self.requestHandler = requestHandler
Expand Down
8 changes: 4 additions & 4 deletions Sources/NetworkKit/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public protocol Request {
}

extension Request {
var scheme: String {
public var scheme: String {
"https"
}

var headers: [String: String] {
public var headers: [String: String] {
[:]
}

var params: [String: Any] {
public var params: [String: Any] {
[:]
}

var requestType: RequestType {
public var requestType: RequestType {
.get
}

Expand Down
10 changes: 0 additions & 10 deletions Tests/NetworkKitTests/Mocks/MockRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,3 @@ public struct MockCommentsRequest: Request {
try! createURLRequest().url!
}
}

public struct MockPostsRequest: Request {
public var scheme: String { "https" }
public var host: String { "jsonplaceholder.typicode.com" }
public var path: String { "/posts" }

var url: URL {
try! createURLRequest().url!
}
}

0 comments on commit 4008c0e

Please sign in to comment.