package com.rest.client.rest;

import java.io.IOException;

import android.util.Log;

import retrofit.Call;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;


/**
 * Architecture for working with Retrofit.
 *
 * @author Xinyue Zhao
 */
public class RestApiManager {
	/**
	 * The id of manger.
	 */
	private long mId;


	/**
	 * Initialize the manager.
	 */

	public void onCreate() {
		setId( java.lang.System.currentTimeMillis() );
	}

	/**
	 * Set the id of manger.
	 */
	private void setId( long id ) {
		mId = id;
	}

	/**
	 * Run a rest request async.
	 *
	 * @param call
	 * 		The {@link Call} to the request.
	 * @param requestObject
	 * 		The request data to post on server.
	 */
	public <LD extends RestObject, SD extends RestObject> void execAsync( Call<SD> call, LD requestObject ) {
		//MAKE A LOCAL STATUS.
		requestObject.updateDB( RestObject.NOT_SYNCED );
		//CALL API.
		call.enqueue( new Callback<SD>() {
			@Override
			public void onResponse( Response<SD> response, Retrofit retrofit ) {
				if( response.isSuccess() ) {
					//-------------------------
					//THE REQUEST IS SUCCESS.
					//-------------------------
					RestObject serverData = response.body();
					//UPDATE LOCAL STATUS.
					serverData.updateDB( RestObject.SYNCED );
				}
			}

			@Override
			public void onFailure( Throwable t ) {
				Log.d(
						getClass().getSimpleName(),
						"onFailure: " + t.toString()

				);
			}
		} );
	}


	/**
	 * Run a rest request sync.
	 *
	 * @param call
	 * 		The {@link Call} to the request.
	 * @param requestObject
	 * 		The request data to post on server.
	 */
	public <LD extends RestObject, SD extends RestObject> void execSync( Call<SD> call, LD requestObject ) {
		//MAKE A LOCAL STATUS.
		requestObject.updateDB( RestObject.NOT_SYNCED );
		try {
			//CALL API.
			Response<SD> response = call.execute();
			//-------------------------
			//THE REQUEST IS SUCCESS.
			//-------------------------
			RestObject serverData = response.body();
			//UPDATE LOCAL STATUS.
			serverData.updateDB( RestObject.SYNCED );
		} catch( IOException e ) {
			Log.e(
					"RestApiManager",
					"execSync: " + e.getMessage()

			);
		}
	}

	public void executePending( ExecutePending exp ) {
		RestUtils.executePending( exp );
	}
}

@@ -1861,24 +1861,57 @@
 .execute();%0A
+%09%09%09if( response.isSuccess() ) %7B%0A%09
 %09%09%09//-------
@@ -1932,16 +1932,17 @@
 ----%0A%09%09%09
+%09
 //THE RE
@@ -1959,16 +1959,17 @@
 UCCESS.%0A
+%09
 %09%09%09//---
@@ -1991,16 +1991,17 @@
 -------%0A
+%09
 %09%09%09RestO
@@ -2039,16 +2039,17 @@
 y();%0A%09%09%09
+%09
 //UPDATE
@@ -2063,16 +2063,17 @@
 STATUS.%0A
+%09
 %09%09%09serve
@@ -2109,16 +2109,21 @@
 NCED );%0A
+%09%09%09%7D%0A
 %09%09%7D catc

Test isSuccess for execSync