BaseClient
@objc(VSSBaseClient)
open class BaseClient : NSObject
Base class for clients
-
Base URL for a service
Declaration
Swift
@objc public let serviceUrl: URL
-
HttpConnectionProtocol implementation to use for queries
Declaration
Swift
public let connection: HttpConnectionProtocol
-
Error domain for Error instances thrown from service
Declaration
Swift
@objc open class var serviceErrorDomain: String { get }
-
Access token provider
Declaration
Swift
@objc public let accessTokenProvider: AccessTokenProvider
-
Initializes new
BaseClient
instanceDeclaration
Swift
public init(accessTokenProvider: AccessTokenProvider, serviceUrl: URL, connection: HttpConnectionProtocol = HttpConnection())
Parameters
accessTokenProvider
Access token provider
serviceUrl
service url
connection
Http Conntection
-
Sends request and performs retries if needed
Throws
- Rethrows from
AccessTokenProvider
- Rethrows from
HttpConnection
Declaration
Swift
public func sendWithRetry(_ request: ServiceRequest, retry: RetryProtocol, tokenContext: TokenContext) throws -> GenericOperation<Response>
Parameters
request
request to send
retry
Retry
tokenContext
token context to forward to Access Token Provider
Return Value
Response
- Rethrows from
-
Handles error
Declaration
Swift
public func handleError(statusCode: Int, body: Data?) -> Error
Parameters
statusCode
http status code
body
response body
Return Value
- ServiceError if service responded with correct error json
- NSError with http response string in the description, if present
- NSError without description in case of empty response
-
Validated response and throws error if needed
Throws
See BaseClient.handleErrorDeclaration
Swift
public func validateResponse(_ response: Response) throws
Parameters
response
response
-
Processes response and returns needed Decodable type
Throws
- BaseClientError.noBody if body was not found in the response
- Rethrows from
JSONDecoder
Declaration
Swift
public func processResponse<T>(_ response: Response) throws -> T where T : Decodable
Parameters
response
response
Return Value
Decoded object of type T