Skip to content

Commit

Permalink
Clear data on Identity logout
Browse files Browse the repository at this point in the history
  • Loading branch information
najmsheikh authored and willpassidomo committed Sep 25, 2020
1 parent a7b5a90 commit 2618a18
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
def mParticleKey = "{YOUR-MPARTICLE-KEY}"
def mParticleSecret = "{YOUR-MPARTICLE-SECRET}"
compileSdkVersion 28

defaultConfig {
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/com/mparticle/kits/ButtonKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.mparticle.AttributionResult;
import com.mparticle.commerce.CommerceEvent;
import com.mparticle.commerce.Product;
import com.mparticle.identity.MParticleUser;
import com.mparticle.internal.Logger;

import java.math.BigDecimal;
Expand All @@ -33,8 +34,8 @@
* Learn more at our <a href="https://developer.usebutton.com/guides/merchants/android/button-merchant-integration-guide">Developer Docs</a>
*/
public class ButtonKit extends KitIntegration implements KitIntegration.ActivityListener,
KitIntegration.CommerceListener, ButtonMerchant.AttributionTokenListener,
PostInstallIntentListener {
KitIntegration.CommerceListener, KitIntegration.IdentityListener,
ButtonMerchant.AttributionTokenListener, PostInstallIntentListener {

public static final String ATTRIBUTE_REFERRER = "com.usebutton.source_token";

Expand Down Expand Up @@ -225,6 +226,31 @@ public List<ReportingMessage> logEvent(CommerceEvent commerceEvent) {
return null;
}

/*
* Overrides for IdentityListener
*/

@Override
public void onIdentifyCompleted(MParticleUser mParticleUser,
FilteredIdentityApiRequest filteredIdentityApiRequest) {}

@Override
public void onLoginCompleted(MParticleUser mParticleUser,
FilteredIdentityApiRequest filteredIdentityApiRequest) {}

@Override
public void onLogoutCompleted(MParticleUser mParticleUser,
FilteredIdentityApiRequest filteredIdentityApiRequest) {
merchant.clearAllData(applicationContext);
}

@Override
public void onModifyCompleted(MParticleUser mParticleUser,
FilteredIdentityApiRequest filteredIdentityApiRequest) {}

@Override
public void onUserIdentified(MParticleUser mParticleUser) {}

/*
* Utility methods
*/
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/mparticle/kits/ButtonKitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.mparticle.commerce.CommerceEvent;
import com.mparticle.commerce.Product;
import com.mparticle.identity.IdentityApi;
import com.mparticle.identity.MParticleUser;
import com.mparticle.internal.CoreCallbacks;

import org.json.JSONArray;
Expand Down Expand Up @@ -185,6 +186,13 @@ public void reset_shouldClearAllData() {
verify(merchant).clearAllData(context);
}

@Test
public void onLogoutCompleted_shouldClearAllData() {
buttonKit.onKitCreate(settings, context);
buttonKit.onLogoutCompleted(mock(MParticleUser.class), mock(FilteredIdentityApiRequest.class));
verify(merchant).clearAllData(context);
}

@Test
public void logEvent_noProductAction_shouldIgnoreCall() {
Product product = new Product.Builder("Test", "987", 1).build();
Expand Down

0 comments on commit 2618a18

Please sign in to comment.