@@ -45,9 +45,6 @@ public class SegmentDestination: DestinationPlugin, Subscriber {
4545 private let uploadsQueue = DispatchQueue ( label: " uploadsQueue.segment.com " )
4646 private var storage : Storage ?
4747
48- private var apiKey : String ? = nil
49- private var apiHost : String ? = nil
50-
5148 @Atomic internal var eventCount : Int = 0
5249 internal var flushAt : Int = 0
5350 internal var flushTimer : QueueTimer ? = nil
@@ -71,11 +68,33 @@ public class SegmentDestination: DestinationPlugin, Subscriber {
7168 }
7269
7370 public func update( settings: Settings , type: UpdateType ) {
71+ guard let analytics = analytics else { return }
7472 let segmentInfo = settings. integrationSettings ( forKey: self . key)
75- apiKey = segmentInfo ? [ Self . Constants. apiKey. rawValue] as? String
76- apiHost = segmentInfo ? [ Self . Constants. apiHost. rawValue] as? String
77- if ( apiHost != nil && apiKey != nil ) , let analytics = self . analytics {
78- httpClient = HTTPClient ( analytics: analytics, apiKey: apiKey, apiHost: apiHost)
73+ // if customer cycles out a writekey at app.segment.com, this is necessary.
74+ /*
75+ This actually works differently than anticipated. It was thought that when a writeKey was
76+ revoked, it's old writekey would redirect to the new, but it doesn't work this way. As a result
77+ it doesn't appear writekey can be changed remotely. Leaving this here in case that changes in the
78+ near future (written on 10/29/2022).
79+ */
80+ /*
81+ if let key = segmentInfo?[Self.Constants.apiKey.rawValue] as? String, key.isEmpty == false {
82+ if key != analytics.configuration.values.writeKey {
83+ /*
84+ - would need to flush.
85+ - would need to change the writeKey across the system.
86+ - would need to re-init storage.
87+ - probably other things too ...
88+ */
89+ }
90+ }
91+ */
92+ // if customer specifies a different apiHost (ie: eu1.segmentapis.com) at app.segment.com ...
93+ if let host = segmentInfo ? [ Self . Constants. apiHost. rawValue] as? String , host. isEmpty == false {
94+ if host != analytics. configuration. values. writeKey {
95+ analytics. configuration. values. apiHost = host
96+ httpClient = HTTPClient ( analytics: analytics)
97+ }
7998 }
8099 }
81100
0 commit comments