Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2329] Added apiUrl check in BranchJSONConfig #1183

Merged
merged 11 commits into from
Apr 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ protected void onStart() {
Branch.getInstance().addFacebookPartnerParameterWithName("ph", getHashedValue("6516006060"));
Log.d("BranchSDK_Tester", "initSession");

initSessionsWithTests();
//initSessionsWithTests();

// Branch integration validation: Validate Branch integration with your app
// NOTE : The below method will run few checks for verifying correctness of the Branch integration.
Expand Down
10 changes: 10 additions & 0 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@
// Should only be set in json config
deferInitForPluginRuntime(BranchUtil.getDeferInitForPluginRuntimeConfig(context));

String apiUrl = BranchJsonConfig.getInstance(context).getAPIUrl();
if (!TextUtils.isEmpty(apiUrl)) {
setAPIUrl(apiUrl + "/");

Check warning on line 382 in Branch-SDK/src/main/java/io/branch/referral/Branch.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/Branch.java#L382

Added line #L382 was not covered by tests
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved
}

BranchUtil.setTestMode(BranchUtil.checkTestMode(context));
branchReferral_ = initBranchSDK(context, BranchUtil.readBranchKey(context));
getPreinstallSystemData(branchReferral_, context);
Expand Down Expand Up @@ -404,6 +409,11 @@
// Should only be set in json config
deferInitForPluginRuntime(BranchUtil.getDeferInitForPluginRuntimeConfig(context));

String apiUrl = BranchJsonConfig.getInstance(context).getAPIUrl();
if (!TextUtils.isEmpty(apiUrl)) {
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved
setAPIUrl(apiUrl);

Check warning on line 414 in Branch-SDK/src/main/java/io/branch/referral/Branch.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/Branch.java#L414

Added line #L414 was not covered by tests
}

BranchUtil.setTestMode(BranchUtil.checkTestMode(context));
// If a Branch key is passed already use it. Else read the key
if (!isValidBranchKey(branchKey)) {
Expand Down
20 changes: 18 additions & 2 deletions Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
liveKey,
useTestInstance,
enableLogging,
deferInitForPluginRuntime
deferInitForPluginRuntime,
apiUrl
}

/*
Expand All @@ -44,7 +45,8 @@
"liveKey":"key_live_hcnegAumkH7Kv18M8AOHhfgiohpXq5tB",
"useTestInstance": true,
"enableLogging": true,
"deferInitForPluginRuntime": true
"deferInitForPluginRuntime": true,
"apiUrl": "https://api.branch.io"
}
*/

Expand Down Expand Up @@ -186,4 +188,18 @@
return false;
}
}

@Nullable
public String getAPIUrl() {
if (mConfiguration == null) return null;

try {
if (!mConfiguration.has("apiUrl")) return null;
return mConfiguration.getString("apiUrl");

Check warning on line 198 in Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java#L198

Added line #L198 was not covered by tests
}
catch (JSONException exception) {
Log.e(TAG, "Error parsing branch.json: " + exception.getMessage());
return null;

Check warning on line 202 in Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java#L200-L202

Added lines #L200 - L202 were not covered by tests
}
}
}
Loading