ABTExperimentPayload.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. /// Policy for handling the case where there's an overflow of experiments for an installation
  17. /// instance.
  18. typedef NS_ENUM(int32_t, ABTExperimentPayloadExperimentOverflowPolicy) {
  19. ABTExperimentPayloadExperimentOverflowPolicyUnrecognizedValue = 999,
  20. ABTExperimentPayloadExperimentOverflowPolicyUnspecified = 0,
  21. ABTExperimentPayloadExperimentOverflowPolicyDiscardOldest = 1,
  22. ABTExperimentPayloadExperimentOverflowPolicyIgnoreNewest = 2,
  23. };
  24. @interface ABTExperimentLite : NSObject
  25. @property(nonatomic, readonly, copy) NSString *experimentId;
  26. - (instancetype)initWithExperimentId:(NSString *)experimentId NS_DESIGNATED_INITIALIZER;
  27. - (instancetype)init NS_UNAVAILABLE;
  28. @end
  29. @interface ABTExperimentPayload : NSObject
  30. /// Unique identifier for this experiment.
  31. @property(nonatomic, readonly, copy) NSString *experimentId;
  32. /// Unique identifier for the variant to which an installation instance has been assigned.
  33. @property(nonatomic, readonly, copy) NSString *variantId;
  34. /// Epoch time that represents when the experiment was started.
  35. @property(nonatomic, readonly) int64_t experimentStartTimeMillis;
  36. /// The event that triggers this experiment into ON state.
  37. @property(nonatomic, nullable, readonly, copy) NSString *triggerEvent;
  38. /// Duration in milliseconds for which the experiment can stay in STANDBY state (un-triggered).
  39. @property(nonatomic, readonly) int64_t triggerTimeoutMillis;
  40. /// Duration in milliseconds for which the experiment can stay in ON state (triggered).
  41. @property(nonatomic, readonly) int64_t timeToLiveMillis;
  42. /// The event logged when impact service sets the experiment.
  43. @property(nonatomic, readonly, copy) NSString *setEventToLog;
  44. /// The event logged when an experiment goes to the ON state.
  45. @property(nonatomic, readonly, copy) NSString *activateEventToLog;
  46. /// The event logged when an experiment is cleared.
  47. @property(nonatomic, readonly, copy) NSString *clearEventToLog;
  48. /// The event logged when an experiment times out after `triggerTimeoutMillis` milliseconds.
  49. @property(nonatomic, readonly, copy) NSString *timeoutEventToLog;
  50. /// The event logged when an experiment times out after `timeToLiveMillis` milliseconds.
  51. @property(nonatomic, readonly, copy) NSString *ttlExpiryEventToLog;
  52. @property(nonatomic, readonly) ABTExperimentPayloadExperimentOverflowPolicy overflowPolicy;
  53. /// A list of all other ongoing (started, and not yet stopped) experiments at the time this
  54. /// experiment was started. Does not include this experiment; only the others.
  55. @property(nonatomic, readonly) NSArray<ABTExperimentLite *> *ongoingExperiments;
  56. /// Parses an ABTExperimentPayload directly from JSON data.
  57. /// @param data JSON object as NSData. Must be reconstructible as an NSDictionary<NSString* , id>.
  58. + (instancetype)parseFromData:(NSData *)data;
  59. /// Initializes an ABTExperimentPayload from a dictionary with experiment metadata.
  60. - (instancetype)initWithDictionary:(NSDictionary<NSString *, id> *)dictionary
  61. NS_DESIGNATED_INITIALIZER;
  62. - (instancetype)init NS_UNAVAILABLE;
  63. /// Clears the trigger event associated with this payload.
  64. - (void)clearTriggerEvent;
  65. /// Checks if the overflow policy is a valid enum object.
  66. - (BOOL)overflowPolicyIsValid;
  67. @end
  68. NS_ASSUME_NONNULL_END