diff --git a/KalturaClient/Classes/Core/Client.swift b/KalturaClient/Classes/Core/Client.swift index f7033e0e6..1f532e066 100644 --- a/KalturaClient/Classes/Core/Client.swift +++ b/KalturaClient/Classes/Core/Client.swift @@ -40,8 +40,8 @@ super.init() - clientTag = "swift:22-05-16" - apiVersion = "7.6.0.29893" + clientTag = "swift:22-05-19" + apiVersion = "7.6.0.29894" } } diff --git a/KalturaClient/Classes/Core/Executor/implementors/USRExecutor.swift b/KalturaClient/Classes/Core/Executor/implementors/USRExecutor.swift index 3b448ecdc..331c0652c 100644 --- a/KalturaClient/Classes/Core/Executor/implementors/USRExecutor.swift +++ b/KalturaClient/Classes/Core/Executor/implementors/USRExecutor.swift @@ -97,7 +97,7 @@ // cancel3ed logger.debug("request has been canceled") } else { - let result = Result(data: nil, error: ApiClientException(message: error.localizedDescription, code: ApiClientException.ErrorCode.httpError)) + let result = Result(data: nil, error: ApiClientException(message: error.localizedDescription, code: ApiClientException.ErrorCode.httpError.rawValue)) r.completion(result) // some other error } diff --git a/KalturaClient/Classes/Core/Response/JSONParser.swift b/KalturaClient/Classes/Core/Response/JSONParser.swift index 771145e30..a1ba001a9 100644 --- a/KalturaClient/Classes/Core/Response/JSONParser.swift +++ b/KalturaClient/Classes/Core/Response/JSONParser.swift @@ -101,12 +101,29 @@ internal class JSONParser{ return ret } + // parse API Exception + internal static func parseException(object: [String: Any]) -> ApiException { + let message = object["message"] as? String + let code = object["code"] as? String + + var exceptionArgs: [ApiExceptionArg]? + + if let args = object["args"] as? [[String: Any]] { + do { + exceptionArgs = try self.parse(array: args) as [ApiExceptionArg] + } catch { + return ApiClientException(message: message, code: code) + } + } + return ApiClientException(message: message, code: code, args: exceptionArgs) + } + // parse dictinoary of object internal static func parse(object: [String: Any]) throws -> T where T: ObjectBase { return try parse(object: object, type: T.self) } - // parse response + // parse response internal static func parse(object: [String: Any], type: ObjectBase.Type) throws -> T where T: ObjectBase { var classType: ObjectBase.Type = type @@ -118,7 +135,7 @@ internal class JSONParser{ return try self.parse(object: result, type: type) } else if let error = object["error"] as? [String: Any] { - throw try parse(object: error) as ApiException + throw self.parseException(object: error) } } @@ -135,7 +152,8 @@ internal class JSONParser{ return json } catch { - throw ApiClientException(message: "Failed to deserialize JSON", code: ApiClientException.ErrorCode.invalidJson) + throw ApiClientException(message: "Failed to deserialize JSON", + code: ApiClientException.ErrorCode.invalidJson.rawValue) } } @@ -159,11 +177,12 @@ internal class JSONParser{ return try self.parse(primitive: result, type: type) } else if let error = dict["error"] as? [String: Any] { - throw try parse(object: error) as ApiException + throw self.parseException(object: error) } } - throw ApiClientException(message: "Type not found", code: ApiClientException.ErrorCode.typeNotFound) + throw ApiClientException(message: "Type not found", + code: ApiClientException.ErrorCode.typeNotFound.rawValue) } @@ -171,7 +190,7 @@ internal class JSONParser{ internal static func parse(array: Any) throws -> [T]? { if let dict = array as? [String: Any] { if dict["objectType"] as? String == "KalturaAPIException" { - throw try parse(object: dict) as ApiException + throw self.parseException(object: dict) } if let result = dict["result"] { @@ -180,14 +199,16 @@ internal class JSONParser{ else if let error = dict["error"] { return try parse(array: error) }else{ - throw ApiClientException(message: "JSON is not valid object", code: ApiClientException.ErrorCode.invalidJsonObject) + throw ApiClientException(message: "JSON is not valid object", + code: ApiClientException.ErrorCode.invalidJsonObject.rawValue) } } else if let arr = array as? [Any] { return try parse(array: arr) as? [T] } else{ - throw ApiClientException(message: "JSON is not of object", code: ApiClientException.ErrorCode.invalidJsonObject) + throw ApiClientException(message: "JSON is not of object", + code: ApiClientException.ErrorCode.invalidJsonObject.rawValue) } @@ -195,14 +216,15 @@ internal class JSONParser{ internal static func parse(json: Any) throws -> T? { if let dict = json as? [String: Any], dict["objectType"] as? String == "KalturaAPIException" { - throw try parse(object: dict) as ApiException + throw self.parseException(object: dict) } if let type: ObjectBase.Type = T.self as? ObjectBase.Type { if let dict = json as? [String: Any] { return try parse(object: dict, type: type) as? T } else { - throw ApiClientException(message: "JSON is not of object", code: ApiClientException.ErrorCode.invalidJsonObject) + throw ApiClientException(message: "JSON is not of object", + code: ApiClientException.ErrorCode.invalidJsonObject.rawValue) } } else if let _ = T.self as? Void.Type { @@ -210,7 +232,7 @@ internal class JSONParser{ let result = dict["result"] as? [String: Any], let error = result["error"] as? [String: Any], error["objectType"] as? String == "KalturaAPIException" { - throw try parse(object: dict) as ApiException + throw self.parseException(object: dict) } return nil diff --git a/KalturaClient/Classes/Model/ApiException.swift b/KalturaClient/Classes/Model/ApiException.swift index bebd6ea4a..889b8eff3 100644 --- a/KalturaClient/Classes/Model/ApiException.swift +++ b/KalturaClient/Classes/Model/ApiException.swift @@ -33,45 +33,14 @@ * MANUAL CHANGES TO THIS CLASS WILL BE OVERWRITTEN. */ -public class ApiException : ObjectBase, Error{ - public var message: String? - public var code: String? - public var args: [ApiExceptionArg]? - - public required init() { - super.init() - } - - public convenience init(message: String, code: String, args: [ApiExceptionArg]) { - self.init() - - self.message = message - self.code = code - self.args = args - } - - public convenience init(message: String, code: String) { - self.init(message: message, code: code, args: []) - } - - internal override func populate(_ dict: [String: Any]) throws { - try super.populate(dict); - // set members values: - message = dict["message"] as? String - code = dict["code"] as? String - if let argsDict = dict["args"] as? [String: String] { - args = [] - for (key, value) in argsDict { - let arg = ApiExceptionArg() - arg.name = key - arg.value = value - } - } - } +public protocol ApiException: Error { + var message: String? { get } + var code: String? { get } + var args: [ApiExceptionArg]? { get } } -public class ApiClientException : ApiException { - +public struct ApiClientException: ApiException { + public enum ErrorCode: String { case typeNotFound = "TYPE_NOT_FOUND" case invalidJson = "INVALID_JSON" @@ -79,7 +48,13 @@ public class ApiClientException : ApiException { case httpError = "HTTP_ERROR" } - public convenience init(message: String, code: ErrorCode) { - self.init(message: message, code: code.rawValue) + public let message: String? + public let code: String? + public let args: [ApiExceptionArg]? + + init(message: String? = nil, code: String? = nil, args: [ApiExceptionArg]? = nil) { + self.message = message + self.code = code + self.args = args } } diff --git a/KalturaClient/Classes/Model/Objects/DeviceBrand.swift b/KalturaClient/Classes/Model/Objects/DeviceBrand.swift index eaee48159..2a6151aa7 100644 --- a/KalturaClient/Classes/Model/Objects/DeviceBrand.swift +++ b/KalturaClient/Classes/Model/Objects/DeviceBrand.swift @@ -50,9 +50,9 @@ open class DeviceBrand: ObjectBase { } } - public var deviceFamilyId: BaseTokenizedObject { + public var deviceFamilyid: BaseTokenizedObject { get { - return self.append("deviceFamilyId") + return self.append("deviceFamilyid") } } @@ -68,7 +68,7 @@ open class DeviceBrand: ObjectBase { /** Device brand name */ public var name: String? = nil /** Device family identifier */ - public var deviceFamilyId: Int64? = nil + public var deviceFamilyid: Int64? = nil /** Type of device family. if this device family belongs only to this group, otherwise. */ public var type: DeviceBrandType? = nil @@ -82,8 +82,8 @@ open class DeviceBrand: ObjectBase { self.dict["name"] = name } - public func setMultiRequestToken(deviceFamilyId: String) { - self.dict["deviceFamilyId"] = deviceFamilyId + public func setMultiRequestToken(deviceFamilyid: String) { + self.dict["deviceFamilyid"] = deviceFamilyid } public func setMultiRequestToken(type: String) { @@ -99,8 +99,8 @@ open class DeviceBrand: ObjectBase { if dict["name"] != nil { name = dict["name"] as? String } - if dict["deviceFamilyId"] != nil { - deviceFamilyId = Int64("\(dict["deviceFamilyId"]!)") + if dict["deviceFamilyid"] != nil { + deviceFamilyid = Int64("\(dict["deviceFamilyid"]!)") } if dict["type"] != nil { type = DeviceBrandType(rawValue: "\(dict["type"]!)") @@ -116,8 +116,8 @@ open class DeviceBrand: ObjectBase { if(name != nil) { dict["name"] = name! } - if(deviceFamilyId != nil) { - dict["deviceFamilyId"] = deviceFamilyId! + if(deviceFamilyid != nil) { + dict["deviceFamilyid"] = deviceFamilyid! } return dict } diff --git a/KalturaOttClient.podspec b/KalturaOttClient.podspec index 499170694..d55ec45da 100644 --- a/KalturaOttClient.podspec +++ b/KalturaOttClient.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'KalturaOttClient' -s.version = '7.6.0.29893' +s.version = '7.6.0.29894' s.summary = 'Kaltura OTT Client Library for Swift/iOS' s.homepage = 'https://github.com/kaltura/KalturaOttGeneratedAPIClientsSwift' s.license = { :type => 'AGPLv3', :text => 'AGPLv3' } diff --git a/KalturaOttClient.spec.header b/KalturaOttClient.spec.header index f571bfb00..71160cddd 100644 --- a/KalturaOttClient.spec.header +++ b/KalturaOttClient.spec.header @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'KalturaOttClient' -s.version = '7.6.0.29893' +s.version = '7.6.0.29894' s.summary = 'Kaltura OTT Client Library for Swift/iOS' s.homepage = 'https://github.com/kaltura/KalturaOttGeneratedAPIClientsSwift' s.license = { :type => 'AGPLv3', :text => 'AGPLv3' }