diff --git a/EnterAffectiveCloud/Cloud/AffectiveCloudServices.swift b/EnterAffectiveCloud/Cloud/AffectiveCloudServices.swift index 7daba0d..7ed0f47 100644 --- a/EnterAffectiveCloud/Cloud/AffectiveCloudServices.swift +++ b/EnterAffectiveCloud/Cloud/AffectiveCloudServices.swift @@ -65,7 +65,7 @@ class AffectiveCloudServices: WebSocketServiceProcotol { self.delegate?.error(client: self.client, request: nil, error: .unSocketConnected, message: "CSRequestError: Pleace check socket is connected!") return } - let requestModel = CSRequestJSONModel() + let requestModel = AffectiveCloudRequestJSONModel() requestModel.services = CSServicesType.session.rawValue requestModel.operation = CSSessionOperation.create.rawValue requestModel.kwargs = CSKwargsJSONModel() @@ -87,7 +87,7 @@ class AffectiveCloudServices: WebSocketServiceProcotol { self.delegate?.error(client: self.client, request: nil, error: .noSession, message: "CSRequestError: The session id is empty, restore failed! Try restart cloud service.") return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.session.rawValue jsonModel.operation = CSSessionOperation.restore.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -105,7 +105,7 @@ class AffectiveCloudServices: WebSocketServiceProcotol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.session.rawValue jsonModel.operation = CSSessionOperation.close.rawValue if let jsonString = jsonModel.toJSONString() { @@ -210,7 +210,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.biodata.rawValue jsonModel.operation = CSBiodataOperation.initial.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -259,7 +259,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.biodata.rawValue jsonModel.operation = CSBiodataOperation.subscribe.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -285,7 +285,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.biodata.rawValue jsonModel.operation = CSBiodataOperation.unsubscribe.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -309,7 +309,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.biodata.rawValue jsonModel.operation = CSBiodataOperation.upload.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -362,7 +362,7 @@ extension AffectiveCloudServices: BiodataServiceProtocol { } let biodataTypes = self.biodataTypeList(with: options) - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.biodata.rawValue jsonModel.operation = CSBiodataOperation.report.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -389,7 +389,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.affective.rawValue jsonModel.operation = CSEmotionOperation.start.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -415,7 +415,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol { self.checkEmotionAffectiveIsInitial(subscribeList: services) - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.affective.rawValue jsonModel.operation = CSEmotionOperation.subscribe.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -464,7 +464,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol { } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.affective.rawValue jsonModel.operation = CSEmotionOperation.unsubscribe.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -514,7 +514,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol { self.checkEmotionAffectiveIsInitial(affectiveList: services) - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.affective.rawValue jsonModel.operation = CSEmotionOperation.report.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -538,7 +538,7 @@ extension AffectiveCloudServices: CSEmotionServiceProcotol { return } - let jsonModel = CSRequestJSONModel() + let jsonModel = AffectiveCloudRequestJSONModel() jsonModel.services = CSServicesType.affective.rawValue jsonModel.operation = CSEmotionOperation.finish.rawValue jsonModel.kwargs = CSKwargsJSONModel() @@ -750,7 +750,7 @@ extension AffectiveCloudServices: WebSocketDelegate { if let unGzipData = try? data.gunzipped() { let text = String(decoding: unGzipData, as: UTF8.self) DLog("response data is \(text)") - if let responseModel = CSResponseJSONModel.deserialize(from: text) { + if let responseModel = AffectiveCloudResponseJSONModel.deserialize(from: text) { if self.handleErrorWithResponse(model: responseModel) { return } self.handleResponse(with: responseModel) } else { @@ -762,7 +762,7 @@ extension AffectiveCloudServices: WebSocketDelegate { } // check response status code, if error return `true` - private func handleErrorWithResponse(model: CSResponseJSONModel) -> Bool { + private func handleErrorWithResponse(model: AffectiveCloudResponseJSONModel) -> Bool { switch model.code { case 400: self.delegate?.error(client: self.client, response: model, error: .requestException, message: "The Request error!!") @@ -781,7 +781,7 @@ extension AffectiveCloudServices: WebSocketDelegate { /// Handle response data /// you can get data use `CSResponseDelegate` in your code - private func handleResponse(with model: CSResponseJSONModel) { + private func handleResponse(with model: AffectiveCloudResponseJSONModel) { if let request = model.request { switch (request.services, request.operation) { case (CSServicesType.session.rawValue, CSSessionOperation.create.rawValue): @@ -790,7 +790,7 @@ extension AffectiveCloudServices: WebSocketDelegate { self.session_id = id self.isSessionConnected = true } - self.delegate?.sessionCreate(client: self.client, response: model) + self.delegate?.sessionCreateAndAuthenticate(client: self.client, response: model) case (CSServicesType.session.rawValue, CSSessionOperation.restore.rawValue): self.delegate?.sessionRestore(client: self.client, response: model) case (CSServicesType.session.rawValue, CSSessionOperation.close.rawValue): @@ -800,7 +800,7 @@ extension AffectiveCloudServices: WebSocketDelegate { let list = biodata.biodataList { self.appendBiodataInitialList(list: list) } - self.delegate?.biodataInitial(client: self.client, response: model) + self.delegate?.biodataServicesInit(client: self.client, response: model) case (CSServicesType.biodata.rawValue, CSBiodataOperation.subscribe.rawValue): if let data = model.dataModel as? CSBiodataProcessJSONModel { DLog("log biodata subscribe is \(data)") @@ -816,30 +816,30 @@ extension AffectiveCloudServices: WebSocketDelegate { // self.appendBiodataSubscribeList(list: list) // } - self.delegate?.biodataSubscribe(client: self.client, response: model) + self.delegate?.biodataServicesSubscribe(client: self.client, response: model) case (CSServicesType.biodata.rawValue, CSBiodataOperation.unsubscribe.rawValue): - self.delegate?.biodataUnsubscribe(client: self.client, response: model) + self.delegate?.biodataServicesUnsubscribe(client: self.client, response: model) case (CSServicesType.biodata.rawValue, CSBiodataOperation.upload.rawValue): - self.delegate?.biodataUpload(client: self.client, response: model) + self.delegate?.biodataServicesUpload(client: self.client, response: model) case (CSServicesType.biodata.rawValue, CSBiodataOperation.report.rawValue): - self.delegate?.biodataReport(client: self.client, response: model) + self.delegate?.biodataServicesReport(client: self.client, response: model) case (CSServicesType.affective.rawValue, CSEmotionOperation.start.rawValue): if let dataModel = model.dataModel as? CSResponseDataJSONModel, let list = dataModel.affectiveList { self.appendEmotionAffectiveInitialList(list: list) } - self.delegate?.affectiveStart(client: self.client, response: model) + self.delegate?.affectiveDataStart(client: self.client, response: model) case (CSServicesType.affective.rawValue, CSEmotionOperation.subscribe.rawValue): if let dataModel = model.dataModel as? CSAffectiveSubscribeProcessJsonModel { DLog("affective data is \(dataModel.isNil())") } - self.delegate?.affectiveSubscribe(client: self.client, response: model) + self.delegate?.affectiveDataSubscribe(client: self.client, response: model) case (CSServicesType.affective.rawValue, CSEmotionOperation.unsubscribe.rawValue): - self.delegate?.affectiveUnsubscribe(client: self.client, response: model) + self.delegate?.affectiveDataUnsubscribe(client: self.client, response: model) case (CSServicesType.affective.rawValue, CSEmotionOperation.report.rawValue): - self.delegate?.affectiveReport(client: self.client, response: model) + self.delegate?.affectiveDataReport(client: self.client, response: model) case (CSServicesType.affective.rawValue, CSEmotionOperation.finish.rawValue): - self.delegate?.affectiveFinish(client: self.client, response: model) + self.delegate?.affectiveDataFinish(client: self.client, response: model) default: break } diff --git a/EnterAffectiveCloud/Cloud/CloudModels.swift b/EnterAffectiveCloud/Cloud/CloudModels.swift index 7987d8a..d395df1 100644 --- a/EnterAffectiveCloud/Cloud/CloudModels.swift +++ b/EnterAffectiveCloud/Cloud/CloudModels.swift @@ -11,7 +11,7 @@ import HandyJSON import SwiftyJSON //MARK: Request Models -public class CSRequestJSONModel: HandyJSON { +public class AffectiveCloudRequestJSONModel: HandyJSON { var services: String = "" var operation: String = "" var kwargs: CSKwargsJSONModel? @@ -87,9 +87,9 @@ class CSKwargsJSONModel: HandyJSON { } //MARK: Response Models -public class CSResponseJSONModel: HandyJSON { +public class AffectiveCloudResponseJSONModel: HandyJSON { public var code: Int = 0 - public var request: CSRequestJSONModel? + public var request: AffectiveCloudRequestJSONModel? private var data: [String: Any]? var message: String? public required init() { } diff --git a/EnterAffectiveCloud/Cloud/CloudServicesProtocol.swift b/EnterAffectiveCloud/Cloud/CloudServicesProtocol.swift index 37f9e96..f3b6ec4 100644 --- a/EnterAffectiveCloud/Cloud/CloudServicesProtocol.swift +++ b/EnterAffectiveCloud/Cloud/CloudServicesProtocol.swift @@ -16,24 +16,24 @@ public protocol AffectiveCloudResponseDelegate: class { func websocketConnect(client: AffectiveCloudClient) func websocketDisconnect(client: AffectiveCloudClient) - func sessionCreate(client: AffectiveCloudClient, response: CSResponseJSONModel) - func sessionRestore(client: AffectiveCloudClient, response: CSResponseJSONModel) - func sessionClose(client: AffectiveCloudClient, response: CSResponseJSONModel) - - func biodataInitial(client: AffectiveCloudClient, response: CSResponseJSONModel) - func biodataSubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel) - func biodataUnsubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel) - func biodataUpload(client: AffectiveCloudClient, response: CSResponseJSONModel) - func biodataReport(client: AffectiveCloudClient, response: CSResponseJSONModel) - - func affectiveStart(client: AffectiveCloudClient, response: CSResponseJSONModel) - func affectiveSubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel) - func affectiveUnsubscribe(client: AffectiveCloudClient, response: CSResponseJSONModel) - func affectiveReport(client: AffectiveCloudClient, response: CSResponseJSONModel) - func affectiveFinish(client: AffectiveCloudClient, response: CSResponseJSONModel) - - func error(client: AffectiveCloudClient, response: CSResponseJSONModel?, error: CSResponseError, message: String?) - func error(client: AffectiveCloudClient, request: CSRequestJSONModel?, error: CSRequestError, message: String?) + func sessionCreateAndAuthenticate(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func sessionRestore(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func sessionClose(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + + func biodataServicesInit(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func biodataServicesSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func biodataServicesUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func biodataServicesUpload(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func biodataServicesReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + + func affectiveDataStart(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func affectiveDataSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func affectiveDataUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func affectiveDataReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + func affectiveDataFinish(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) + + func error(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel?, error: AffectiveCloudResponseError, message: String?) + func error(client: AffectiveCloudClient, request: AffectiveCloudRequestJSONModel?, error: AffectiveCloudRequestError, message: String?) } //MARK: websocket services diff --git a/EnterAffectiveCloud/Cloud/CloudType.swift b/EnterAffectiveCloud/Cloud/CloudType.swift index 5087871..81d752f 100644 --- a/EnterAffectiveCloud/Cloud/CloudType.swift +++ b/EnterAffectiveCloud/Cloud/CloudType.swift @@ -42,7 +42,7 @@ public enum CSEmotionOperation: String { case finish } -public enum CSRequestError: Error { +public enum AffectiveCloudRequestError: Error { case unSocketConnected case unStart case noBiodataService @@ -53,7 +53,7 @@ public enum CSRequestError: Error { case unKnow } -public enum CSResponseError: Error { +public enum AffectiveCloudResponseError: Error { case requestException case notFoundServer case auth diff --git a/README.md b/README.md index 56ea5c5..a1a57b5 100644 --- a/README.md +++ b/README.md @@ -336,25 +336,25 @@ func finishAffectiveDataServices(services: AffectiveDataServiceOptions) ~~~swift // session -func createAndAuthenticateSession(response: affectiveCloudResponseJSONModel) -func restoreSession(response: affectiveCloudResponseJSONModel) -func closeSession(response: affectiveCloudResponseJSONModel) +func sessionCreateAndAuthenticate(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func sessionRestore(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func sessionClose(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) // bioData -func initBiodataServices(response: affectiveCloudResponseJSONModel) -func subscribeBiodataServices(response: affectiveCloudResponseJSONModel) -func unsubscribeBiodataServices(response: affectiveCloudResponseJSONModel) -func appendBiodata(response: affectiveCloudResponseJSONModel) -func getBiodataReport(response: affectiveCloudResponseJSONModel) +func biodataServicesInit(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func biodataServicesSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func biodataServicesUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func biodataServicesUpload(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func biodataServicesReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) // affectiveData -func startAffectiveDataServices(response: affectiveCloudResponseJSONModel) -func subscribeAffectiveDataServices(response: affectiveCloudResponseJSONModel) -func unsubscribeAffectiveDataServices(response: affectiveCloudResponseJSONModel) -func getAffectiveDataReport(response: affectiveCloudResponseJSONModel) -func finishAffectiveDataServices(response: affectiveCloudResponseJSONModel) +func affectiveDataStart(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func affectiveDataSubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func affectiveDataUnsubscribe(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func affectiveDataReport(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) +func affectiveDataFinish(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel) // error -func error(response: affectiveCloudResponseJSONModel?, error: affectiveCloudResponseError, message: String?) -func error(request: affectiveCloudRequestJSONModel?, error: affectiveCloudRequestError, message: String?) +func error(client: AffectiveCloudClient, response: AffectiveCloudResponseJSONModel?, error: AffectiveCloudResponseError, message: String?) +func error(client: AffectiveCloudClient, request: AffectiveCloudRequestJSONModel?, error: AffectiveCloudRequestError, message: String?) ~~~