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

fix: remove some unused code and add periphery api #235

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
retain_public: true
targets:
- PostHog
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build buildSdk buildExamples format swiftLint swiftFormat test testOniOSSimulator testOnMacSimulator lint bootstrap releaseCocoaPods
.PHONY: build buildSdk buildExamples format swiftLint swiftFormat test testOniOSSimulator testOnMacSimulator lint bootstrap releaseCocoaPods api

build: buildSdk buildExamples

Expand Down Expand Up @@ -45,12 +45,18 @@ test:
lint:
swiftformat . --lint --swiftversion 5.3 && swiftlint

# periphery scan --setup
# TODO: add periphery to the CI/commit prehooks
api:
periphery scan

# requires gem and brew
# xcpretty needs 'export LANG=en_US.UTF-8'
bootstrap:
gem install xcpretty
brew install swiftlint
brew install swiftformat
brew install peripheryapp/periphery/periphery

releaseCocoaPods:
pod trunk push PostHog.podspec --allow-warnings
9 changes: 0 additions & 9 deletions PostHog/Models/PostHogEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ public class PostHogEvent {
// Only used for Replay
public var apiKey: String?

enum Key: String {
case event
case distinctId
case properties
case timestamp
case uuid
case apiKey
}

init(event: String, distinctId: String, properties: [String: Any]? = nil, timestamp: Date = Date(), uuid: UUID = UUID.v7(), apiKey: String? = nil) {
self.event = event
self.distinctId = distinctId
Expand Down
1 change: 1 addition & 0 deletions PostHog/PostHogFileBackedQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PostHogFileBackedQueue {
}
}

/// Internal, used for testing
func clear() {
deleteSafely(queue)
setup(oldQueue: nil)
Expand Down
5 changes: 2 additions & 3 deletions PostHog/PostHogQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class PostHogQueue {
}

private let config: PostHogConfig
private let storage: PostHogStorage
private let api: PostHogApi
private var paused: Bool = false
private let pausedLock = NSLock()
Expand All @@ -41,6 +40,7 @@ class PostHogQueue {
private let endpoint: PostHogApiEndpoint
private let dispatchQueue: DispatchQueue

/// Internal, used for testing
var depth: Int {
fileQueue.depth
}
Expand All @@ -50,7 +50,6 @@ class PostHogQueue {
#if !os(watchOS)
init(_ config: PostHogConfig, _ storage: PostHogStorage, _ api: PostHogApi, _ endpoint: PostHogApiEndpoint, _ reachability: Reachability?) {
self.config = config
self.storage = storage
self.api = api
self.reachability = reachability
self.endpoint = endpoint
Expand All @@ -67,7 +66,6 @@ class PostHogQueue {
#else
init(_ config: PostHogConfig, _ storage: PostHogStorage, _ api: PostHogApi, _ endpoint: PostHogApiEndpoint) {
self.config = config
self.storage = storage
self.api = api
self.endpoint = endpoint

Expand Down Expand Up @@ -173,6 +171,7 @@ class PostHogQueue {
}
}

/// Internal, used for testing
func clear() {
fileQueue.clear()
}
Expand Down
15 changes: 6 additions & 9 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ let maxRetryDelay = 30.0

private var queue: PostHogQueue?
private var replayQueue: PostHogQueue?
private var api: PostHogApi?
private var storage: PostHogStorage?
#if !os(watchOS)
private var reachability: Reachability?
Expand Down Expand Up @@ -98,9 +97,8 @@ let maxRetryDelay = 30.0
self.config = config
let theStorage = PostHogStorage(config)
storage = theStorage
let theApi = PostHogApi(config)
api = theApi
featureFlags = PostHogFeatureFlags(config, theStorage, theApi)
let api = PostHogApi(config)
featureFlags = PostHogFeatureFlags(config, theStorage, api)
config.storageManager = config.storageManager ?? PostHogStorageManager(config)
#if os(iOS)
replayIntegration = PostHogReplayIntegration(config)
Expand All @@ -122,11 +120,11 @@ let maxRetryDelay = 30.0
}

#if !os(watchOS)
queue = PostHogQueue(config, theStorage, theApi, .batch, reachability)
replayQueue = PostHogQueue(config, theStorage, theApi, .snapshot, reachability)
queue = PostHogQueue(config, theStorage, api, .batch, reachability)
replayQueue = PostHogQueue(config, theStorage, api, .snapshot, reachability)
#else
queue = PostHogQueue(config, theStorage, theApi, .batch)
replayQueue = PostHogQueue(config, theStorage, theApi, .snapshot)
queue = PostHogQueue(config, theStorage, api, .batch)
replayQueue = PostHogQueue(config, theStorage, api, .snapshot)
#endif

queue?.start(disableReachabilityForTesting: config.disableReachabilityForTesting,
Expand Down Expand Up @@ -939,7 +937,6 @@ let maxRetryDelay = 30.0
config.storageManager?.reset()
config.storageManager = nil
config = PostHogConfig(apiKey: "")
api = nil
featureFlags = nil
storage = nil
#if !os(watchOS)
Expand Down
4 changes: 0 additions & 4 deletions PostHog/PostHogStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ class PostHogStorage {
case personProcessingEnabled = "posthog.enabledPersonProcessing"
}

private let config: PostHogConfig

// The location for storing data that we always want to keep
let appFolderUrl: URL

init(_ config: PostHogConfig) {
self.config = config

appFolderUrl = Self.getAppFolderUrl(from: config)

createDirectoryAtURLIfNeeded(url: appFolderUrl)
Expand Down
8 changes: 0 additions & 8 deletions PostHog/Utils/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ struct InternalPostHogError: Error, CustomStringConvertible {
self.description = "\(description) (\(fileID):\(line))"
}
}

struct FatalPostHogError: Error, CustomStringConvertible {
let description: String

init(description: String, fileID: StaticString = #fileID, line: UInt = #line) {
self.description = "Fatal PostHog error: \(description) (\(fileID):\(line))"
}
}
12 changes: 0 additions & 12 deletions PostHog/Utils/Reachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ import Foundation
}
}

private var isRunningOnDevice: Bool = {
#if targetEnvironment(simulator)
return false
#else
return true
#endif
}()

private(set) var notifierRunning = false
private let reachabilityRef: SCNetworkReachability
private let reachabilitySerialQueue: DispatchQueue
Expand Down Expand Up @@ -356,10 +348,6 @@ import Foundation
contains(.isDirect)
}

var isConnectionRequiredAndTransientFlagSet: Bool {
intersection([.connectionRequired, .transientConnection]) == [.connectionRequired, .transientConnection]
}

var description: String {
let W = isOnWWANFlagSet ? "W" : "-"
let R = isReachableFlagSet ? "R" : "-"
Expand Down
Loading