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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
endpoint | Endpoint |
The request's endpoint |
version | Int |
The API version |
user | PCUser? |
The user |
headers | [String: String] |
An additional headers |
Properties
Methods
perform(sensitive:decoder:customErrorHandler: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
Name | Type | Description |
---|---|---|
sensitive | Bool |
If set to |
decoder | JSONDecoder |
Custom decoder to decode JSON response |
customErrorHandler | (([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 |
perform(sensitive:customErrorHandler:completion:)
func perform(
sensitive: Bool = false,
customErrorHandler: (([String: Any]) -> Error)? = nil,
completion: @escaping (_ result: Result<Void, Error>) -> Void
)
Performs request
Parameters
Name | Type | Description |
---|---|---|
sensitive | Bool |
If set to |
customErrorHandler | (([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 |