Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 balancerepository/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
12 changes: 12 additions & 0 deletions balancerepository/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apply from: "$rootProject.projectDir/android-library.gradle"
description = 'Hyperwallet Balance Repository SDK for Android to integrate with the Hyperwallet Platform'
project.ext {
mavenName = 'Hyperwallet Android Balance Repository SDK'
}
apply from: "$rootProject.projectDir/publish.gradle"

dependencies {
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"
testImplementation project(':testutils')
}
21 changes: 21 additions & 0 deletions balancerepository/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions balancerepository/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest
package="com.hyperwallet.android.ui.balance.repository"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2018 Hyperwallet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hyperwallet.android.ui.balance.repository;

import androidx.annotation.NonNull;

import com.hyperwallet.android.model.Errors;
import com.hyperwallet.android.model.balance.Balance;

import java.util.List;

public interface PrepaidCardBalanceRepository {
/**
* Load prepaid card balances
*/
void loadPrepaidCardBalances(String prepaidCardToken, @NonNull final LoadPrepaidCardBalanceCallback callback);

/**
* Load prepaid card balance callback
*/
interface LoadPrepaidCardBalanceCallback {
/**
* On prepaid card balance list loaded
*/
void onPrepaidCardBalanceLoaded(@NonNull final List<Balance> balances);

/**
* On error
*/
void onError(@NonNull final Errors errors);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2018 Hyperwallet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hyperwallet.android.ui.balance.repository;

public class PrepaidCardBalanceRepositoryFactory {
private static PrepaidCardBalanceRepositoryFactory sInstance;
private PrepaidCardBalanceRepository mPrepaidCardBalanceRepository;

private PrepaidCardBalanceRepositoryFactory() {
mPrepaidCardBalanceRepository = new PrepaidCardBalanceRepositoryImpl();
}

public static synchronized PrepaidCardBalanceRepositoryFactory getInstance() {
if (sInstance == null) {
sInstance = new PrepaidCardBalanceRepositoryFactory();
}
return sInstance;
}

public static void clearInstance() {
sInstance = null;
}

public PrepaidCardBalanceRepository getPrepaidCardBalanceRepository() {
return mPrepaidCardBalanceRepository;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2018 Hyperwallet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hyperwallet.android.ui.balance.repository;

import android.os.Handler;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.hyperwallet.android.Hyperwallet;
import com.hyperwallet.android.exception.HyperwalletException;
import com.hyperwallet.android.listener.HyperwalletListener;
import com.hyperwallet.android.model.balance.Balance;
import com.hyperwallet.android.model.balance.PrepaidCardBalanceQueryParam;
import com.hyperwallet.android.model.paging.PageList;

import java.util.ArrayList;

public class PrepaidCardBalanceRepositoryImpl implements PrepaidCardBalanceRepository {

private final Handler mHandler = new Handler();
private final int LIMIT = 100;

@VisibleForTesting
Hyperwallet getHyperwallet() {
return Hyperwallet.getDefault();
}


@Override
public void loadPrepaidCardBalances(String prepaidCardToken,
@NonNull final LoadPrepaidCardBalanceCallback callback) {
PrepaidCardBalanceQueryParam queryParam = new PrepaidCardBalanceQueryParam.Builder()
.limit(LIMIT)
.sortByCurrencyAsc()
.build();

getHyperwallet().listPrepaidCardBalances(prepaidCardToken, queryParam,
new HyperwalletListener<PageList<Balance>>() {
@Override
public void onSuccess(@Nullable PageList<Balance> result) {
callback.onPrepaidCardBalanceLoaded(
result != null ? result.getDataList() : new ArrayList<Balance>());
}

@Override
public void onFailure(HyperwalletException exception) {
callback.onError(exception.getErrors());
}

@Override
public Handler getHandler() {
return mHandler;
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2018 Hyperwallet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hyperwallet.android.ui.balance.repository;

import androidx.annotation.NonNull;

import com.hyperwallet.android.model.Errors;
import com.hyperwallet.android.model.balance.Balance;

import java.util.List;

/**
* User balance repository
*/
public interface UserBalanceRepository {
/**
* Load user balances
*
* @param callback
*/
void loadUserBalances(@NonNull final LoadUserBalanceListCallback callback);

/**
* Load User balance callback
*/
interface LoadUserBalanceListCallback {
/**
* User balance loaded callback
*
* @param balances
*/
void onUserBalanceListLoaded(@NonNull final List<Balance> balances);

/**
* User balance load error
*
* @param errors
*/
void onError(@NonNull final Errors errors);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2018 Hyperwallet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hyperwallet.android.ui.balance.repository;

public class UserBalanceRepositoryFactory {
private static UserBalanceRepositoryFactory sInstance;
private UserBalanceRepository mUserBalanceRepository;

private UserBalanceRepositoryFactory() {
mUserBalanceRepository = new UserBalanceRepositoryImpl();
}

public static synchronized UserBalanceRepositoryFactory getInstance() {
if (sInstance == null) {
sInstance = new UserBalanceRepositoryFactory();
}
return sInstance;
}

public static void clearInstance() {
sInstance = null;
}

public UserBalanceRepository getUserBalanceRepository() {
return mUserBalanceRepository;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2018 Hyperwallet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.hyperwallet.android.ui.balance.repository;

import android.os.Handler;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.hyperwallet.android.Hyperwallet;
import com.hyperwallet.android.exception.HyperwalletException;
import com.hyperwallet.android.listener.HyperwalletListener;
import com.hyperwallet.android.model.balance.Balance;
import com.hyperwallet.android.model.balance.BalanceQueryParam;
import com.hyperwallet.android.model.paging.PageList;

import java.util.ArrayList;

public class UserBalanceRepositoryImpl implements UserBalanceRepository {

private final Handler mHandler = new Handler();
private final int LIMIT = 100;

@VisibleForTesting
Hyperwallet getHyperwallet() {
return Hyperwallet.getDefault();
}

@Override
public void loadUserBalances(@NonNull final LoadUserBalanceListCallback callback) {
BalanceQueryParam queryParam = new BalanceQueryParam.Builder().limit(LIMIT).build();
getHyperwallet().listUserBalances(queryParam, new HyperwalletListener<PageList<Balance>>() {
@Override
public void onSuccess(@Nullable PageList<Balance> result) {
callback.onUserBalanceListLoaded(result != null ? result.getDataList() : new ArrayList<Balance>());
}

@Override
public void onFailure(HyperwalletException exception) {
callback.onError(exception.getErrors());
}

@Override
public Handler getHandler() {
return mHandler;
}
});
}
}
Loading