Twitch SDK (Internal)
experimentapi.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2017 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
12 #include "twitchsdk/core/coreapi.h"
13 #include "twitchsdk/core/module.h"
14 
15 
16 namespace ttv
17 {
18  class TaskRunner;
19 
20  namespace experiment
21  {
22  class ExperimentAPI;
23  }
24 }
25 
26 
44 {
45 public:
46  using FetchExperimentsCallback = std::function<void(TTV_ErrorCode ec, const std::shared_ptr<ExperimentSet>& result)>;
47 
48 public:
49  ExperimentAPI();
50  virtual ~ExperimentAPI();
51 
52  // IModule implementation
53  virtual std::string GetModuleName() const override;
54  virtual TTV_ErrorCode Initialize(const InitializeCallback& callback) override;
55  virtual TTV_ErrorCode Shutdown(const ShutdownCallback& callback) override;
56  virtual TTV_ErrorCode Update() override;
57 
58  TTV_ErrorCode SetCoreApi(const std::shared_ptr<CoreAPI>& coreApi);
59  TTV_ErrorCode SetAnalyticsId(const std::string& id);
60 
68  TTV_ErrorCode SetExperiments(const ExperimentSet& experiments);
72  TTV_ErrorCode DeserializeExperiments(const std::string& json, ExperimentSet& result);
78  TTV_ErrorCode DetermineBucket(const std::string& experiment, std::string& result);
82  TTV_ErrorCode SetOverride(const std::string& experimentGuid, const std::string& groupValue);
86  TTV_ErrorCode GetOverride(const std::string& experimentGuid, std::string& result);
90  TTV_ErrorCode GetOverrides(std::map<std::string, std::string>& result);
94  TTV_ErrorCode RemoveOverride(const std::string& experimentGuid);
99 
100 protected:
101  // ModuleBase overrides
102  virtual bool CheckShutdown() override;
103  virtual void CompleteShutdown() override;
104 
105 private:
107  {
108  public:
109  // ICoreApiClient implementation
110  virtual std::string GetClientName();
111  };
112 
113  std::shared_ptr<CoreAPI> mCoreApi;
114  std::shared_ptr<TaskRunner> mTaskRunner;
115  std::shared_ptr<CoreApiClient> mCoreApiClient;
116 
117  ExperimentSet mExperimentSet; // The last fetched experiment set.
118  std::string mAnalyticsId; // The unique id used for hashing and generating buckets for experiments.
119  std::map<std::string, std::string> mOverrides;
120 };
std::shared_ptr< TaskRunner > mTaskRunner
Definition: experimentapi.h:114
TTV_ErrorCode SetOverride(const std::string &experimentGuid, const std::string &groupValue)
Definition: coreapi.h:51
TTV_ErrorCode GetOverride(const std::string &experimentGuid, std::string &result)
Definition: experimentapi.h:106
virtual void CompleteShutdown() override
std::shared_ptr< CoreAPI > mCoreApi
Definition: experimentapi.h:113
virtual bool CheckShutdown() override
TTV_ErrorCode GetOverrides(std::map< std::string, std::string > &result)
Definition: experimentapi.h:43
std::function< void(TTV_ErrorCode ec)> InitializeCallback
Definition: module.h:48
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
TTV_ErrorCode SetExperiments(const ExperimentSet &experiments)
virtual TTV_ErrorCode Initialize(const InitializeCallback &callback) override
TTV_ErrorCode DetermineBucket(const std::string &experiment, std::string &result)
TTV_ErrorCode FetchExperiments(const FetchExperimentsCallback &callback)
TTV_ErrorCode RemoveOverride(const std::string &experimentGuid)
std::map< std::string, std::string > mOverrides
Definition: experimentapi.h:119
uint32_t TTV_ErrorCode
Definition: errortypes.h:30
virtual TTV_ErrorCode Update() override
std::function< void(TTV_ErrorCode ec)> ShutdownCallback
Definition: module.h:49
Definition: experimenttypes.h:33
std::string mAnalyticsId
Definition: experimentapi.h:118
TTV_ErrorCode SetCoreApi(const std::shared_ptr< CoreAPI > &coreApi)
std::function< void(TTV_ErrorCode ec, const std::shared_ptr< ExperimentSet > &result)> FetchExperimentsCallback
Definition: experimentapi.h:46
TTV_ErrorCode SetAnalyticsId(const std::string &id)
TTV_ErrorCode DeserializeExperiments(const std::string &json, ExperimentSet &result)
Definition: module.h:85
virtual std::string GetModuleName() const override
virtual TTV_ErrorCode Shutdown(const ShutdownCallback &callback) override
std::shared_ptr< CoreApiClient > mCoreApiClient
Definition: experimentapi.h:115
ExperimentSet mExperimentSet
Definition: experimentapi.h:117