RCNConfigSettings.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import Foundation
  2. class RCNConfigSettings {
  3. var customSignals : [String : String] = [:]
  4. var minimumFetchInterval : TimeInterval = RCNConstants.RCNDefaultMinimumFetchInterval
  5. var fetchTimeout : TimeInterval = RCNConstants.RCNHTTPDefaultConnectionTimeout
  6. var lastETag : String? = ""
  7. var lastETagUpdateTime: TimeInterval = 0
  8. var lastFetchTimeInterval : TimeInterval = 0
  9. var lastFetchStatus : FIRRemoteConfigFetchStatus = .noFetchYet
  10. var isFetchInProgress: Bool = false
  11. var exponentialBackoffThrottleEndTime : TimeInterval = 0
  12. var exponentialBackoffRetryInterval : TimeInterval = 0
  13. var lastApplyTimeInterval : TimeInterval = 0
  14. var lastSetDefaultsTimeInterval : TimeInterval = 0
  15. var lastFetchedTemplateVersion : String? = "0"
  16. var lastActiveTemplateVersion : String? = "0"
  17. var configInstallationsToken : String? = ""
  18. var configInstallationsIdentifier : String? = ""
  19. var realtimeExponentialBackoffRetryInterval : TimeInterval = 0
  20. var realtimeExponentialBackoffThrottleEndTime : TimeInterval = 0
  21. var realtimeRetryCount : Int = 0
  22. init() {}
  23. func setRealtimeRetryCount(realtimeRetryCount: Int) {
  24. }
  25. // MARK: - Throttling
  26. func hasMinimumFetchIntervalElapsed(minimumFetchInterval: TimeInterval) -> Bool {
  27. if lastFetchTimeInterval == 0 {
  28. return true
  29. }
  30. // Check if last config fetch is within minimum fetch interval in seconds.
  31. let diffInSeconds = Date().timeIntervalSince1970 - lastFetchTimeInterval
  32. return diffInSeconds > minimumFetchInterval
  33. }
  34. func shouldThrottle() -> Bool {
  35. let now = Date().timeIntervalSince1970
  36. return (self.lastFetchTimeInterval > 0 &&
  37. (self.lastFetchStatus != FIRRemoteConfigFetchStatus.success) &&
  38. (_exponentialBackoffThrottleEndTime - now > 0))
  39. }
  40. //MARK: - update
  41. func updateMetadataWithFetchSuccessStatus(fetchSuccess: Bool, templateVersion: String?) {
  42. }
  43. func updateMetadataTable(){
  44. }
  45. func updateLastFetchTimeInterval(lastFetchTimeInterval: TimeInterval){
  46. }
  47. func updateLastActiveTemplateVersion() {
  48. }
  49. func updateRealtimeExponentialBackoffTime(){
  50. }
  51. func updateExponentialBackoffTime() {
  52. }
  53. func nextRequestWithUserProperties(userProperties: [String : Any]) -> String {
  54. return ""
  55. }
  56. func getRealtimeBackoffInterval() -> TimeInterval {
  57. return 0.0
  58. }
  59. }