mock-api
??
?? OkHttp ? Interceptor ? ????url??mock??????assets?sdcard?????????????????
??
???? build.gradle
????????
compile 'com.shanbay.android:mock-api:0.0.1'
?????mock?????????? /api/user/
???????
{
username: "shanbay"
}
?????????? user.json
?????assets???? mockdata/account/
???????account?suite-name???????;
?????Client????????
MockApiSuite suite = new MockApiSuite("account");
// account ?? suite name suite.addMockApi(new StandardMockApi(MockHttpMethod.GET, "/api/user/").setSuccessDataFile("user.json")) MockApiInterceptor mockApiInterceptor = new MockApiInterceptor(context);
mockApiInterceptor.addMockApiSuite(suite);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
.addInterceptor(mockApiInterceptor)
// ??mock api interceptor
.addInterceptor(new UserAgentInterceptor(context));
....
????? /api/user/
????????????mock??? ;-)
??
MockApiSuite
???mock??api??????????????api????????&????????????Suite????????????api????suite??????account???purchase??????????????????????
StandardMockApi
StandardMockApi????????mock?api????????????mock? HTTP Method???GET?POST?PUT?DELETE???????????mock?url**??????**??????????????????????mock api???????????????
setSuccessDataFile
??api????????????setErrorDataFile
??api????????????setState
???????api???????????????????setRequestTime
??api???????????????????
Mock??
- ??mock??????? mockdata/[suite_name]/?
- MockApiInterceptor?????????????mock?????sdcard??????assets???????????Mock?????sdcard??????????adb??????mock?????????App?????????