retrofit.Retrofit.create()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(279)

本文整理了Java中retrofit.Retrofit.create方法的一些代码示例,展示了Retrofit.create的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Retrofit.create方法的具体详情如下:
包路径:retrofit.Retrofit
类名称:Retrofit
方法名:create

Retrofit.create介绍

暂无

代码示例

代码示例来源:origin: yigit/dev-summit-architecture-demo

@Provides
  @Singleton
  public ApiService apiService(DemoConfig demoConfig) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return new Retrofit.Builder()
        .baseUrl(demoConfig.getApiUrl())
        .addConverterFactory(JacksonConverterFactory.create(mapper)).build()
        .create(ApiService.class);
  }
}

代码示例来源:origin: boredream/DesignResCollection

public static AppService getApiService() {
  return retrofit.create(AppService.class);
}

代码示例来源:origin: macoscope/RoomBookerMVP

public RetrofitRestRepository(Retrofit retrofit) {
  apiService = retrofit.create(ApiService.class);
}

代码示例来源:origin: Leaking/WeGit

public Authenticator(Context context) {
  super(context);
  this.context = context;
  this.app = (GithubApplication) context.getApplicationContext();
  this.retrofit = RetrofitUtil.getRetrofitWithoutTokenInstance(context);
  this.service = retrofit.create(GithubService.class);
}

代码示例来源:origin: Leaking/WeGit

public TokenInteractorImpl(Context context, final OnTokenCreatedListener listener){
  this.context = context;
  this.listener = listener;
  this.service = RetrofitUtil.getRetrofitWithoutTokenInstance(context).create(GithubService.class);
}

代码示例来源:origin: codepath/dagger2-example

@Provides
  @UserScope
  public GitHubApiInterface providesGitHubInterface(Retrofit retrofit) {
    return retrofit.create(GitHubApiInterface.class);
  }
}

代码示例来源:origin: Leaking/WeGit

public RepoInteractorImpl(Context context, final OnLoadRepoListener listener){
  this.context = context;
  this.listener = listener;
  this.service = RetrofitUtil.getJsonRetrofitInstance(context).create(GithubService.class);
  this.gitHubAccount = GitHubAccount.getInstance(context);
}

代码示例来源:origin: Leaking/WeGit

public FindItemsInteractorImpl(Context context, final OnLoadItemListListener listener) {
  this.context = context;
  this.service = RetrofitUtil.getJsonRetrofitInstance(context).create(GithubService.class);
  this.gitHubAccount = GitHubAccount.getInstance(context);
  this.listener = listener;
}

代码示例来源:origin: Leaking/WeGit

public RepoAndEventPreviewInteractorImpl(final Context context, final OnLoadRepoAndEventPreviewListener listener){
  this.context = context;
  this.listener = listener;
  this.service = RetrofitUtil.getJsonRetrofitInstance(context).create(GithubService.class);
  this.gitHubAccount = GitHubAccount.getInstance(context);
}

代码示例来源:origin: Leaking/WeGit

public CodeInteractorImpl(final Context context, final OnCodeListener listener){
  this.listener = listener;
  this.context = context;
  this.service = RetrofitUtil.getStringRetrofitInstance(context).create(GithubService.class);
  this.gitHubAccount = GitHubAccount.getInstance(context);
}

代码示例来源:origin: bingoogolapple/BGARefreshLayoutDemo

@Override
public void onCreate() {
  super.onCreate();
  sInstance = this;
  mEngine = new Retrofit.Builder()
      .baseUrl("http://7xk9dj.com1.z0.glb.clouddn.com/")
      .addConverterFactory(GsonConverterFactory.create())
      .build().create(Engine.class);
}

代码示例来源:origin: akraxx/gitlab-jira-integration

