Skip to content

Instantly share code, notes, and snippets.

@yuyang041060120
Last active July 26, 2016 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyang041060120/6e8cc86d8cab94d2b3534f13ee499a99 to your computer and use it in GitHub Desktop.
Save yuyang041060120/6e8cc86d8cab94d2b3534f13ee499a99 to your computer and use it in GitHub Desktop.
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