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

Set koala's base url based on current environment #820

Merged
merged 1 commit into from
Aug 28, 2019
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
2 changes: 1 addition & 1 deletion Library/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public struct Environment {
environmentVariables: EnvironmentVariables = EnvironmentVariables(),
is1PasswordSupported: @escaping () -> Bool = { ksr_is1PasswordSupported() },
isVoiceOverRunning: @escaping () -> Bool = { UIAccessibility.isVoiceOverRunning },
koala: Koala = Koala(client: KoalaTrackingClient(endpoint: .production)),
koala: Koala = Koala(client: KoalaTrackingClient()),
language: Language = Language(languageStrings: Locale.preferredLanguages) ?? Language.en,
launchedCountries: LaunchedCountries = .init(),
locale: Locale = .current,
Expand Down
23 changes: 8 additions & 15 deletions Library/Koala/KoalaTrackingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@ private let flushInterval = 60.0
private let chunkSize = 4

public final class KoalaTrackingClient: TrackingClientType {
fileprivate let endpoint: Endpoint
fileprivate let URLSession: URLSession
fileprivate let queue = DispatchQueue(label: "com.kickstarter.KoalaTrackingClient")
fileprivate var buffer: [[String: Any]] = []
fileprivate var timer: Timer?
fileprivate var taskId = UIBackgroundTaskIdentifier.invalid

public enum Endpoint {
case staging
case production

var base: String {
switch self {
case .staging:
return Secrets.KoalaEndpoint.staging
case .production:
return Secrets.KoalaEndpoint.production
}
fileprivate var base: String {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since our base url is being affected by environmentType we no longer require a separate Endpoint enum.

switch AppEnvironment.current.environmentType {
case .production:
return Secrets.KoalaEndpoint.production
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only production will go to production ... anything else (development or local) should default to staging

default:
return Secrets.KoalaEndpoint.staging
}
}

public init(endpoint: Endpoint = .production, URLSession: URLSession = .shared) {
self.endpoint = endpoint
public init(URLSession: URLSession = .shared) {
self.URLSession = URLSession

let notifications = NotificationCenter.default
Expand Down Expand Up @@ -130,7 +123,7 @@ public final class KoalaTrackingClient: TrackingClientType {
if dataString.count >= 10_000 {
print("🐨 [Koala Error]: Base64 payload is longer than 10,000 characters.")
}
return URL(string: "\(self.endpoint.base)?data=\(dataString)")
return URL(string: "\(self.base)?data=\(dataString)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately KoalaClient isn't very testable (most if not all functions are fileprivate) so I'd suggest we proceed without tests for now (as I wasn't able to figure out how to test)...open to any suggestions!!!

}

fileprivate static func koalaRequest(_ url: URL) -> URLRequest {
Expand Down