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

Types

Public Properties

  • The URLSession used to preform all the networking operations

    Declaration

    Swift

    public let urlSession: URLSession
  • The URLSession used to preform all the networking operations

    Declaration

    Swift

    public let loggingConfig: LoggingConfig

Init

Functions

  • 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 console

    Declaration

    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 console

    Declaration

    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