NetworkService
public class NetworkService
Class responsible for sending all the networking requests, checking for http errors, RPC errors, Decoding the responses and optionally logging progress
-
Errors that can be returned by the
See moreNetworkService
Declaration
Swift
public enum NetworkError : Error
-
The
URLSession
used to preform all the networking operationsDeclaration
Swift
public let urlSession: URLSession
-
The
URLSession
used to preform all the networking operationsDeclaration
Swift
public let loggingConfig: LoggingConfig
-
Init an
NetworkService
with aURLSession
Declaration
Swift
public init(urlSession: URLSession, loggingConfig: LoggingConfig)
Parameters
urlSession
A
URLSession
object
-
A generic send function that takes an RPC, with a generic type conforming to
Decodable
, executes the request and returns the result.Declaration
Swift
public func send<T>(rpc: RPC<T>, withNodeURLs nodeURLs: [URL], retryCount: Int = 0, completion: @escaping ((Result<T, KukaiError>) -> Void)) where T : Decodable
Parameters
rpc
A instance of
RPC
.withNodeURLs
An array of nodeURLs from
TezosNodeConfig
.retryCount
An Int denoting the current number of attempts made. 3 is max.
completion
A completion callback that will be executed on the main thread.
Return Value
Void
-
A generic network request function that takes a URL, optional payload and a
Decodable
response type. Function will execute the request and attempt to parse the response. Using the Logging config, will auto log (or not) urls, response outputs, or fails to the consoleDeclaration
Swift
public func request<T>(url: URL, isPOST: Bool, withBody body: Data?, forReturnType: T.Type, completion: @escaping ((Result<T, KukaiError>) -> Void)) where T : Decodable
Parameters
url
The full url, including query parameters to execute.
isPOST
Bool indicating if its a POST or GET request.
withBody
Optional Data to be passed as the body.
forReturnType
The Type to parse the response as.
completion
A completion block with a
Result<T, Error>
T being the supplied decoable type -
A generic network request function that takes a URL, optional payload and a
Decodable
response type. Function will execute the request and attempt to parse the response, returning it as a combine publisher. Using the Logging config, will auto log (or not) urls, response outputs, or fails to the consoleDeclaration
Swift
public func request<T>(url: URL, isPOST: Bool, withBody body: Data?, forReturnType: T.Type) -> AnyPublisher<T, KukaiError> where T : Decodable
Parameters
url
The full url, including query parameters to execute.
isPOST
Bool indicating if its a POST or GET request.
withBody
Optional Data to be passed as the body.
forReturnType
The Type to parse the response as.
Return Value
A publisher of the supplied return type, or error response
-
Send a HTTP DELETE to a given URL
Declaration
Swift
public func delete(url: URL, completion: @escaping ((Result<Bool, KukaiError>) -> Void))
-
Send a HTTP DELETE to a given URL
Declaration
Swift
public func delete(url: URL) -> AnyPublisher<Bool, KukaiError>
-
Logging details of request failures using
os_log
global loggingDeclaration
Swift
public static func logRequestFailed(loggingConfig: LoggingConfig?, isPost: Bool, fullURL: URL, payload: Data?, error: Error?, statusCode: Int?, responseData: Data?)
-
Logging details of successful requests using
os_log
global loggingDeclaration
Swift
public static func logRequestSucceded(loggingConfig: LoggingConfig?, isPost: Bool, fullURL: URL, payload: Data?, responseData: Data?)
-
Logging details when a request starts using
os_log
global loggingDeclaration
Swift
public static func logRequestStart(loggingConfig: LoggingConfig?, fullURL: URL)