Skip to content

Commit

Permalink
'可以动态修改baseurl'
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelly committed Feb 12, 2020
1 parent d3fc285 commit f49fb9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import retrofit2.converter.scalars.ScalarsConverterFactory;


public final class RestCreator {
public class RestCreator {

private static final class RetrofitHolder {
private static class RetrofitHolder {

private static final String BASE_URL = ProjectInit.getConfiguration(ConfigKeys.API_HOST_SING);
private static String BASE_URL = ProjectInit.getConfiguration(ConfigKeys.API_HOST_SING);

private static final Retrofit RETROFIT_CLIENT = new Retrofit
private static Retrofit RETROFIT_CLIENT = new Retrofit
.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
Expand All @@ -39,7 +39,7 @@ private static Retrofit RETROFIT_CUSTOM_INTERCEPTOR(Interceptor interceptor) {
}

//单独配置okhttp
private static final class OkHttpHolder {
private static class OkHttpHolder {

private static final int TIME_OUT = 60;

Expand All @@ -66,9 +66,9 @@ private static OkHttpClient OK_HTTP_CLIENT_INTERCEPTOR(Interceptor interceptor)
}

//提供一个接口让调用者得到retrofit对象
private static final class RestServiceHolder {
private static class RestServiceHolder {

private static final RestService REST_SERVICE = RetrofitHolder.RETROFIT_CLIENT.create(RestService.class);
private static RestService REST_SERVICE = RetrofitHolder.RETROFIT_CLIENT.create(RestService.class);

private static RestService getRestServiceInterceptor(Interceptor interceptor) {
return RetrofitHolder.RETROFIT_CUSTOM_INTERCEPTOR(interceptor).create(RestService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public interface RestService {
@GET
Call<String> get(@Url String url, @QueryMap Map<String, Object> params);

@Headers({"Content-Type: application/json", "Accept: application/json"})
@FormUrlEncoded
@POST
Call<String> post(@Url String url, @FieldMap Map<String, Object> params);

@POST
Call<String> postRaw(@Url String url, @Body RequestBody params);

@Headers({"Content-Type: application/json", "Accept: application/json"})
@POST
Call<String> postMapRaw(@Url String url,@Body RequestBody params);

@Streaming
@GET
Call<ResponseBody> down(@Url String url);
Expand Down

0 comments on commit f49fb9f

Please sign in to comment.