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

Rename parseResult to completeRequest #101

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Add `BrowserSwitchRequest` and `BrowserSwitchPendingRequest`
* Convert `BrowserSwitchResult` to sealed class and add `BrowserSwitchResultInfo`
* Remove `BrowserSwitchStatus`
* Rename `parseResult()` to `completeRequest()`

## 2.6.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public BrowserSwitchClient() {
* @param activity the activity used to start browser switch
* @param browserSwitchOptions {@link BrowserSwitchOptions} the options used to configure the browser switch
* @return a {@link BrowserSwitchPendingRequest.Started} that should be stored and passed to
* {@link BrowserSwitchClient#parseResult(BrowserSwitchPendingRequest.Started, Intent)} upon return to the app,
* {@link BrowserSwitchClient#completeRequest(BrowserSwitchPendingRequest.Started, Intent)} upon return to the app,
* or {@link BrowserSwitchPendingRequest.Failure} if browser could not be launched.
*/
@NonNull
Expand Down Expand Up @@ -115,7 +115,8 @@ private boolean isValidRequestCode(int requestCode) {
}

/**
* Parses and returns a browser switch result if a match is found for the given {@link BrowserSwitchRequest}
* Completes the browser switch flow and returns a browser switch result if a match is found for
* the given {@link BrowserSwitchRequest}
* @param pendingRequest the {@link BrowserSwitchPendingRequest.Started} returned from
* {@link BrowserSwitchClient#start(ComponentActivity, BrowserSwitchOptions)}
* @param intent the intent to return to your application containing a deep link result from the
Expand All @@ -125,7 +126,7 @@ private boolean isValidRequestCode(int requestCode) {
* {@link BrowserSwitchPendingRequest.Started}. A {@link BrowserSwitchResult.NoResult} will be
* returned if the user returns to the app without completing the browser switch flow.
*/
public BrowserSwitchResult parseResult(@NonNull BrowserSwitchPendingRequest.Started pendingRequest, @Nullable Intent intent) {
public BrowserSwitchResult completeRequest(@NonNull BrowserSwitchPendingRequest.Started pendingRequest, @Nullable Intent intent) {
if (intent != null && intent.getData() != null) {
Uri deepLinkUrl = intent.getData();
if (pendingRequest.getBrowserSwitchRequest().matchesDeepLinkUrlScheme(deepLinkUrl)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.json.JSONException

/**
* A pending request for browser switching. This pending request should be stored locally within the app or
* on-device and used to deliver a result of the browser flow in [BrowserSwitchClient.parseResult]
* on-device and used to deliver a result of the browser flow in [BrowserSwitchClient.completeRequest]
*/
sealed class BrowserSwitchPendingRequest {

/**
* A browser switch was successfully started. This pending request should be store dnd passed to
* [BrowserSwitchClient.parseResult]
* [BrowserSwitchClient.completeRequest]
*/
class Started(val browserSwitchRequest: BrowserSwitchRequest) : BrowserSwitchPendingRequest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.braintreepayments.api

/**
* The result of a browser switch obtained from [BrowserSwitchClient.parseResult]
* The result of a browser switch obtained from [BrowserSwitchClient.completeRequest]
*/
sealed class BrowserSwitchResult {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void start_whenNoReturnUrlSchemeSet_throwsFailure() {
}

@Test
public void parseResult_whenActiveRequestMatchesDeepLinkResultURLScheme_returnsBrowserSwitchSuccessResult() {
public void completeRequest_whenActiveRequestMatchesDeepLinkResultURLScheme_returnsBrowserSwitchSuccessResult() {
BrowserSwitchClient sut = new BrowserSwitchClient(browserSwitchInspector,
customTabsInternalClient);

Expand All @@ -188,14 +188,14 @@ public void parseResult_whenActiveRequestMatchesDeepLinkResultURLScheme_returnsB

Uri deepLinkUrl = Uri.parse("fake-url-scheme://success");
Intent intent = new Intent(Intent.ACTION_VIEW, deepLinkUrl);
BrowserSwitchResult browserSwitchResult = sut.parseResult(new BrowserSwitchPendingRequest.Started(request), intent);
BrowserSwitchResult browserSwitchResult = sut.completeRequest(new BrowserSwitchPendingRequest.Started(request), intent);

assertTrue(browserSwitchResult instanceof BrowserSwitchResult.Success);
assertEquals(deepLinkUrl, ((BrowserSwitchResult.Success) browserSwitchResult).getResultInfo().getDeepLinkUrl());
}

@Test
public void parseResult_whenDeepLinkResultURLSchemeDoesntMatch_returnsNoResult() {
public void completeRequest_whenDeepLinkResultURLSchemeDoesntMatch_returnsNoResult() {
BrowserSwitchClient sut = new BrowserSwitchClient(browserSwitchInspector,
customTabsInternalClient);

Expand All @@ -205,21 +205,21 @@ public void parseResult_whenDeepLinkResultURLSchemeDoesntMatch_returnsNoResult()

Uri deepLinkUrl = Uri.parse("a-different-url-scheme://success");
Intent intent = new Intent(Intent.ACTION_VIEW, deepLinkUrl);
BrowserSwitchResult browserSwitchResult = sut.parseResult(new BrowserSwitchPendingRequest.Started(request), intent);
BrowserSwitchResult browserSwitchResult = sut.completeRequest(new BrowserSwitchPendingRequest.Started(request), intent);

assertTrue(browserSwitchResult instanceof BrowserSwitchResult.NoResult);
}

@Test
public void parseResult_whenIntentIsNull_returnsNoResult() {
public void completeRequest_whenIntentIsNull_returnsNoResult() {
BrowserSwitchClient sut = new BrowserSwitchClient(browserSwitchInspector,
customTabsInternalClient);

JSONObject requestMetadata = new JSONObject();
BrowserSwitchRequest request =
new BrowserSwitchRequest(123, browserSwitchDestinationUrl, requestMetadata, "fake-url-scheme", false);

BrowserSwitchResult browserSwitchResult = sut.parseResult(new BrowserSwitchPendingRequest.Started(request), null);
BrowserSwitchResult browserSwitchResult = sut.completeRequest(new BrowserSwitchPendingRequest.Started(request), null);
assertTrue(browserSwitchResult instanceof BrowserSwitchResult.NoResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ComposeActivity : ComponentActivity() {
super.onResume()
PendingRequestStore.get(this)?.let { startedRequest ->
when (val browserSwitchResult =
browserSwitchClient.parseResult(startedRequest, intent)) {
browserSwitchClient.completeRequest(startedRequest, intent)) {
is BrowserSwitchResult.Success -> viewModel.browserSwitchResult =
browserSwitchResult.resultInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void onNewIntent(Intent intent) {

BrowserSwitchPendingRequest.Started pendingRequest = PendingRequestStore.Companion.get(this);
if (pendingRequest != null) {
BrowserSwitchResult result = browserSwitchClient.parseResult(pendingRequest, intent);
BrowserSwitchResult result = browserSwitchClient.completeRequest(pendingRequest, intent);
if (result instanceof BrowserSwitchResult.Success) {
Objects.requireNonNull(getDemoFragment()).onBrowserSwitchResult(((BrowserSwitchResult.Success) result).getResultInfo());
}
Expand Down
Loading