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>, withBaseURL baseURL: URL, completion: @escaping ((Result<T, KukaiError>) -> Void)) where T : Decodable

    Parameters

    rpc

    A instance of RPC.

    withBaseURL

    The base URL needed. This will typically come from TezosNodeConfig.

    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

Logging