Skip to content

Commit

Permalink
Release 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Jul 27, 2021
1 parent 7f9458f commit ac39197
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SensorsABTestSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'signing'
apply plugin: 'maven-publish'

version = "0.0.6"
version = "0.0.7"
android {
compileSdkVersion 29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public void onFailure(int errorCode, String message) {
}

void requestExperiments(final IApiCallback<String> callBack) {
requestExperiments(null, callBack);
}

void requestExperiments(JSONObject object, final IApiCallback<String> callBack) {
String url = null, key = null;
SensorsABTestConfigOptions configOptions = SensorsABTest.shareInstance().getConfigOptions();
if (configOptions != null) {
Expand All @@ -189,7 +193,7 @@ void requestExperiments(final IApiCallback<String> callBack) {
headers.put("project-key", key);
new RequestHelper.Builder(HttpMethod.POST, url)
.header(headers)
.jsonData(new ExperimentRequest().createRequestBody().toString())
.jsonData(new ExperimentRequest(object).createRequestBody().toString())
.callback(new HttpCallback.StringCallback() {
@Override
public void onFailure(final int code, final String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ private void parseCache(String result, ConcurrentHashMap<String, Experiment> has
}
}
}
SALog.i(TAG, "saveExperiments2MemoryCache | experiments:\n" + JSONUtils.formatJson(hashMap.toString()));
}
} catch (Exception e) {
SALog.printStackTrace(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.sensorsdata.abtest.entity.AppConstants;
import com.sensorsdata.abtest.entity.H5Request;
import com.sensorsdata.analytics.android.sdk.SALog;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -66,7 +67,8 @@ public void handlerJSMessage() {
JSONObject data = jsonObject.optJSONObject("data");
if (data != null) {
request.messageId = data.optString("message_id");
new SensorsABTestApiRequestHelper<>().requestExperiments(new IApiCallback<String>() {
final String distinctId = SensorsDataAPI.sharedInstance().getDistinctId();
new SensorsABTestApiRequestHelper<>().requestExperiments(data.optJSONObject("request_body"), new IApiCallback<String>() {
@Override
public void onSuccess(String s) {
if (TextUtils.isEmpty(s)) {
Expand All @@ -90,7 +92,13 @@ public void onSuccess(String s) {
JSONArray array = originObject.optJSONArray("results");
String status = originObject.optString("status");
if (TextUtils.equals(AppConstants.AB_TEST_SUCCESS, status)) {
SensorsABTestCacheManager.getInstance().loadExperimentsFromCache(array != null ? array.toString() : "");
JSONObject obj = null;
if (array != null) {
obj = new JSONObject();
obj.put("experiments", array);
obj.put("distinct_id", distinctId);
}
SensorsABTestCacheManager.getInstance().loadExperimentsFromCache(obj != null ? obj.toString() : "");
}
} catch (JSONException e) {
SALog.printStackTrace(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

public class ExperimentRequest {
private static final String TAG = "SAB.RequestParams";
private JSONObject mJSONObject;

public ExperimentRequest(JSONObject jsonObject) {
this.mJSONObject = jsonObject;
}

public JSONObject createRequestBody() {
JSONObject jsonObject = new JSONObject();
Expand All @@ -41,7 +48,20 @@ public JSONObject createRequestBody() {
jsonObject.put("platform", "Android");
jsonObject.put("properties", getPresetProperties());
jsonObject.put("abtest_lib_version", BuildConfig.SDK_VERSION);

try {
if (mJSONObject != null) {
Iterator<String> iterator = mJSONObject.keys();
while (iterator.hasNext()) {
String key = iterator.next();
String value = mJSONObject.optString(key);
if (!TextUtils.isEmpty(key)) {
jsonObject.put(key, value);
}
}
}
} catch (Exception e) {
SALog.printStackTrace(e);
}
SALog.i(TAG, "getRequestParams | request:\n" + JSONUtils.formatJson(jsonObject.toString()));
} catch (JSONException e) {
SALog.printStackTrace(e);
Expand Down

0 comments on commit ac39197

Please sign in to comment.