diff --git a/Package.swift b/Package.swift index c88a5cc1..118e669a 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,6 @@ let package = Package( dependencies: [ .package(url: "https://github.com/Moya/Moya.git", .upToNextMajor(from: "14.0.0")), .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0")), - .package(url: "https://github.com/tristanhimmelman/ObjectMapper.git", .upToNextMajor(from: "4.1.0")), .package(name: "KeychainSwift", url: "https://github.com/evgenyneu/keychain-swift.git", .upToNextMajor(from: "22.0.0")), .package(name: "JWTDecode", url: "https://github.com/auth0/JWTDecode.swift.git", .upToNextMajor(from: "2.6.0")), .package( @@ -26,7 +25,7 @@ let package = Package( ], targets: [ .target(name: "Rio", dependencies: [ - "Moya", "Alamofire", "ObjectMapper", "KeychainSwift", "JWTDecode", + "Moya", "Alamofire", "KeychainSwift", "JWTDecode", .product(name: "FirebaseAuth", package: "Firebase"), .product(name: "FirebaseFirestore", package: "Firebase") diff --git a/Rio.podspec b/Rio.podspec index abf57ee6..32c01c32 100644 --- a/Rio.podspec +++ b/Rio.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'Rio' - s.version = '0.0.54' + s.version = '0.0.55' s.summary = 'A short description of Rio.' # This description is used to generate tags and improve search results. @@ -41,6 +41,8 @@ TODO: Add long description of the pod here. s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } + s.swift_version = '5.0' + # s.public_header_files = 'Pod/Classes/**/*.h' # s.frameworks = 'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' @@ -49,7 +51,6 @@ TODO: Add long description of the pod here. s.dependency 'Moya', '~> 14.0' s.dependency 'Alamofire', '~> 5.2' - s.dependency 'ObjectMapper', '~> 3.4' s.dependency 'KeychainSwift', '~> 22.0' s.dependency 'JWTDecode', '~> 2.4' s.dependency 'Firebase', '~> 10.2.0' diff --git a/Rio/Classes/Rio.swift b/Rio/Classes/Rio.swift index 1ba9b7be..0bb474db 100644 --- a/Rio/Classes/Rio.swift +++ b/Rio/Classes/Rio.swift @@ -2,7 +2,6 @@ import Alamofire import Moya import KeychainSwift -import ObjectMapper import JWTDecode import Foundation import FirebaseCore @@ -150,11 +149,11 @@ public struct RioUser { public var isAnonymous: Bool } -struct RioTokenResponse: Decodable { +struct RioTokenResponse: Codable { var response: RioTokenData } -struct RioTokenData: Mappable, Decodable { +struct RioTokenData: Codable { var projectId: String? var isAnonym: Bool? var uid: String? @@ -193,22 +192,6 @@ struct RioTokenData: Mappable, Decodable { } return nil } - - - init?(map: Map) { - - } - - mutating func mapping(map: Map) { - isAnonym <- map["isAnonym"] - projectId <- map["projectId"] - uid <- map["uid"] - accessToken <- map["accessToken"] - refreshToken <- map["refreshToken"] - firebaseToken <- map["firebaseToken"] - deltaTime <- map["deltaTime"] - firebase <- map["firebase"] - } } public enum RioClientAuthStatus { @@ -325,7 +308,7 @@ public class Rio { let accessTokenPlugin = AccessTokenPlugin { _ -> String in if let data = self.keychain.getData(RioKeychainKey.token.keyName), let json = try? JSONSerialization.jsonObject(with: data, options: []) { - if let tokenData = Mapper().map(JSONObject: json), let accessToken = tokenData.accessToken { + if let tokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = tokenData.accessToken { return accessToken } } @@ -431,7 +414,7 @@ public class Rio { let json = try! JSONSerialization.jsonObject(with: data, options: []) - if let tokenData = Mapper().map(JSONObject: json), + if let tokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let refreshTokenExpiresAt = tokenData.refreshTokenExpiresAt, let accessTokenExpiresAt = tokenData.accessTokenExpiresAt, let projectId = tokenData.projectId { @@ -470,7 +453,7 @@ public class Rio { // First get last stored token data from keychain. if let data = self.keychain.getData(RioKeychainKey.token.keyName), let json = try? JSONSerialization.jsonObject(with: data, options: []) { - if let storedTokenData = Mapper().map(JSONObject: json), let accessToken = storedTokenData.accessToken { + if let storedTokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = storedTokenData.accessToken { let jwt = try! decode(jwt: accessToken) if let userId = jwt.claim(name: "userId").string { storedUserId = userId @@ -491,8 +474,8 @@ public class Rio { return } - let obj = Mapper().toJSON(tokenData) - guard let data = try? JSONSerialization.data(withJSONObject: obj, options: .prettyPrinted) else { return } + let obj = try? JSONEncoder().encode(tokenData) + guard let object = obj, let data = try? JSONSerialization.data(withJSONObject: object, options: .prettyPrinted) else { return } keychain.set(data, forKey: RioKeychainKey.token.keyName) // ?? logger.log("saveTokenData 2") @@ -807,7 +790,7 @@ public class Rio { if let data = self.keychain.getData(RioKeychainKey.token.keyName), let json = try? JSONSerialization.jsonObject(with: data, options: []) { - if let tokenData = Mapper().map(JSONObject: json), + if let tokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = tokenData.accessToken, let userId = tokenData.userId { @@ -1044,7 +1027,7 @@ public class Rio { var userId = "" if let data = self.keychain.getData(RioKeychainKey.token.keyName), let json = try? JSONSerialization.jsonObject(with: data, options: []) { - if let storedTokenData = Mapper().map(JSONObject: json), let accessToken = storedTokenData.accessToken { + if let storedTokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = storedTokenData.accessToken { let jwt = try! decode(jwt: accessToken) if let id = jwt.claim(name: "userId").string { userId = id @@ -1096,7 +1079,7 @@ public class Rio { var userId: String? if let data = self.keychain.getData(RioKeychainKey.token.keyName) { let json = try! JSONSerialization.jsonObject(with: data, options: []) - if let storedTokenData = Mapper().map(JSONObject: json), let accessToken = storedTokenData.accessToken { + if let storedTokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = storedTokenData.accessToken { let jwt = try! decode(jwt: accessToken) if let id = jwt.claim(name: "userId").string { userId = id @@ -1142,7 +1125,7 @@ public class Rio { private func checkForAuthStatus(isForStatusChangeDelegation: Bool = true) -> RioClientAuthStatus { guard let data = keychain.getData(RioKeychainKey.token.keyName), let json = try? JSONSerialization.jsonObject(with: data, options: []), - let tokenData = Mapper().map(JSONObject: json), + let tokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = tokenData.accessToken, let jwt = try? decode(jwt: accessToken), let userId = jwt.claim(name: "userId").string else { @@ -1380,7 +1363,7 @@ public class RioCloudObjectState { var identity = userIdentity if userId.isEmpty, identity.isEmpty, let data = KeychainSwift().getData(RioKeychainKey.token.keyName), let json = try? JSONSerialization.jsonObject(with: data, options: []) { - if let storedTokenData = Mapper().map(JSONObject: json), let accessToken = storedTokenData.accessToken { + if let storedTokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = storedTokenData.accessToken { let jwt = try! decode(jwt: accessToken) if let id = jwt.claim(name: "userId").string { userId = id @@ -1519,39 +1502,18 @@ public struct RioCloudObjectMethod: Decodable { let tag: String? } -struct CloudOption: Decodable, Mappable { +struct CloudOption: Codable { var customToken: String? var projectId: String? var apiKey: String? var envs: RioFirebaseEnv? - - init?(map: Map) { - - } - - mutating func mapping(map: Map) { - customToken <- map["customToken"] - projectId <- map["projectId"] - apiKey <- map["apiKey"] - envs <- map["envs"] - } } -struct RioFirebaseEnv: Decodable, Mappable { +struct RioFirebaseEnv: Codable { var iosAppId: String? var gcmSenderId: String? - - init?(map: Map) { - - } - - mutating func mapping(map: Map) { - iosAppId <- map["iosAppId"] - gcmSenderId <- map["gcmSenderId"] - } } - public struct RioCloudObjectResponse: Codable { public let statusCode: Int public let headers: [String:String]? diff --git a/Rio/Classes/RioRequests.swift b/Rio/Classes/RioRequests.swift index 2428f093..b3d066f7 100644 --- a/Rio/Classes/RioRequests.swift +++ b/Rio/Classes/RioRequests.swift @@ -6,73 +6,32 @@ // import Foundation -import ObjectMapper import Moya -class GetAnonymTokenRequest : Mappable { +class GetAnonymTokenRequest: Codable { var projectId: String? - - required init?(map: Map) { } - - init() { } - - func mapping(map: Map) { - projectId <- map["projectId"] - } } -class RefreshTokenRequest : Mappable { +class RefreshTokenRequest: Codable { var projectId: String? var refreshToken: String? var userId: String? - - required init?(map: Map) { } - - init() { } - - func mapping(map: Map) { - projectId <- map["projectId"] - refreshToken <- map["refreshToken"] - userId <- map["userId"] - } } -class AuthWithCustomTokenRequest : Mappable { +class AuthWithCustomTokenRequest: Codable { var projectId: String? var customToken: String? var userId: String? - - required init?(map: Map) { } - - init() { } - - func mapping(map: Map) { - projectId <- map["projectId"] - customToken <- map["customToken"] - userId <- map["userId"] - } } -class SignOutRequest : Mappable { +class SignOutRequest: Codable { var projectId: String? var accessToken: String? var userId: String? var type: String? - - required init?(map: Map) { } - - init() { } - - func mapping(map: Map) { - projectId <- map["projectId"] - accessToken <- map["accessToken"] - userId <- map["userId"] - type <- map["type"] - } } -class ExecuteActionRequest : Mappable { - +class ExecuteActionRequest { var projectId: String? var accessToken:String? var actionName:String? @@ -87,19 +46,4 @@ class ExecuteActionRequest : Mappable { var queryString: [String: Any]? var path: String? var isStaticMethod: Bool? - - required init?(map: Map) { } - - init() { - - } - - func mapping(map: Map) { - projectId <- map["projectId"] - accessToken <- map["accessToken"] - actionName <- map["actionName"] - payload <- map["payload"] - headers <- map["headers"] - culture <- map["culture"] - } } diff --git a/Rio/Classes/RioResponses.swift b/Rio/Classes/RioResponses.swift index 70be9076..423680ef 100644 --- a/Rio/Classes/RioResponses.swift +++ b/Rio/Classes/RioResponses.swift @@ -8,7 +8,7 @@ import Foundation import Moya - +/* class GetTokenResponse: Decodable { var accessToken: String? @@ -57,7 +57,7 @@ class ExecuteActionResponse: Decodable { } } } - +*/ enum NetworkError : Error { case connection_lost diff --git a/Rio/Classes/RioService.swift b/Rio/Classes/RioService.swift index 9103ad3c..2e88cc6d 100644 --- a/Rio/Classes/RioService.swift +++ b/Rio/Classes/RioService.swift @@ -8,7 +8,6 @@ import Foundation import Moya -import ObjectMapper import Alamofire @@ -272,7 +271,7 @@ extension RioService: TargetType, AccessTokenAuthorizable { var headers: [String: String] = [:] headers["Content-Type"] = "application/json" headers["x-rio-sdk-client"] = "iOS" - headers["rio-sdk-version"] = "0.0.54" + headers["rio-sdk-version"] = "0.0.55" headers["installationId"] = String.getInstallationId() switch self {