// Path: app/src/main/java/app/data/foundation/net/RestApi.java
// public interface RestApi {
//     String URL_BASE = "https://api.github.com";
//     String HEADER_API_VERSION = "Accept: application/vnd.github.v3+json";
// 
//     @Headers({HEADER_API_VERSION})
//     @GET("/users/{username}") Observable<Response<User>> getUserByName(@Path("username") String username);
// 
//     @Headers({HEADER_API_VERSION})
//     @GET("/users") Observable<Response<List<User>>> getUsers(@Query("since") int lastIdQueried, @Query("per_page") int perPage);
// }
// 
// Path: app/src/main/java/app/domain/user_demo/User.java
// @Data
// public class User {
//     private final int id;
//     private String login;
//     private String avatar_url = "";
// 
//     public String getAvatarUrl() {
//         if (avatar_url.isEmpty()) return avatar_url;
//         return avatar_url.split("\\?")[0];
//     }
// }


import rx.Observable;
import rx.exceptions.Exceptions;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import app.data.foundation.net.RestApi;
import app.domain.user_demo.User;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okio.Buffer;
import retrofit2.Response;
import retrofit2.adapter.rxjava.HttpException;
import retrofit2.http.Path;
import retrofit2.http.Query;
        });
    }

    private final static int SECONDS_DELAY = 2;

    private <T> Observable<Response<T>> responseSuccess(T object) {
        return Observable.just(Response.success(object)).delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private <T> Observable<Response<T>> responseError() {
        Response<T> response = Response.error(404, ResponseBody.create(MediaType.parse("application/json"), "responseError"));
        return Observable.just(response).delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private <T> Observable<T> success(T object) {
        return Observable.just(object).delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private <T> Observable<T> error() {
        Response<T> response = Response.error(404, ResponseBody.create(MediaType.parse("application/json"), "responseError"));
        return Observable.<T>create(subscriber -> subscriber.onError(new HttpException(response)))
                .delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private String bodyToString(final RequestBody request) {
        try {
            final RequestBody copy = request;
            final Buffer buffer = new Buffer();
            if (copy != null) copy.writeTo(buffer);
            else return "";
// Path: app/src/main/java/app/data/foundation/net/RestApi.java
// public interface RestApi {
//     String URL_BASE = "https://api.github.com";
//     String HEADER_API_VERSION = "Accept: application/vnd.github.v3+json";
// 
//     @Headers({HEADER_API_VERSION})
//     @GET("/users/{username}") Observable<Response<User>> getUserByName(@Path("username") String username);
// 
//     @Headers({HEADER_API_VERSION})
//     @GET("/users") Observable<Response<List<User>>> getUsers(@Query("since") int lastIdQueried, @Query("per_page") int perPage);
// }
// 
// Path: app/src/main/java/app/domain/user_demo/User.java
// @Data
// public class User {
//     private final int id;
//     private String login;
//     private String avatar_url = "";
// 
//     public String getAvatarUrl() {
//         if (avatar_url.isEmpty()) return avatar_url;
//         return avatar_url.split("\\?")[0];
//     }
// }


// Path: app/src/main/java/app/data/foundation/net/mock/RestApiMock.java
import rx.Observable;
import rx.exceptions.Exceptions;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import app.data.foundation.net.RestApi;
import app.domain.user_demo.User;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okio.Buffer;
import retrofit2.Response;
import retrofit2.adapter.rxjava.HttpException;
import retrofit2.http.Path;
import retrofit2.http.Query;

        });
    }

    private final static int SECONDS_DELAY = 2;

    private <T> Observable<Response<T>> responseSuccess(T object) {
        return Observable.just(Response.success(object)).delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private <T> Observable<Response<T>> responseError() {
        Response<T> response = Response.error(404, ResponseBody.create(MediaType.parse("application/json"), "responseError"));
        return Observable.just(response).delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private <T> Observable<T> success(T object) {
        return Observable.just(object).delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private <T> Observable<T> error() {
        Response<T> response = Response.error(404, ResponseBody.create(MediaType.parse("application/json"), "responseError"));
        return Observable.<T>create(subscriber -> subscriber.onError(new HttpException(response)))
                .delay(SECONDS_DELAY, TimeUnit.SECONDS);
    }

    private String bodyToString(final RequestBody request) {
        try {
            final RequestBody copy = request;
            final Buffer buffer = new Buffer();
            if (copy != null) copy.writeTo(buffer);
            else return "";
            return buffer.readUtf8();