BMLTCommunicator
class BMLTCommunicator
The main reason for the existence of this class is to make the communications testable. Its structure allows the tester to inject data sources and sinks.
Data sources and sinks are adornments. This allows us to substitute mocks when testing.
This is a lightweight, short-lifetime class. It is meant to be instantiated and destroyed on an as needed
basis.
-
This is the definition for the testRootServerURI completion block.
The routine is called upon completion of a URL connection. When the connection ends (either successfully or not), this routine is called. If it is successful, then the inData parameter will be non-nil. If it failed, then the parameter will be nil, and the inError parameter may have a value.
Declaration
Swift
typealias RequestCompletionBlock = (_ inData: Any?, _ inError: Error?) -> VoidParameters
inDataThe Data returned.
inErrorAny error that ocurred. Nil, if no error.
-
This is the data source for the call.
Declaration
Swift
let dataSource: BMLTCommunicatorDataSourceProtocol! -
This is the completion handler to be called when the URL is called.
Declaration
Swift
weak var delegate: BMLTCommunicatorDataSinkProtocol! -
This is the completion handler to be called when the URL is called.
Declaration
Swift
let uriAsAString: String! -
This is any extra data the caller may want passed to the callback.
Declaration
Swift
let refCon: AnyObject?
-
This contains any error from the call.
Declaration
Swift
var error: Error! -
This contains the data response (if any).
Declaration
Swift
var data: Data!
-
This is the designated initializer for this class. You have to give a URL, as well as a delegate (sink) and data source. This class executes the connection upon initialization.
Declaration
Swift
init(_ inURI: String, dataSource inDataSource: BMLTCommunicatorDataSourceProtocol, delegate inDelegate: BMLTCommunicatorDataSinkProtocol!, refCon inRefCon: AnyObject? = nil, executeImmediately inExecute: Bool = true)Parameters
inURIThe URL to be called, as a string.
dataSourceThe data source.
delegateThe delegate object (the sink) to be notified when new data arrives.
refConThis is any object or data that you want to send to the delegate receive method. Default is nil.
executeImmediatelyIf true (the default), the instance executes immediately. The reason for this flag, as opposed to simply overriding the
execute()
method, is so we have a bit more flexibility. We don’t need to rewrite that method if we don’t want to. Since the parameter has a default, it’s not an issue to ignore it. -
This actually executes the connection.
Declaration
Swift
func execute() -
This is the callback for the URL request.
Declaration
Swift
func handleResponseFromHandler(_ inData: Any, inError: Error?)Parameters
inDatathe data from the URL request.
inErrorAny error that ocurred. Nil, if no error.
View on GitHub
BMLTCommunicator Class Reference