@Inject
public GitLabService(@NonNull GitLabConfiguration gitLabConfiguration) {
  this.gitLabConfiguration = gitLabConfiguration;
  this.gitLabEndPoints = new Retrofit.Builder()
      .baseUrl(sanitizeURL(gitLabConfiguration.getUrl()))
      .addConverterFactory(JacksonConverterFactory.create())
      .build()
      .create(GitLabEndPoints.class);
}

代码示例来源:origin: SpikeKing/wcl-dagger-demo

@Provides
  @Singleton
  protected GitHubService provideGitHubService() {
    Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(GitHubService.ENDPOINT)
        .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // 添加Rx适配器
        .addConverterFactory(GsonConverterFactory.create()) // 添加Gson转换器
        .build();
    return retrofit.create(GitHubService.class);
  }
}

代码示例来源:origin: vickychijwani/udacity-p1-p2-popular-movies

public Model() {
  mDatabase = new Database();
  Gson gson = new GsonBuilder()
      .registerTypeAdapter(Date.class, new DateDeserializer())
      .registerTypeAdapter(new TypeToken<RealmList<Video>>() {}.getType(), new VideoRealmListDeserializer())
      .registerTypeAdapter(new TypeToken<RealmList<Review>>() {}.getType(), new ReviewRealmListDeserializer())
      .setExclusionStrategies(new RealmExclusionStrategy())
      .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
      .create();
  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(BASE_URL)
      .addConverterFactory(GsonConverterFactory.create(gson))
      .build();
  mApiService = retrofit.create(MovieDBApiService.class);
  mApiKey = "075c3ac2845f0a71e38797ec6f57cdfb";
  getDataBus().register(this);
}

代码示例来源:origin: VictorAlbertos/RxGcm

public GcmServerService() {
  this.apiGcmServer = new Retrofit.Builder()
      .baseUrl(ApiGcmServer.URL_BASE)
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(GsonConverterFactory.create())
      .build().create(ApiGcmServer.class);
}

代码示例来源:origin: SpikeKing/wcl-rx-cache-demo

public GitHubClient() {
  mGitHubService = new Retrofit.Builder()
      .baseUrl(GitHubService.BASE_URL)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .build()
      .create(GitHubService.class);
}

代码示例来源:origin: fedepaol/RxRestSample

public GitHubClient() {
  mClient = new Retrofit.Builder()
             .baseUrl("https://api.github.com")
             .addConverterFactory(GsonConverterFactory.create())
             .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
             .build()
             .create(GitHubService.class);
}

代码示例来源:origin: adhamenaya/AndroidMosaicLayout

private void downloadImages() {
  mWebServiceProxy = new Retrofit.Builder().baseUrl(WebServiceProxy.ENDPOINT)
      .addConverterFactory(GsonConverterFactory.create())
      .build().create(WebServiceProxy.class);
  Call<ResponseData> call = mWebServiceProxy.getImages();
  call.enqueue(this);
}

代码示例来源:origin: fangx/ZhiHuMVP

public static <T> T createApi(Context context, Class<T> clazz) {
  if (singleton == null) {
    synchronized (RetrofitUtils.class) {
      if (singleton == null) {
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.baseUrl("http://zhuanlan.zhihu.com/")
            .addConverterFactory(GsonConverterFactory.create())//设置远程地址
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create());
        singleton = builder.build();
      }
    }
  }
  return singleton.create(clazz);
}

代码示例来源:origin: io.paradoxical/cassieq-client

static CassieqApi createClient(String baseUri, CassieqCredentials cassieqCredentials) {
  final Logger logger = getLogger(CassieqApi.class);
  OkHttpClient client = new OkHttpClient();
  client.interceptors().add(chain -> {
    final Request request = chain.request();
    return chain.proceed(cassieqCredentials.authorize(request));
  });
  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(baseUri)
      .addConverterFactory(JacksonConverterFactory.create(Mappers.getJson()))
      .client(client)
      .build();
  return retrofit.create(CassieqApi.class);
}

相关文章