PCSDKModule Documentation

Structure Request

public struct Request  

The helper struct to communicate with PCSDK server

Initializers

init(to:​version:​body:​user:​parameters:​headers:​)

public init<T: Encodable>(
        to endpoint: Endpoint,
        version: Int,
        body: T,
        user: PCUser? = nil,
        parameters: PCParameters? = nil,
        headers: [String: String] = [:]
    )  

Creates new instance

Parameters

endpoint Endpoint

The request's endpoint

version Int

The API version

body T

The request's body

user PCUser?

The user

parameters PCParameters?

Additional parameters

headers [String:​ String]

Additional headers

init(to:​version:​user:​headers:​)

public init(
        to endpoint: Endpoint,
        version: Int,
        user: PCUser? = nil,
        headers: [String: String] = [:]
    )  

Creates new instance

Parameters

endpoint Endpoint

The request's endpoint

version Int

The API version

user PCUser?

The user

headers [String:​ String]

An additional headers

Properties

endpoint

public let endpoint: Endpoint

The corresponding endpoint

version

public let version: Int

The API version

headers

public var headers: [String: String] 

An additional headers

Methods

perform(sensitive:​decoder:​custom​Error​Handler:​completion:​)

func perform<T>(
        sensitive: Bool = false,
        decoder: JSONDecoder = JSONDecoder(),
        customErrorHandler: (([String: Any]) -> Error)? = nil,
        completion: @escaping (_ result: Result<T, Error>) -> Void
    ) where T: Decodable  

Performs request

Parameters

sensitive Bool

If set to true request and response bodies will be hidden from logs

decoder JSONDecoder

Custom decoder to decode JSON response

custom​Error​Handler (([String:​ Any]) -> Error)?

Closure to handle response when HTTP code is not 200

completion @escaping (_ result:​ Result<T, Error>) -> Void

A closure to be invoked after performing the request

result

Returns Data when success. Otherwise, returns error

perform(sensitive:​custom​Error​Handler:​completion:​)

func perform(
        sensitive: Bool = false,
        customErrorHandler: (([String: Any]) -> Error)? = nil,
        completion: @escaping (_ result: Result<Void, Error>) -> Void
    )  

Performs request

Parameters

sensitive Bool

If set to true request and response bodies will be hidden from logs

custom​Error​Handler (([String:​ Any]) -> Error)?

Closure to handle response when HTTP code is not 200

completion @escaping (_ result:​ Result<Void, Error>) -> Void

A closure to be invoked after performing the request

result

Returns Data when success. Otherwise, returns error