Skip to content

Commit

Permalink
version 0.0.55
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuzer committed Apr 18, 2024
1 parent a082246 commit 5793692
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 121 deletions.
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")

Expand Down
5 changes: 3 additions & 2 deletions Rio.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
66 changes: 14 additions & 52 deletions Rio/Classes/Rio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import Alamofire
import Moya
import KeychainSwift
import ObjectMapper
import JWTDecode
import Foundation
import FirebaseCore
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<RioTokenData>().map(JSONObject: json), let accessToken = tokenData.accessToken {
if let tokenData = try? JSONDecoder().decode(RioTokenData.self, from: data), let accessToken = tokenData.accessToken {
return accessToken
}
}
Expand Down Expand Up @@ -431,7 +414,7 @@ public class Rio {

let json = try! JSONSerialization.jsonObject(with: data, options: [])

if let tokenData = Mapper<RioTokenData>().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 {
Expand Down Expand Up @@ -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<RioTokenData>().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
Expand All @@ -491,8 +474,8 @@ public class Rio {
return
}

let obj = Mapper<RioTokenData>().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")
Expand Down Expand Up @@ -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<RioTokenData>().map(JSONObject: json),
if let tokenData = try? JSONDecoder().decode(RioTokenData.self, from: data),
let accessToken = tokenData.accessToken,
let userId = tokenData.userId {

Expand Down Expand Up @@ -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<RioTokenData>().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
Expand Down Expand Up @@ -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<RioTokenData>().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
Expand Down Expand Up @@ -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<RioTokenData>().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 {
Expand Down Expand Up @@ -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<RioTokenData>().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
Expand Down Expand Up @@ -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]?
Expand Down
66 changes: 5 additions & 61 deletions Rio/Classes/RioRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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"]
}
}
4 changes: 2 additions & 2 deletions Rio/Classes/RioResponses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Moya


/*
class GetTokenResponse: Decodable {

var accessToken: String?
Expand Down Expand Up @@ -57,7 +57,7 @@ class ExecuteActionResponse: Decodable {
}
}
}

*/

enum NetworkError : Error {
case connection_lost
Expand Down
3 changes: 1 addition & 2 deletions Rio/Classes/RioService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import Moya
import ObjectMapper
import Alamofire


Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5793692

Please sign in to comment.