diff --git a/.idea/misc.xml b/.idea/misc.xml index 4bc4fc6..c3df9b0 100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/java/com/baato/osmnavigationapp/MainActivity.java b/app/src/main/java/com/baato/osmnavigationapp/MainActivity.java index 9e569f8..bf4d251 100755 --- a/app/src/main/java/com/baato/osmnavigationapp/MainActivity.java +++ b/app/src/main/java/com/baato/osmnavigationapp/MainActivity.java @@ -1,6 +1,7 @@ package com.baato.osmnavigationapp; import android.os.Bundle; +import android.os.Handler; import android.util.Log; import androidx.appcompat.app.AppCompatActivity; @@ -16,21 +17,31 @@ import com.baato.baatolibrary.services.BaatoRouting; import com.baato.baatolibrary.services.BaatoReverse; import com.baato.baatolibrary.services.BaatoSearch; +import com.baato.baatolibrary.utilities.BaatoNavMode; import com.baato.baatolibrary.utilities.BaatoUtil; import com.kathmandulivinglabs.osmnavigationapp.R; +import java.util.UUID; + public class MainActivity extends AppCompatActivity { - private static final String TAG = "apple"; + private static final String TAG = "Baato-JAVA-CLIENT"; + private String sessionId; + private String bundleIdentifier; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + sessionId = UUID.randomUUID().toString(); + bundleIdentifier = MainActivity.this.getPackageName(); + performRouting(); performReverseGeoCoding(); performSearch(); getPlaces(); + } private void performRouting() { @@ -38,7 +49,9 @@ private void performRouting() { new BaatoRouting(this) .setPoints(points) .setAccessToken(Constants.TOKEN) - .setMode("foot") + .setSessionId(sessionId) + .setBundleIdentifier(bundleIdentifier) + .setMode(BaatoNavMode.BIKE) .setAlternatives(false) .setInstructions(false) .withListener(new BaatoRouting.BaatoRoutingRequestListener() { @@ -62,6 +75,8 @@ private void performReverseGeoCoding() { .setLatLon(new LatLon(27.73405, 85.33685)) .setAPIVersion("1") .setAccessToken(Constants.TOKEN) + .setSessionId(sessionId) + .setBundleIdentifier(bundleIdentifier) .setLimit(5) .withListener(new BaatoReverse.BaatoReverseRequestListener() { @Override @@ -83,6 +98,8 @@ private void getPlaces() { new BaatoPlace(this) .setAccessToken(Constants.TOKEN) .setPlaceId(101499) + .setSessionId(sessionId) + .setBundleIdentifier(bundleIdentifier) .withListener(new BaatoPlace.BaatoPlaceListener() { @Override public void onSuccess(PlaceAPIResponse place) { @@ -104,6 +121,8 @@ private void performSearch() { .setAccessToken(Constants.TOKEN) .setAPIVersion("1") .setQuery("Kathmandu") + .setSessionId(sessionId) + .setBundleIdentifier(bundleIdentifier) .setLimit(5) .withListener(new BaatoSearch.BaatoSearchRequestListener() { @Override diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/application/BaatoLib.java b/baatolibrary/src/main/java/com/baato/baatolibrary/application/BaatoLib.java index 1784958..bbbe3e0 100755 --- a/baatolibrary/src/main/java/com/baato/baatolibrary/application/BaatoLib.java +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/application/BaatoLib.java @@ -5,6 +5,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; +import com.baato.baatolibrary.utilities.LoggingInterceptor; import com.baato.baatolibrary.utilities.RetryInterceptor; import java.util.concurrent.TimeUnit; @@ -38,6 +39,7 @@ public static Retrofit retrofitV2(String apiVersion, String apiBaseURL) { .readTimeout(15, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .addInterceptor(new RetryInterceptor(4)) +// .addInterceptor(new LoggingInterceptor()) .build(); Retrofit.Builder builder = new Retrofit.Builder() .baseUrl(apiBaseURL+ "v" + apiVersion + "/") diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/requests/BaatoAPI.java b/baatolibrary/src/main/java/com/baato/baatolibrary/requests/BaatoAPI.java index dbab4ff..8679c3c 100755 --- a/baatolibrary/src/main/java/com/baato/baatolibrary/requests/BaatoAPI.java +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/requests/BaatoAPI.java @@ -8,20 +8,35 @@ import retrofit2.Call; import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.HeaderMap; +import retrofit2.http.Headers; import retrofit2.http.Query; import retrofit2.http.QueryMap; public interface BaatoAPI { @GET("directions") - Call getDirections(@QueryMap Map filters, @Query("points[]") String[] points); + Call getDirections( + @Header("SessionId") String sessionId, + @Header("BundleIdentifier") String bundleIdentifier, + @QueryMap Map filters, @Query("points[]") String[] points); @GET("search") - Call searchQuery(@QueryMap Map filters); + Call searchQuery( + @Header("SessionId") String sessionId, + @Header("BundleIdentifier") String bundleIdentifier, + @QueryMap Map filters); @GET("reverse") - Call performReverseGeoCode(@QueryMap Map filter); + Call performReverseGeoCode( + @Header("SessionId") String sessionId, + @Header("BundleIdentifier") String bundleIdentifier, + @QueryMap Map filter); @GET("places") - Call performPlacesQuery(@QueryMap Map filter); + Call performPlacesQuery( + @Header("SessionId") String sessionId, + @Header("BundleIdentifier") String bundleIdentifier, + @QueryMap Map filter); } diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoPlace.java b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoPlace.java index 77ecef4..a791fc3 100755 --- a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoPlace.java +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoPlace.java @@ -26,7 +26,7 @@ public class BaatoPlace { private Context context; - private String accessToken, securityCode; + private String accessToken, securityCode,bundleIdentifier,sessionId; private String apiVersion = "1"; private String apiBaseUrl = "https://api.baato.io/api/"; private BaatoPlaceListener baatoPlaceListener; @@ -86,7 +86,20 @@ public BaatoPlace setSecurityCode(String securityCode) { this.securityCode = securityCode; return this; } - + /** + * Set the package name. + */ + public BaatoPlace setBundleIdentifier(String bundleIdentifier) { + this.bundleIdentifier = bundleIdentifier; + return this; + } + /** + * Set the session Id. + */ + public BaatoPlace setSessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } /** * Method to set the UpdateListener for the AppUpdaterUtils actions * @@ -100,7 +113,7 @@ public BaatoPlace withListener(BaatoPlaceListener baatoPlaceListener) { public void doRequest() { BaatoAPI baatoAPI = BaatoLib.retrofitV2(apiVersion, apiBaseUrl).create(BaatoAPI.class); - placeAPIResponseCall = baatoAPI.performPlacesQuery(giveMeQueryFilter(context)); + placeAPIResponseCall = baatoAPI.performPlacesQuery(sessionId,bundleIdentifier,giveMeQueryFilter(context)); placeAPIResponseCall.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoReverse.java b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoReverse.java index 1957102..3fc40e8 100755 --- a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoReverse.java +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoReverse.java @@ -27,7 +27,7 @@ public class BaatoReverse { private static final String TAG = "BaatoReverseGeoCode"; private Context context; private BaatoReverseRequestListener baatoReverseRequestListener; - private String accessToken, securityCode; + private String accessToken, securityCode,bundleIdentifier,sessionId; private String apiVersion = "1"; private String apiBaseUrl = "https://api.baato.io/api/"; private int radius, limit = 0; @@ -104,6 +104,20 @@ public BaatoReverse setSecurityCode(String securityCode) { this.securityCode = securityCode; return this; } + /** + * Set the package name. + */ + public BaatoReverse setBundleIdentifier(String bundleIdentifier) { + this.bundleIdentifier = bundleIdentifier; + return this; + } + /** + * Set the session Id. + */ + public BaatoReverse setSessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } /** * Method to set the UpdateListener for the AppUpdaterUtils actions @@ -118,7 +132,7 @@ public BaatoReverse withListener(BaatoReverseRequestListener baatoReverseRequest public void doRequest() { BaatoAPI baatoAPI = BaatoLib.retrofitV2(apiVersion, apiBaseUrl).create(BaatoAPI.class); - placeAPIResponseCall = baatoAPI.performReverseGeoCode(giveMeQueryFilter(context)); + placeAPIResponseCall = baatoAPI.performReverseGeoCode(sessionId,bundleIdentifier,giveMeQueryFilter(context)); placeAPIResponseCall.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoRouting.java b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoRouting.java index c1db47e..ac51fd9 100755 --- a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoRouting.java +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoRouting.java @@ -11,6 +11,7 @@ import com.baato.baatolibrary.models.NavResponse; import com.baato.baatolibrary.navigation.NavigateResponseConverter; import com.baato.baatolibrary.requests.BaatoAPI; +import com.baato.baatolibrary.utilities.BaatoNavMode; import com.baato.baatolibrary.utilities.BaatoUtil; import com.baato.baatolibrary.utilities.ErrorUtils; @@ -26,7 +27,8 @@ public class BaatoRouting { private Context context; private BaatoRoutingRequestListener baatoRoutingRequestListener; - private String accessToken, securityCode, mode; + private String accessToken, securityCode,bundleIdentifier,sessionId,mode; +// private BaatoNavMode mode; private String apiVersion = "1"; private String apiBaseUrl = "https://api.baato.io/api/"; private String[] points; @@ -35,7 +37,6 @@ public class BaatoRouting { private Call directionsAPIResponseCall; private Locale locale; - public interface BaatoRoutingRequestListener { /** * onSuccess method called after it is successful @@ -57,6 +58,20 @@ public BaatoRouting setAccessToken(@NonNull String accessToken) { this.accessToken = accessToken; return this; } + /** + * Set the package name. + */ + public BaatoRouting setBundleIdentifier(String bundleIdentifier) { + this.bundleIdentifier = bundleIdentifier; + return this; + } + /** + * Set the session Id. + */ + public BaatoRouting setSessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } /** * Set the apiVersion. By default it takes version "1" @@ -88,8 +103,8 @@ public BaatoRouting setAPIBaseURL(@NonNull String apiBaseURL) { /** * Set the mode. */ - public BaatoRouting setMode(@NonNull String mode) { - this.mode = mode; + public BaatoRouting setMode(@NonNull BaatoNavMode mode) { + this.mode = mode.toString().toLowerCase(); return this; } @@ -139,7 +154,7 @@ public BaatoRouting withListener(BaatoRoutingRequestListener baatoRoutingRequest public void doRequest() { BaatoAPI baatoAPI = BaatoLib.retrofitV2(apiVersion, apiBaseUrl).create(BaatoAPI.class); - directionsAPIResponseCall = baatoAPI.getDirections(giveMeQueryFilter(context), points); + directionsAPIResponseCall = baatoAPI.getDirections(sessionId,bundleIdentifier,giveMeQueryFilter(context), points); directionsAPIResponseCall .enqueue(new Callback() { @Override diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoSearch.java b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoSearch.java index e509ed1..ea8d12d 100755 --- a/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoSearch.java +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoSearch.java @@ -23,7 +23,7 @@ public class BaatoSearch { private Context context; private BaatoSearchRequestListener baatoSearchRequestListener; - private String accessToken, query; + private String accessToken, query,bundleIdentifier,sessionId; private String type, securityCode; private String apiVersion = "1"; private String apiBaseUrl = "https://api.baato.io/api/"; @@ -52,6 +52,20 @@ public BaatoSearch setAccessToken(@NonNull String accessToken) { this.accessToken = accessToken; return this; } + /** + * Set the package name. + */ + public BaatoSearch setBundleIdentifier(String bundleIdentifier) { + this.bundleIdentifier = bundleIdentifier; + return this; + } + /** + * Set the session Id. + */ + public BaatoSearch setSessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } /** * Set the securityCode is security enabled. @@ -133,7 +147,7 @@ public BaatoSearch withListener(BaatoSearchRequestListener baatoSearchRequestLis public void doRequest() { BaatoAPI baatoAPI = BaatoLib.retrofitV2(apiVersion, apiBaseUrl).create(BaatoAPI.class); - searchAPIResponseCall = baatoAPI.searchQuery(giveMeQueryFilter(context)); + searchAPIResponseCall = baatoAPI.searchQuery(sessionId,bundleIdentifier,giveMeQueryFilter(context)); searchAPIResponseCall.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/utilities/BaatoNavMode.java b/baatolibrary/src/main/java/com/baato/baatolibrary/utilities/BaatoNavMode.java new file mode 100644 index 0000000..678c3c5 --- /dev/null +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/utilities/BaatoNavMode.java @@ -0,0 +1,5 @@ +package com.baato.baatolibrary.utilities; + +public enum BaatoNavMode { + CAR,BIKE,FOOT +} diff --git a/baatolibrary/src/main/java/com/baato/baatolibrary/utilities/LoggingInterceptor.java b/baatolibrary/src/main/java/com/baato/baatolibrary/utilities/LoggingInterceptor.java new file mode 100644 index 0000000..44eb230 --- /dev/null +++ b/baatolibrary/src/main/java/com/baato/baatolibrary/utilities/LoggingInterceptor.java @@ -0,0 +1,51 @@ +package com.baato.baatolibrary.utilities; + +import java.io.IOException; + +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; +import okio.Buffer; +import okio.BufferedSource; + +import java.io.IOException; + +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; +import okio.Buffer; +import okio.BufferedSource; + +public class LoggingInterceptor implements Interceptor { + + @Override + public Response intercept(Chain chain) throws IOException { + Request originalRequest = chain.request(); + + // Log request headers + System.out.println("Request Headers: " + originalRequest.headers().get("SessionId")); + System.out.println("Request Headers: " + originalRequest.headers().get("BundleIdentifier")); + + // Log request body if present + if (originalRequest.body() != null) { + Buffer buffer = new Buffer(); + originalRequest.body().writeTo(buffer); + System.out.println("Request Body: " + buffer.readUtf8()); + } + + Response response = chain.proceed(originalRequest); + + // Log response body if present + ResponseBody responseBody = response.body(); + if (responseBody != null) { + BufferedSource source = responseBody.source(); + source.request(Long.MAX_VALUE); // Buffer the entire body. + Buffer buffer = source.buffer(); + System.out.println("Response Body: " + buffer.clone().readUtf8()); + } + + return response; + } +}