Last active
July 26, 2016 06:51
-
-
Save yuyang041060120/6e8cc86d8cab94d2b3534f13ee499a99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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