Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ dependencies {
// Retrofit
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofit_version"
implementation "com.squareup.moshi:moshi:1.11.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the usual dependency version specification style that has been used for others

implementation "com.squareup.retrofit2:converter-moshi:2.4.0"
implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttp_version"

// RxAndroid
Expand Down
15 changes: 2 additions & 13 deletions app/src/main/java/com/tip/lunchbox/data/server/ApiManager.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.tip.lunchbox.data.server;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.moshi.MoshiConverterFactory;

public class ApiManager {

Expand All @@ -22,7 +18,7 @@ private static Retrofit getRetrofitClient() {
.baseUrl(BASE_URL)
.client(getOkHttpClient())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.addConverterFactory(getGson()).build();
.addConverterFactory(MoshiConverterFactory.create()).build();
}
return retrofit;
}
Expand All @@ -39,13 +35,6 @@ private static OkHttpClient getOkHttpClient() {
.build();
}

private static GsonConverterFactory getGson() {
Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
return GsonConverterFactory.create(gson);
}

public static ApiService getApiService() {
if (apiService == null) {
apiService = getRetrofitClient().create(ApiService.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tip.lunchbox.data.zomato;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
Expand Down Expand Up @@ -27,11 +29,11 @@ private static Retrofit getRetrofitClient() {
private static OkHttpClient getOkHttpClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);

return new OkHttpClient()
.newBuilder()
.addInterceptor(new ZomatoApiInterceptor())
.addInterceptor(logging)
.readTimeout(5, TimeUnit.SECONDS)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epicadk we are not expecting a huge load on the server so I believe we can keep lower socket time out values. But still, I believe the connection time out value can be set as low as 5 seconds but the socket timeout can be dragged a little higher like 10 seconds.

What was your reasoning behind setting this as 5 seconds?

.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class Comment {
@Expose
private int rating;
@Expose
private int zomatoResId;
private int zomato_res_id;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Camel case!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah moshi requires snake case.


public Comment(String comment, int rating, String zomatoResId) {
public Comment(String comment, int rating, String zomato_res_id) {
this.comment = comment;
this.rating = rating;
this.zomatoResId = Integer.parseInt(zomatoResId);
this.zomato_res_id = Integer.parseInt(zomato_res_id);
}

public String getComment() {
Expand All @@ -27,7 +27,7 @@ public int getRating() {


public String getZomatoResId() {
return "" + zomatoResId;
return "" + zomato_res_id;
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.tip.lunchbox.model.server.request;

import com.google.gson.annotations.Expose;

public class FavouriteRestaurants {
@Expose
private int zomatoResId;

private int zomato_res_id;

public String getZomatoResId() {
return "" + zomatoResId;
return "" + zomato_res_id;
}

public void setZomatoResId(int zomatoResId) {
this.zomatoResId = zomatoResId;
public void setZomatoResId(int zomato_res_id) {
this.zomato_res_id = zomato_res_id;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.tip.lunchbox.model.server.request;

import com.google.gson.annotations.Expose;

// Required for Moshi
@SuppressWarnings("unused")
public class Login {
@Expose
private String username;
@Expose
private String password;

public Login(String username, String password) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.tip.lunchbox.model.server.request;

import com.google.gson.annotations.Expose;

/**
* This class represents a request made to the SignUp endpoint of the api
* Username represents username of the user
* password represents password of the user
* phone represents phone number of the user.
**/
// Required for Moshi
@SuppressWarnings("unused")
public class SignUp {
@Expose
private String username;
@Expose
private String password;
@Expose
private long phone;

public SignUp(String username, String password, long phone) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.tip.lunchbox.model.server.response;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.squareup.moshi.Json;

// Required for Moshi
@SuppressWarnings("unused")
public class CommentsResponse {
@SerializedName("_id")
@Expose
@Json(name = "_id")
private String id;
@Expose
private Integer rating;
@Expose
private String comment;
@Expose
private int zomatoResId;
@SerializedName("user_name")
private int zomato_res_id;
@Json(name = "user_name")
private String author;

public String getId() {
Expand All @@ -29,7 +26,7 @@ public String getComment() {
}

public int getZomatoResId() {
return zomatoResId;
return zomato_res_id;
}

public String getAuthor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.util.List;

// Required for Moshi
@SuppressWarnings("unused")
public class CommentsResponseContainer {
List<CommentsResponse> comments;
private List<CommentsResponse> comments;

public List<CommentsResponse> getComments() {
return comments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.tip.lunchbox.model.server.response;

import com.google.gson.annotations.Expose;

// Required for Moshi
@SuppressWarnings("unused")
public class FavouriteRestaurantsResponse {
@Expose
private Integer[] result;

public Integer[] getResult() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.tip.lunchbox.model.server.response;

// Required for Moshi
@SuppressWarnings("unused")
public class RefreshResponse {
String authToken;
String auth_token;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also


public String getAuthToken() {
return authToken;
return auth_token;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.tip.lunchbox.model.server.response;

import com.google.gson.annotations.Expose;

// Required for Moshi
@SuppressWarnings("unused")
//Response for both signup and login endpoints
public class Tokens {
@Expose
private String authToken;
@Expose
private String refreshToken;
private String auth_token;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not following the camel case style of writing and because of this build tests are failing. Please fix this

private String refresh_token;

public String getAuthToken() {
return authToken;
return auth_token;
}

public String getRefreshToken() {
return refreshToken;
return refresh_token;
}
}