Skip to content

Commit

Permalink
gank所有接口回调采用新版本回调
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Sep 30, 2020
1 parent 41c3d7d commit aa5e7ec
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 243 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/com/maning/gankmm/bean/gank/GankBaseBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.maning.gankmm.bean.gank;

/**
* @author : maning
* @date : 2020-09-29
* @desc : 第一版本的Gank
*/
public class GankBaseBean {

private boolean error;

public boolean isError() {
return error;
}

public void setError(boolean error) {
this.error = error;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.maning.gankmm.bean;
package com.maning.gankmm.bean.gank;

import com.maning.gankmm.bean.GankEntity;
import com.maning.gankmm.bean.gank.GankBaseBean;

import java.io.Serializable;
import java.util.List;
Expand All @@ -7,28 +10,12 @@
* Created by maning on 16/6/2.
* 获取每日数据的接口
*/
public class DayEntity implements Serializable {
public class GankDayBean extends GankBaseBean implements Serializable {
private static final long serialVersionUID = 1437313256335061579L;


/**
* category : ["iOS","拓展资源","Android","休息视频","福利"]
* error : false
* results : {"Android":[{"_id":"56cc6d23421aa95caa707bba","createdAt":"2015-08-06T02:05:32.826Z","desc":"一个查看设备规格的库,并且可以计算哪一年被定为\u201c高端\u201d机","publishedAt":"2015-08-06T04:16:55.575Z","type":"Android","url":"https://github.com/facebook/device-year-class","used":true,"who":"有时放纵"},{"_id":"56cc6d23421aa95caa707c67","createdAt":"2015-08-05T16:36:19.591Z","desc":"一个好玩的自定义字体库","publishedAt":"2015-08-06T04:16:55.805Z","type":"Android","url":"https://github.com/vsvankhede/easyfonts","used":true,"who":"有时放纵"},{"_id":"56cc6d23421aa95caa707c6a","createdAt":"2015-08-06T02:07:23.290Z","desc":"一个小清新spinner","publishedAt":"2015-08-06T04:16:55.582Z","type":"Android","url":"https://github.com/arcadefire/nice-spinner","used":true,"who":"有时放纵"}],"iOS":[{"_id":"56cc6d1d421aa95caa70777e","createdAt":"2015-08-06T01:55:36.30Z","desc":"iOS 核心动画高级技巧","publishedAt":"2015-08-06T04:16:55.592Z","type":"iOS","url":"http://zsisme.gitbooks.io/ios-/content/","used":true,"who":"Andrew Liu"},{"_id":"56cc6d23421aa95caa707a65","createdAt":"2015-08-05T03:45:12.537Z","desc":"设定label,text等视图的属性,你喜欢这种方式么?","publishedAt":"2015-08-06T04:16:55.584Z","type":"iOS","url":"http://natashatherobot.com/ios-a-beautiful-way-of-styling-iboutlets-in-swift/?utm_campaign=This%2BWeek%2Bin%2BSwift&utm_medium=web&utm_source=This_Week_in_Swift_47","used":true,"who":"Huan"},{"_id":"56cc6d23421aa95caa707c62","createdAt":"2015-08-06T01:56:32.207Z","desc":"iOS开发之block终极篇","publishedAt":"2015-08-06T04:16:55.589Z","type":"iOS","url":"http://www.90159.com/2015/08/05/ios-block-ultimate/","used":true,"who":"Andrew Liu"},{"_id":"56cc6d23421aa95caa707c70","createdAt":"2015-08-05T12:17:08.481Z","desc":"Status Board 2 - Panic 公司推出的 iOS App,可以生成可视化数据图表,用以监测项目效率、Bug量,团队动态、销售情况等多种数据(稀土圈)","publishedAt":"2015-08-06T04:16:55.601Z","type":"iOS","url":"https://www.panic.com/statusboard/","used":true,"who":"LHF"}],"休息视频":[{"_id":"56cc6d23421aa95caa707c2b","createdAt":"2015-08-06T03:55:07.175Z","desc":"重温字幕版倒鸭子~~~","publishedAt":"2015-08-06T04:16:55.578Z","type":"休息视频","url":"http://video.weibo.com/show?fid=1034:0c79a69b1bafe17df62e750391d92118","used":true,"who":"代码家"}],"拓展资源":[{"_id":"56cc6d1d421aa95caa707781","createdAt":"2015-08-06T00:53:43.851Z","desc":"node express 源码接卸","publishedAt":"2015-08-06T04:16:55.601Z","type":"拓展资源","url":"https://gist.github.com/dlutwuwei/3faf88d535ac81c4e263","used":true,"who":"YJX"},{"_id":"56cc6d23421aa95caa707a66","createdAt":"2015-08-06T00:49:19.237Z","desc":"MongoDB从入门到精通系列","publishedAt":"2015-08-06T04:16:55.579Z","type":"拓展资源","url":"http://codefrom.com/t/mongodb%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E7%B2%BE%E9%80%9A%E7%B3%BB%E5%88%97%E4%B8%93%E9%A2%98","used":true,"who":"YJX"}],"福利":[{"_id":"56cc6d23421aa95caa707c6f","createdAt":"2015-08-06T01:33:55.463Z","desc":"8.6","publishedAt":"2015-08-06T04:16:55.601Z","type":"福利","url":"http://ww4.sinaimg.cn/large/7a8aed7bgw1eusn3niy2bj20hs0qo0wb.jpg","used":true,"who":"张涵宇"}]}
*/

private boolean error;
private ResultsEntity results;
private List<String> category;

public boolean isError() {
return error;
}

public void setError(boolean error) {
this.error = error;
}

public ResultsEntity getResults() {
return results;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.maning.gankmm.bean.gank;

import java.util.List;

/**
* @author : maning
* @date : 2020-09-30
* @desc :
*/
public class GankHistoryListBean extends GankBaseBean{

/**
* error : false
* results : ["2019-04-10","2019-01-21","2019-01-03","2018-12-28","2018-12-13","2018-11-28","2018-11-19","2018-11-06","2018-10-22","2018-10-15","2018-10-08","2018-09-19","2018-09-11","2018-08-28","2018-08-21","2018-08-16","2018-08-13","2018-08-09","2018-08-06","2018-08-03","2018-08-01","2018-07-31","2018-07-30","2018-07-19","2018-07-18","2018-07-13","2018-07-11","2018-07-10","2018-07-09","2018-07-06","2018-07-05","2018-07-03","2018-07-02","2018-06-28","2018-06-27","2018-06-26","2018-06-25","2018-06-22","2018-06-21","2018-06-20","2018-06-19","2018-06-15","2018-06-14","2018-06-13","2018-06-12","2018-06-11","2018-06-08","2018-06-07","2018-06-06","2018-06-05","2018-06-04","2018-06-01","2018-05-31","2018-05-30","2018-05-29","2018-05-28","2018-05-25","2018-05-24","2018-05-23","2018-05-22","2018-05-21","2018-05-19","2018-05-18","2018-05-17","2018-05-16","2018-05-15","2018-05-14","2018-05-13","2018-05-12","2018-05-11","2018-05-10","2018-05-09","2018-05-08","2018-05-06","2018-05-05","2018-05-04","2018-03-12","2018-02-22","2018-02-08","2018-01-29","2018-01-23","2018-01-16","2018-01-10","2018-01-04","2018-01-02","2017-12-27","2017-12-25","2017-12-19","2017-12-15","2017-12-11","2017-12-06","2017-12-05","2017-11-30","2017-11-24","2017-11-20","2017-11-17","2017-11-16","2017-11-14","2017-11-13","2017-11-10","2017-11-08","2017-11-06","2017-11-01","2017-10-31","2017-10-27","2017-10-25","2017-10-24","2017-10-23","2017-10-20","2017-10-17","2017-10-16","2017-10-11","2017-10-10","2017-10-09","2017-09-29","2017-09-26","2017-09-21","2017-09-20","2017-09-19","2017-09-14","2017-09-12","2017-09-07","2017-09-06","2017-09-05","2017-09-01","2017-08-31","2017-08-29","2017-08-24","2017-08-23","2017-08-22","2017-08-21","2017-08-17","2017-08-15","2017-08-14","2017-08-11","2017-08-09","2017-08-08","2017-08-03","2017-08-02","2017-08-01","2017-07-27","2017-07-26","2017-07-25","2017-07-24","2017-07-21","2017-07-20","2017-07-19","2017-07-18","2017-07-17","2017-07-14","2017-07-13","2017-07-12","2017-07-11","2017-07-10","2017-07-07","2017-07-06","2017-07-05","2017-07-04","2017-06-15","2017-06-14","2017-06-12","2017-06-09","2017-06-08","2017-06-07","2017-06-06","2017-06-05","2017-06-03","2017-06-02","2017-06-01","2017-05-26","2017-05-25","2017-05-24","2017-05-23","2017-05-22","2017-05-16","2017-05-15","2017-05-12","2017-05-11","2017-05-10","2017-05-09","2017-05-08","2017-05-05","2017-05-04","2017-05-03","2017-05-02","2017-04-28","2017-04-27","2017-04-26","2017-04-25","2017-04-24","2017-04-21","2017-04-20","2017-04-19","2017-04-18","2017-04-17","2017-04-14","2017-04-13","2017-04-12","2017-04-11","2017-04-10","2017-04-07","2017-04-06","2017-04-05","2017-03-31","2017-03-30","2017-03-29","2017-03-28","2017-03-27","2017-03-24","2017-03-23","2017-03-22","2017-03-21","2017-03-20","2017-03-17","2017-03-16","2017-03-15","2017-03-14","2017-03-13","2017-03-10","2017-03-09","2017-03-08","2017-03-07","2017-03-06","2017-03-03","2017-03-02","2017-03-01","2017-02-28","2017-02-27","2017-02-24","2017-02-23","2017-02-22","2017-02-21","2017-02-20","2017-02-17","2017-02-16","2017-02-15","2017-02-14","2017-02-13","2017-02-10","2017-02-09","2017-02-08","2017-02-07","2017-02-06","2017-02-04","2017-02-03","2017-01-23","2017-01-22","2017-01-20","2017-01-19","2017-01-16","2017-01-13","2017-01-12","2017-01-11","2017-01-10","2017-01-09","2017-01-06","2017-01-05","2017-01-04","2017-01-03","2016-12-30","2016-12-29","2016-12-28","2016-12-27","2016-12-26","2016-12-23","2016-12-22","2016-12-21","2016-12-20","2016-12-19","2016-12-16","2016-12-15","2016-12-14","2016-12-13","2016-12-12","2016-12-09","2016-12-08","2016-12-07","2016-12-06","2016-12-05","2016-12-02","2016-12-01","2016-11-30","2016-11-29","2016-11-28","2016-11-25","2016-11-24","2016-11-23","2016-11-22","2016-11-21","2016-11-18","2016-11-17","2016-11-16","2016-11-15","2016-11-14","2016-11-11","2016-11-10","2016-11-09","2016-11-08","2016-11-07","2016-11-04","2016-11-03","2016-11-02","2016-11-01","2016-10-31","2016-10-28","2016-10-27","2016-10-26","2016-10-25","2016-10-24","2016-10-21","2016-10-20","2016-10-19","2016-10-18","2016-10-17","2016-10-14","2016-10-13","2016-10-12","2016-10-11","2016-10-10","2016-10-09","2016-10-08","2016-09-30","2016-09-29","2016-09-28","2016-09-27","2016-09-26","2016-09-23","2016-09-22","2016-09-21","2016-09-20","2016-09-19","2016-09-18","2016-09-14","2016-09-13","2016-09-12","2016-09-09","2016-09-08","2016-09-07","2016-09-06","2016-09-05","2016-09-02","2016-09-01","2016-08-31","2016-08-30","2016-08-29","2016-08-26","2016-08-25","2016-08-24","2016-08-23","2016-08-22","2016-08-19","2016-08-18","2016-08-17","2016-08-16","2016-08-15","2016-08-12","2016-08-11","2016-08-10","2016-08-09","2016-08-08","2016-08-05","2016-08-03","2016-08-02","2016-08-01","2016-07-29","2016-07-28","2016-07-27","2016-07-26","2016-07-25","2016-07-22","2016-07-21","2016-07-20","2016-07-19","2016-07-18","2016-07-15","2016-07-14","2016-07-13","2016-07-12","2016-07-11","2016-07-08","2016-07-07","2016-07-06","2016-07-05","2016-07-04","2016-07-01","2016-06-30","2016-06-29","2016-06-28","2016-06-27","2016-06-24","2016-06-23","2016-06-22","2016-06-21","2016-06-20","2016-06-17","2016-06-16","2016-06-15","2016-06-14","2016-06-13","2016-06-12","2016-06-08","2016-06-07","2016-06-06","2016-06-03","2016-06-02","2016-06-01","2016-05-31","2016-05-30","2016-05-27","2016-05-26","2016-05-25","2016-05-24","2016-05-23","2016-05-20","2016-05-19","2016-05-18","2016-05-17","2016-05-16","2016-05-13","2016-05-12","2016-05-11","2016-05-10","2016-05-09","2016-05-06","2016-05-05","2016-05-04","2016-05-03","2016-04-29","2016-04-28","2016-04-27","2016-04-26","2016-04-25","2016-04-22","2016-04-21","2016-04-20","2016-04-19","2016-04-18","2016-04-15","2016-04-14","2016-04-13","2016-04-12","2016-04-11","2016-04-08","2016-04-07","2016-04-06","2016-04-05","2016-04-01","2016-03-31","2016-03-30","2016-03-29","2016-03-28","2016-03-25","2016-03-24","2016-03-23","2016-03-22","2016-03-21","2016-03-18","2016-03-17","2016-03-16","2016-03-15","2016-03-14","2016-03-11","2016-03-10","2016-03-09","2016-03-08","2016-03-07","2016-03-04","2016-03-03","2016-03-02","2016-03-01","2016-02-29","2016-02-26","2016-02-25","2016-02-24","2016-02-23","2016-02-22","2016-02-19","2016-02-18","2016-02-17","2016-02-16","2016-02-15","2016-02-04","2016-02-03","2016-02-02","2016-02-01","2016-01-29","2016-01-28","2016-01-27","2016-01-26","2016-01-25","2016-01-22","2016-01-21","2016-01-20","2016-01-19","2016-01-18","2016-01-15","2016-01-14","2016-01-13","2016-01-12","2016-01-11","2016-01-08","2016-01-07","2016-01-06","2016-01-05","2016-01-04","2015-12-31","2015-12-30","2015-12-29","2015-12-28","2015-12-25","2015-12-24","2015-12-23","2015-12-22","2015-12-21","2015-12-18","2015-12-17","2015-12-16","2015-12-15","2015-12-14","2015-12-11","2015-12-10","2015-12-09","2015-12-08","2015-12-07","2015-12-04","2015-12-03","2015-12-02","2015-12-01","2015-11-30","2015-11-27","2015-11-26","2015-11-25","2015-11-24","2015-11-23","2015-11-20","2015-11-19","2015-11-18","2015-11-17","2015-11-16","2015-11-13","2015-11-12","2015-11-11","2015-11-10","2015-11-09","2015-11-06","2015-11-05","2015-11-04","2015-11-03","2015-11-02","2015-10-30","2015-10-29","2015-10-28","2015-10-27","2015-10-26","2015-10-23","2015-10-22","2015-10-21","2015-10-20","2015-10-19","2015-10-16","2015-10-15","2015-10-14","2015-10-13","2015-10-12","2015-10-10","2015-10-09","2015-10-08","2015-09-30","2015-09-29","2015-09-28","2015-09-25","2015-09-24","2015-09-23","2015-09-22","2015-09-21","2015-09-18","2015-09-17","2015-09-16","2015-09-15","2015-09-14","2015-09-11","2015-09-10","2015-09-09","2015-09-08","2015-09-07","2015-09-06","2015-09-02","2015-09-01","2015-08-31","2015-08-28","2015-08-27","2015-08-26","2015-08-25","2015-08-24","2015-08-21","2015-08-20","2015-08-19","2015-08-18","2015-08-17","2015-08-14","2015-08-13","2015-08-12","2015-08-11","2015-08-10","2015-08-07","2015-08-06","2015-08-05","2015-08-04","2015-08-03","2015-07-31","2015-07-30","2015-07-29","2015-07-28","2015-07-27","2015-07-24","2015-07-23","2015-07-22","2015-07-21","2015-07-20","2015-07-17","2015-07-16","2015-07-15","2015-07-14","2015-07-13","2015-07-10","2015-07-09","2015-07-08","2015-07-07","2015-07-06","2015-07-03","2015-07-02","2015-07-01","2015-06-30","2015-06-29","2015-06-26","2015-06-19","2015-06-18","2015-06-17","2015-06-16","2015-06-15","2015-06-12","2015-06-11","2015-06-10","2015-06-09","2015-06-08","2015-06-05","2015-06-04","2015-06-03","2015-06-02","2015-06-01","2015-05-29","2015-05-28","2015-05-27","2015-05-26","2015-05-25","2015-05-22","2015-05-21","2015-05-20","2015-05-19","2015-05-18","2015-05-15","2015-05-14","2015-05-13","2015-05-12","2015-05-11","2015-05-08","2015-05-07","2015-05-06","2015-05-04","2015-04-30","2015-04-29","2015-04-27","2015-04-24","2015-04-23","2015-04-22","2015-04-21","2015-04-20","2015-04-17","2015-04-16","2015-04-15","2015-04-14","2015-04-13","2015-04-10","2015-04-09","2015-04-08","2015-04-07","2015-04-03","2015-04-02","2015-04-01","2015-03-31","2015-03-30","2015-03-26","2015-03-25","2015-03-24","2015-03-23","2015-03-20","2015-03-19","2015-03-18","2015-03-17","2015-03-16","2015-03-13","2015-03-12","2015-03-11"]
*/

private List<String> results;

public List<String> getResults() {
return results;
}

public void setResults(List<String> results) {
this.results = results;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.maning.gankmm.http.gank;

import com.maning.gankmm.bean.DayEntity;
import com.maning.gankmm.bean.HttpResult;
import com.maning.gankmm.bean.gank.GankDayBean;
import com.maning.gankmm.bean.gank.GankHistoryListBean;
import com.maning.gankmm.constant.Constants;

import java.util.List;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Headers;
Expand All @@ -20,14 +18,13 @@ public interface APIGankService {
//这里填写全部路径就会覆盖掉Build得BaseUrl
@Headers("Cache-Control: public, max-age=3600")
@GET(Constants.URL_HistoryDate)
Call<HttpResult<List<String>>> getGankHistoryDate();
Call<GankHistoryListBean> getGankHistoryDate();

//http://gank.io/api/day/2015/08/06 --- 每日数据
@Headers("Cache-Control: public, max-age=300")
@GET("day/{year}/{month}/{day}")
Call<DayEntity> getOneDayData(@Path("year") String year,
@Path("month") String month,
@Path("day") String day
Call<GankDayBean> getOneDayData(@Path("year") String year,
@Path("month") String month,
@Path("day") String day
);

}
96 changes: 8 additions & 88 deletions app/src/main/java/com/maning/gankmm/http/gank/GankApi.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,18 @@
package com.maning.gankmm.http.gank;

import com.maning.gankmm.R;
import com.maning.gankmm.app.MyApplication;
import com.maning.gankmm.bean.DayEntity;
import com.maning.gankmm.bean.HttpResult;
import com.maning.gankmm.bean.gank.GankDayBean;
import com.maning.gankmm.bean.gank.GankHistoryListBean;
import com.maning.gankmm.http.BuildApi;
import com.maning.gankmm.http.callback.MyCallBack;
import com.socks.library.KLog;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import com.maning.gankmm.http.callback.CommonHttpCallback;

/**
* Created by maning on 16/3/2.
* <p/>
* 所有的网络请求
* gankid 第一版本接口
*/
public class GankApi {

public final static String GET_DATA_FAIL = MyApplication.getIntstance().getString(R.string.gank_get_data_fail);
public final static String NET_FAIL = MyApplication.getIntstance().getString(R.string.gank_net_fail);


public static Call<HttpResult<List<String>>> getHistoryData(final int what, final MyCallBack myCallBack) {

Call<HttpResult<List<String>>> gankHistoryDate = BuildApi.getGankAPIService().getGankHistoryDate();

gankHistoryDate.enqueue(new Callback<HttpResult<List<String>>>() {
@Override
public void onResponse(Call<HttpResult<List<String>>> call, Response<HttpResult<List<String>>> response) {
if (response.isSuccessful()) {
HttpResult<List<String>> httpResult = response.body();
if (httpResult != null) {
if (!httpResult.isError()) {
List<String> gankEntityList = httpResult.getResults();
KLog.i("getHistoryData---success:" + gankEntityList.toString());
myCallBack.onSuccessList(what, gankEntityList);
} else {
myCallBack.onFail(what, GET_DATA_FAIL);
}
} else {
myCallBack.onFail(what, GET_DATA_FAIL);
}
} else {
myCallBack.onFail(what, GET_DATA_FAIL);
}
}

@Override
public void onFailure(Call<HttpResult<List<String>>> call, Throwable t) {
KLog.e("getHistoryData-----onFailure:" + t.toString());
//数据错误
myCallBack.onFail(what, NET_FAIL);
}
});

return gankHistoryDate;

public static void getHistoryData(CommonHttpCallback<GankHistoryListBean> httpCallback) {
BuildApi.getGankAPIService().getGankHistoryDate().enqueue(httpCallback);
}

/**
Expand All @@ -68,43 +21,10 @@ public void onFailure(Call<HttpResult<List<String>>> call, Throwable t) {
* @param year
* @param month
* @param day
* @param what
* @param myCallBack
* @return
*/
public static Call<DayEntity> getOneDayData(String year, String month, String day, final int what, final MyCallBack myCallBack) {

Call<DayEntity> oneDayData = BuildApi.getGankAPIService().getOneDayData(year, month, day);

oneDayData.enqueue(new Callback<DayEntity>() {
@Override
public void onResponse(Call<DayEntity> call, Response<DayEntity> response) {
if (response.isSuccessful()) {
DayEntity body = response.body();
if (body != null) {
if (!body.isError()) {
KLog.i("getOneDayData---success:" + body.toString());
myCallBack.onSuccess(what, body);
} else {
myCallBack.onFail(what, GET_DATA_FAIL);
}
} else {
myCallBack.onFail(what, GET_DATA_FAIL);
}
} else {
myCallBack.onFail(what, GET_DATA_FAIL);
}
}

@Override
public void onFailure(Call<DayEntity> call, Throwable t) {
KLog.e("getOneDayData-----onFailure:" + t.toString());
//数据错误
myCallBack.onFail(what, NET_FAIL);
}
});

return oneDayData;
public static void getOneDayData(String year, String month, String day, CommonHttpCallback<GankDayBean> httpCallback) {
BuildApi.getGankAPIService().getOneDayData(year, month, day).enqueue(httpCallback);
}

}
Loading

0 comments on commit aa5e7ec

Please sign in to comment.