package es.craftsmanship.toledo.katangapp.interactors;

import java.io.IOException;

import es.craftsmanship.toledo.katangapp.models.Route;
import es.craftsmanship.toledo.katangapp.services.BusStopsService;
import es.craftsmanship.toledo.katangapp.utils.AndroidBus;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

/**
 * @author Cristóbal Hermida
 */
public class RoutesInteractor implements Runnable{
    private static final String BACKEND_ENDPOINT = "https://secret-depths-4660.herokuapp.com";
    private final String route;

    public RoutesInteractor(String route) {
        this.route = route;
    }

    @Override
    public void run() {
        try {
            Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BACKEND_ENDPOINT)
                .addConverterFactory(JacksonConverterFactory.create())
                .build();

            BusStopsService service = retrofit.create(BusStopsService.class);

            Response<Route> response = null;

            response = service.getRouteId(route).execute();

            Object event = new Error(response.message());

            if (response.isSuccessful()) {
                event = response.body();
            }

            AndroidBus.getInstance().post(event);
        }
        catch (IOException e) {
            AndroidBus.getInstance().post(e);
        }
    }

}
@@ -53,37 +53,8 @@
 s;%0A%0A
-import java.io.IOException;%0A%0A
 impo
@@ -216,51 +216,32 @@
 app.
-utils.AndroidBus;%0Aimport retrofit2.
+services.Katanga
 Response
 ;%0Aim
@@ -240,95 +240,72 @@
 onse
+Wrapper
 ;%0A
+%0A
 import 
-retrofit2.Retrofit;%0Aimport retrofit2.converter.jackson.JacksonConverterFactory
+java.io.IOException;%0A%0Aimport retrofit2.Response
 ;%0A%0A/
@@ -336,16 +336,45 @@
 Hermida%0A
+ * @author Manuel de la Pe%C3%B1a%0A
  */%0Apubl
@@ -403,123 +403,40 @@
 tor 
-implements Runnable%7B%0A    private static final String BACKEND_ENDPOINT = %22https://secret-depths-4660.herokuapp.com%22;
+extends BaseKatangaInteractor %7B%0A
 %0A   
@@ -567,728 +567,267 @@
    p
-ublic void run() %7B%0A        try %7B%0A            Retrofit retrofit = new Retrofit.Builder()%0A                .baseUrl(BACKEND_ENDPOINT)%0A                .addConverterFactory(JacksonConverterFactory.create())%0A                .build();%0A%0A            BusStopsService service = retrofit.create(BusStopsService.class);%0A%0A            Response%3CRoute%3E response = null;%0A%0A            response = service.getRouteId(route).execute();%0A%0A            Object event = new Error(response.message());%0A%0A            if (response.isSuccessful()) %7B%0A                event = response.body();%0A            %7D%0A%0A            AndroidBus.getInstance().post(event);%0A        %7D%0A        catch (IOException e) %7B%0A            AndroidBus.getInstance().post(e);%0A        %7D
+rotected KatangaResponseWrapper%3CResponse%3CRoute%3E%3E getResponse(BusStopsService busStopsService)%0A        throws IOException %7B%0A%0A        Response%3CRoute%3E response = busStopsService.getRouteId(route).execute();%0A%0A        return new KatangaResponseWrapper%3C%3E(response);
 %0A   

Apply interactor pattern to RoutesInteractor