<commit_before>package de.fau.amos.virtualledger.android.api.banking;

import android.util.Log;

import java.util.List;

import de.fau.amos.virtualledger.android.api.Restapi;
import de.fau.amos.virtualledger.android.api.shared.CallWithToken;
import de.fau.amos.virtualledger.android.api.shared.TokenCallback;
import de.fau.amos.virtualledger.dtos.BankAccess;
import de.fau.amos.virtualledger.dtos.BankAccessCredential;
import de.fau.amos.virtualledger.dtos.BankAccountSync;
import de.fau.amos.virtualledger.dtos.BankAccountSyncResult;
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by sebastian on 14.05.17.
 */

public class HTTPBankingProvider implements BankingProvider {

    private static final String TAG = "HTTPBankingProvider";

    private Retrofit retrofit;
    private CallWithToken callWithToken;

    public HTTPBankingProvider(Retrofit retrofit, final CallWithToken callWithToken) {
        this.retrofit = retrofit;
        this.callWithToken = callWithToken;
    }

    @Override
    public Observable<List<BankAccess>> getBankingOverview() {
        final PublishSubject observable = PublishSubject.create();

        callWithToken.callWithToken(observable, new TokenCallback() {
            @Override
            public void onReceiveToken(final String token) {
                // got token
                final retrofit2.Call<List<BankAccess>> responseMessage = retrofit.create(Restapi.class).getBankAccesses(token);

                responseMessage.enqueue(new Callback<List<BankAccess>>() {
                    @Override
                    public void onResponse(retrofit2.Call<List<BankAccess>> call, Response<List<BankAccess>> response) {
                        // got response from server
                        if (response.isSuccessful()) {
                            List<BankAccess> bankAccesses = response.body();
                            Log.v(TAG, "Fetching of bank accesses was successful " + response.code());
                            observable.onNext(bankAccesses);
                        } else {
                            Log.e(TAG, "Fetchin of bank accesses was not successful! ERROR " + response.code());
                            observable.onError(new Throwable("Fetching of bank accesses was not successful!"));
                        }
                    }


                    @Override
                    public void onFailure(retrofit2.Call<List<BankAccess>> call, Throwable t) {
                        // response of server failed
                        Log.e(TAG, "No connection to server!");
                        observable.onError(new Throwable("No connection to server!"));
                    }
                });
            }
        });

        return observable;
    }

    @Override
    public Observable<BankAccountSyncResult> getBankingTransactions(final List<BankAccountSync> bankAccountSyncList) {

        final PublishSubject observable = PublishSubject.create();

        callWithToken.callWithToken(observable, new TokenCallback() {<commit_msg>User general callback for getBankingOverview<commit_after>package de.fau.amos.virtualledger.android.api.banking;

import android.util.Log;

import java.util.List;

import de.fau.amos.virtualledger.android.api.Restapi;
import de.fau.amos.virtualledger.android.api.shared.CallWithToken;
import de.fau.amos.virtualledger.android.api.shared.RetrofitCallback;
import de.fau.amos.virtualledger.android.api.shared.TokenCallback;
import de.fau.amos.virtualledger.dtos.BankAccess;
import de.fau.amos.virtualledger.dtos.BankAccessCredential;
import de.fau.amos.virtualledger.dtos.BankAccountSync;
import de.fau.amos.virtualledger.dtos.BankAccountSyncResult;
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by sebastian on 14.05.17.
 */

public class HTTPBankingProvider implements BankingProvider {

    private static final String TAG = "HTTPBankingProvider";

    private Retrofit retrofit;
    private CallWithToken callWithToken;

    public HTTPBankingProvider(Retrofit retrofit, final CallWithToken callWithToken) {
        this.retrofit = retrofit;
        this.callWithToken = callWithToken;
    }

    @Override
    public Observable<List<BankAccess>> getBankingOverview() {
        final PublishSubject observable = PublishSubject.create();

        callWithToken.callWithToken(observable, new TokenCallback() {
            @Override
            public void onReceiveToken(final String token) {
                // got token
                retrofit.create(Restapi.class).getBankAccesses(token).enqueue(new RetrofitCallback<List<BankAccess>>(observable));
            }
        });

        return observable;
    }

    @Override
    public Observable<BankAccountSyncResult> getBankingTransactions(final List<BankAccountSync> bankAccountSyncList) {

        final PublishSubject observable = PublishSubject.create();

        callWithToken.callWithToken(observable, new TokenCallback() {
{'fraction_non_alphanumeric': 0.08808190071469964, 'fraction_numerical': 0.004056403322387483, 'mean_word_length': 2.8612975391498883, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '423663', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1402, 'n_words': 271}