Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Backend<T> {
private int code;
private List<T> data;
private String msg;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public List<T> getData() {
return data;
}
public void setData(List<T> data) {
this.data = data;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
public class HttpClient {
private static HttpService httpService = new Retrofit.Builder()
.baseUrl("http://192.168.1.24:8088/api/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(HttpService.class);
public static List<Company> getCompanies() {
try {
return httpService.getCompanies().execute().body().getData();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static List<Schedule> getSchedules() {
try {
return httpService.getSchedules().execute().body().getData();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
public interface HttpService {
@GET("companies")
Call<Backend<Company>> getCompanies();
@GET("schedules")
Call<Backend<Schedule>> getSchedules();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment