Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: DVC-8020 rename DVC to DevCycle on public interfaces #169

Merged
merged 11 commits into from
Jul 21, 2023
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "LaunchDarkly/swift-eventsource" "3.0.0"
github "LaunchDarkly/swift-eventsource" "3.1.1"
104 changes: 52 additions & 52 deletions DevCycle.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

47 changes: 25 additions & 22 deletions DevCycle/DVCClient.swift → DevCycle/DevCycleClient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DVCClient.swift
// DevCycleClient.swift
// DevCycle-iOS-SDK
//
//
Expand Down Expand Up @@ -28,12 +28,12 @@ public typealias IdentifyCompletedHandler = (Error?, [String: Variable]?) -> Voi
public typealias FlushCompletedHandler = (Error?) -> Void
public typealias CloseCompletedHandler = () -> Void

public class DVCClient {
public class DevCycleClient {
var sdkKey: String?
var user: DVCUser?
var lastIdentifiedUser: DVCUser?
var user: DevCycleUser?
var lastIdentifiedUser: DevCycleUser?
var config: DVCConfig?
var options: DVCOptions?
var options: DevCycleOptions?
var configCompletionHandlers: [ClientInitializedHandler] = []
var initialized: Bool = false
var eventQueue: EventQueue = EventQueue()
Expand Down Expand Up @@ -196,11 +196,11 @@ public class DVCClient {
self.sdkKey = sdkKey
}

func setUser(_ user: DVCUser) {
func setUser(_ user: DevCycleUser) {
self.user = user
}

func setOptions(_ options: DVCOptions) {
func setOptions(_ options: DevCycleOptions) {
self.options = options
}

Expand All @@ -219,7 +219,7 @@ public class DVCClient {
}
}

private func cacheUser(user: DVCUser) {
private func cacheUser(user: DevCycleUser) {
self.cacheService.save(user: user)
if user.isAnonymous == true, let userId = user.userId {
self.cacheService.setAnonUserId(anonUserId: userId)
Expand Down Expand Up @@ -313,12 +313,12 @@ public class DVCClient {
}
}

public func identifyUser(user: DVCUser, callback: IdentifyCompletedHandler? = nil) throws {
public func identifyUser(user: DevCycleUser, callback: IdentifyCompletedHandler? = nil) throws {
guard let currentUser = self.user, let userId = currentUser.userId, let incomingUserId = user.userId else {
throw ClientError.InvalidUser
}
self.flushEvents()
var updateUser: DVCUser = currentUser
var updateUser: DevCycleUser = currentUser
if (userId == incomingUserId) {
updateUser.update(with: user)
} else {
Expand Down Expand Up @@ -351,7 +351,7 @@ public class DVCClient {

let cachedAnonUserId = self.cacheService.getAnonUserId()
self.cacheService.clearAnonUserId()
let anonUser = try DVCUser.builder().isAnonymous(true).build()
let anonUser = try DevCycleUser.builder().isAnonymous(true).build()

self.lastIdentifiedUser = anonUser

Expand Down Expand Up @@ -384,9 +384,9 @@ public class DVCClient {
return self.config?.userConfig?.variables ?? [:]
}

public func track(_ event: DVCEvent) {
public func track(_ event: DevCycleEvent) {
if (self.closed) {
Log.error("DVCClient is closed, cannot log new events.")
Log.error("DevCycleClient is closed, cannot log new events.")
return
}
if(!self.disableCustomEventLogging){
Expand Down Expand Up @@ -419,10 +419,10 @@ public class DVCClient {

public func close(callback: CloseCompletedHandler?) {
if (self.closed) {
Log.error("DVC Client is already closed.")
Log.error("DevCycleClient is already closed.")
return
}
Log.info("Closing DVC client and flushing remaining events.")
Log.info("Closing DevCycleClient and flushing remaining events.")
self.closed = true
self.flushTimer?.invalidate()
self.flushEvents(callback: { error in
Expand All @@ -432,14 +432,14 @@ public class DVCClient {
}

public class ClientBuilder {
private var client: DVCClient
private var client: DevCycleClient
private var service: DevCycleServiceProtocol?

init() {
self.client = DVCClient()
self.client = DevCycleClient()
}

@available(*, deprecated)
@available(*, deprecated, message: "Use sdkKey()")
public func environmentKey(_ key: String) -> ClientBuilder {
self.client.setSDKKey(key)
return self
Expand All @@ -450,12 +450,12 @@ public class DVCClient {
return self
}

public func user(_ user: DVCUser) -> ClientBuilder {
public func user(_ user: DevCycleUser) -> ClientBuilder {
self.client.setUser(user)
return self
}

public func options(_ options: DVCOptions) -> ClientBuilder {
public func options(_ options: DevCycleOptions) -> ClientBuilder {
self.client.setOptions(options)
return self
}
Expand All @@ -465,7 +465,7 @@ public class DVCClient {
return self
}

public func build(onInitialized: ClientInitializedHandler?) throws -> DVCClient {
public func build(onInitialized: ClientInitializedHandler?) throws -> DevCycleClient {
guard self.client.sdkKey != nil else {
Log.error("Missing SDK Key", tags: ["build"])
throw ClientError.MissingSDKKeyOrUser
Expand All @@ -481,7 +481,7 @@ public class DVCClient {
} else {
result.initialize(callback: onInitialized)
}
self.client = DVCClient()
self.client = DevCycleClient()
return result
}
}
Expand All @@ -507,3 +507,6 @@ public class DVCClient {
DispatchQueue.main.asyncAfter(deadline: .now() + Double(delay), execute: work)
}
}

@available(*, deprecated, message: "Use DevCycleClient")
public typealias DVCClient = DevCycleClient
22 changes: 12 additions & 10 deletions DevCycle/DVCUser.swift → DevCycle/DevCycleUser.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//
// DVCUser.swift
// DevCycleUser.swift
// DevCycle-iOS-SDK
//
//

import Foundation

Expand All @@ -21,12 +20,12 @@ enum UserError: Error {
public class UserBuilder {
private let cacheService: CacheServiceProtocol = CacheService()

var user: DVCUser
var user: DevCycleUser
var customData: [String: Any]?
var privateCustomData: [String: Any]?

init() {
self.user = DVCUser()
self.user = DevCycleUser()
}

public func userId(_ userId: String) -> UserBuilder {
Expand Down Expand Up @@ -79,7 +78,7 @@ public class UserBuilder {
return self
}

public func build() throws -> DVCUser {
public func build() throws -> DevCycleUser {
guard self.user.userId?.trimmingCharacters(in: .whitespacesAndNewlines) != ""
else {
throw UserError.InvalidUser
Expand All @@ -105,15 +104,15 @@ public class UserBuilder {
}

let result = self.user
self.user = DVCUser()
self.user = DevCycleUser()
self.customData = nil
self.privateCustomData = nil
return result
}
}


public class DVCUser: Codable {
public class DevCycleUser: Codable {
public var userId: String?
public var isAnonymous: Bool?
public var email: String?
Expand Down Expand Up @@ -152,7 +151,7 @@ public class DVCUser: Codable {
case isAnonymous, email, name, language, country, appVersion, appBuild, customData, privateCustomData, lastSeenDate, createdDate, platform, platformVersion, deviceModel, sdkType, sdkVersion
}

public func update(with user: DVCUser) {
public func update(with user: DevCycleUser) {
self.lastSeenDate = Date()
self.email = user.email
self.name = user.name
Expand Down Expand Up @@ -199,11 +198,14 @@ public class DVCUser: Codable {
}
}

@available(*, deprecated, message: "Use DevCycleUser")
public typealias DVCUser = DevCycleUser

class QueryItemBuilder {
var items: [URLQueryItem]
let user: DVCUser
let user: DevCycleUser

init(user: DVCUser) {
init(user: DevCycleUser) {
self.items = []
self.user = user
}
Expand Down
20 changes: 10 additions & 10 deletions DevCycle/Models/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import Foundation

protocol CacheServiceProtocol {
func load() -> Cache
func save(user: DVCUser)
func save(user: DevCycleUser)
func setAnonUserId(anonUserId: String)
func getAnonUserId() -> String?
func clearAnonUserId()
func saveConfig(user: DVCUser, fetchDate: Int, configToSave: Data?)
func getConfig(user: DVCUser, ttlMs: Int) -> UserConfig?
func saveConfig(user: DevCycleUser, fetchDate: Int, configToSave: Data?)
func getConfig(user: DevCycleUser, ttlMs: Int) -> UserConfig?
}

struct Cache {
var config: UserConfig?
var user: DVCUser?
var user: DevCycleUser?
var anonUserId: String?
}

Expand All @@ -35,22 +35,22 @@ class CacheService: CacheServiceProtocol {

func load() -> Cache {
var userConfig: UserConfig?
var dvcUser: DVCUser?
var dvcUser: DevCycleUser?
if let data = defaults.object(forKey: CacheKeys.config) as? Data,
let dictionary = try? JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed) as? [String:Any],
let config = try? UserConfig(from: dictionary)
{
userConfig = config
}
if let data = defaults.object(forKey: CacheKeys.user) as? Data {
dvcUser = try? JSONDecoder().decode(DVCUser.self, from: data)
dvcUser = try? JSONDecoder().decode(DevCycleUser.self, from: data)
}
let anonUserId = self.getAnonUserId()

return Cache(config: userConfig, user: dvcUser, anonUserId: anonUserId)
}

func save(user: DVCUser) {
func save(user: DevCycleUser) {
if let data = try? JSONEncoder().encode(user) {
defaults.set(data, forKey: CacheKeys.user)
}
Expand All @@ -68,7 +68,7 @@ class CacheService: CacheServiceProtocol {
self.remove(key: CacheKeys.anonUserId)
}

func saveConfig(user: DVCUser, fetchDate: Int, configToSave: Data?) {
func saveConfig(user: DevCycleUser, fetchDate: Int, configToSave: Data?) {
let key = getConfigKeyPrefix(user: user)
defaults.set(configToSave, forKey: key)
if let data = user.userId {
Expand All @@ -77,7 +77,7 @@ class CacheService: CacheServiceProtocol {
self.setInt(key: "\(key).FETCH_DATE", value: fetchDate)
}

func getConfig(user: DVCUser, ttlMs: Int) -> UserConfig? {
func getConfig(user: DevCycleUser, ttlMs: Int) -> UserConfig? {
let key = getConfigKeyPrefix(user: user)
var config: UserConfig?

Expand Down Expand Up @@ -125,7 +125,7 @@ class CacheService: CacheServiceProtocol {
defaults.removeObject(forKey: key)
}

private func getConfigKeyPrefix(user: DVCUser) -> String {
private func getConfigKeyPrefix(user: DevCycleUser) -> String {
return (user.isAnonymous ?? false) ? CacheKeys.anonymousConfigKey : CacheKeys.identifiedConfigKey
}
}
4 changes: 2 additions & 2 deletions DevCycle/Models/DVCConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation

public class DVCConfig {
var sdkKey: String
var user: DVCUser
var user: DevCycleUser
var userConfig: UserConfig? {
didSet {
if let userConfig = self.userConfig {
Expand All @@ -21,7 +21,7 @@ public class DVCConfig {
}
}

init(sdkKey: String, user: DVCUser) {
init(sdkKey: String, user: DevCycleUser) {
self.sdkKey = sdkKey
self.user = user
}
Expand Down
Loading
Loading