• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Builder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中retrofit2.Retrofit.Builder的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Builder类属于retrofit2.Retrofit包,在下文中一共展示了Builder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createPublicApi

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
private PUBLICApi createPublicApi(String username, String password) {
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            .registerTypeAdapter(GenericZoneSetting.class, new ZoneSettingConverter())
            .registerTypeAdapter(OverlayTerminationCondition.class, new TerminationConditionConverter())
            .registerTypeAdapter(OverlayTerminationConditionTemplate.class,
                    new OverlayTerminationConditionTemplateConverter())
            .registerTypeAdapter(GenericZoneCapabilities.class, new ZoneCapabilitiesConverter()).create();

    Builder adapterBuilder = new Retrofit.Builder().baseUrl(API_URL)
            // .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(gson));

    ApiClient apiClient = new ApiClient();
    apiClient.setAdapterBuilder(adapterBuilder);
    apiClient.getOkBuilder().addInterceptor(new UserAgentInterceptor(USER_AGENT));

    TokenRequestBuilder tokenRequestBuilder = OAuthClientRequest.tokenLocation(OAUTH_TOKEN_URL)
            .setScope(OAUTH_SCOPE).setClientId(OAUTH_CLIENT_ID).setClientSecret(OAUTH_CLIENT_SECRET)
            .setUsername(username).setPassword(password);
    OkHttpClient authHttpClient = new OkHttpClient.Builder().addInterceptor(new UserAgentInterceptor(USER_AGENT))
            .build();

    OAuth oauth = new OAuth(authHttpClient, tokenRequestBuilder);
    oauth.setFlow(OAuthFlow.password);

    apiClient.addAuthorization("oauth", oauth);
    return apiClient.createService(PUBLICApi.class);
}
 
开发者ID:dfrommi,项目名称:openhab-tado,代码行数:29,代码来源:TadoApiClientFactory.java


示例2: testJspoonConverterAllowsRetrofitToChooseAnotherConverter

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
@Test
public void testJspoonConverterAllowsRetrofitToChooseAnotherConverter() throws Exception {
    MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("Ahoy matey!"));

    Converter mockConverter = mock(Converter.class);
    when(mockConverter.convert(any(ResponseBody.class)))
        .thenReturn(new Item("1", "Item 1"));

    Factory mockConverterFactory = mock(Factory.class);
    when(mockConverterFactory.responseBodyConverter(
        any(Type.class),
        any(Annotation[].class),
        any(Retrofit.class))).thenReturn(mockConverter);

    NonScrapingService service = new Builder()
        .baseUrl(server.url("/"))
        .addConverterFactory(JspoonConverterFactory.create())
        .addConverterFactory(mockConverterFactory)
        .build()
        .create(NonScrapingService.class);
    Item item = service.getItem("1").execute().body();
    assertEquals(item.id, "1");
    assertEquals(item.name, "Item 1");

    verify(mockConverter, atLeastOnce()).convert(any(ResponseBody.class));
}
 
开发者ID:DroidsOnRoids,项目名称:jspoon,代码行数:28,代码来源:JspoonConverterFactoryTest.java


示例3: createRetrofit

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
private Retrofit createRetrofit(String baseHost) {
  return new Builder().baseUrl(baseHost)
      .client(httpClient)
      .addCallAdapterFactory(callAdapterFactory)
      .addConverterFactory(converterFactory)
      .build();
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:8,代码来源:WebServiceFactory.java


示例4: onCreate

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
@Override public void onCreate() {
    setStrictModeConfiguration();
    super.onCreate();
    setStrictModeConfigurationWorkaround();

    Iconify.with(new FontAwesomeModule());

    gson = new Gson();
    database = new Database(this, gson);
    httpClient = new OkHttpClient.Builder()
            .build();
    Picasso.setSingletonInstance(new Picasso.Builder(this)
            .listener(new Listener() {
                @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                    Log.d("Picasso", "Image failed loading: " + exception);
                }
            })
            .build());

    if (Constants.isBaseApiUrlDefined() && !FORCE_MOCK) {
        Retrofit retrofit = new Builder()
                .baseUrl(Constants.API_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(httpClient)
                .build();
        api = retrofit.create(VespappApi.class);
    }
}
 
开发者ID:CarlosTenorio,项目名称:vespapp-android,代码行数:29,代码来源:Vespapp.java


示例5: executeCommand

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
@Override
public void executeCommand(IMessage msg) {
	URL url = resolveUrl(msg);
	em = new EmbedBuilder();
	if(url == null) {
		em.withColor(Color.RED).withTitle("Error").withDesc("No image found in your message or the previous " + SEARCH + " messages");
		MessageUtils.sendMessage(msg.getChannel(), em.build());
		return;
	}
	Interceptor interceptor;
	Builder builder = new Retrofit.Builder()
			.baseUrl(SauceNaoAPI.ENDPOINT)
			.addConverterFactory(GsonConverterFactory.create());
	if((interceptor = queryInterceptor()) != null) {
		builder.client((new OkHttpClient.Builder()).addInterceptor(interceptor).build());
	} else {
		em.withColor(Color.RED).withTitle("Error").withDesc("This bot isn't setup to search SauceNao");
		MessageUtils.sendMessage(msg.getChannel(), em.build());
		return;
	}
	Retrofit rf = builder.build();
	
	SauceNaoAPI api = rf.create(SauceNaoAPI.class);
	Call<SauceNaoResult> sauceCall = api.getSauce(url);
	try {
		SauceNaoResult sauce = sauceCall.execute().body();
		if(sauce.getResults() == null) {
			em.withColor(Color.RED).withTitle("Error").withDesc(String.format("No results found on SauceNao for <%s>", url.toString()));
			em.withThumbnail(url.toString());
			MessageUtils.sendMessage(msg.getChannel(), em.build());
			return;
		}
		resolveData(sauce);
	} catch (IOException e) {
		e.printStackTrace();
	}
	MessageUtils.sendMessage(msg.getChannel(), em.build());
}
 
开发者ID:paul-io,项目名称:momo-discord-old,代码行数:39,代码来源:SourceSearch.java


示例6: executeCommand

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
@Override
public void executeCommand(Message msg) {
	URL url = resolveUrl(msg);
	em = new EmbedBuilder();
	if (url == null) {
		em.setTitle("Error", null)
		.setColor(Color.RED)
		.setDescription("No image found in your message or the previous " + SEARCH + " messages");
		msg.getChannel().sendMessage(em.build()).queue();
		return;
	}
	Interceptor interceptor;
	Builder builder = new Retrofit.Builder()
			.baseUrl(SauceNaoAPI.ENDPOINT)
			.addConverterFactory(GsonConverterFactory.create());
	if ((interceptor = queryInterceptor()) != null) {
		builder.client((new OkHttpClient.Builder()).addInterceptor(interceptor).build());
	} else {
		em.setTitle("Error", null)
		.setColor(Color.RED)
		.setDescription("This bot isn't setup to search SauceNao");
		msg.getChannel().sendMessage(em.build()).queue();
		return;
	}
	Retrofit rf = builder.build();

	SauceNaoAPI api = rf.create(SauceNaoAPI.class);
	Call<SauceNaoResult> sauceCall = api.getSauce(url);
	try {
		SauceNaoResult sauce = sauceCall.execute().body();
		if (sauce.getResults() == null) {
			em.setTitle("Error", null)
			.setColor(Color.RED)
			.setDescription(String.format("No results found on SauceNao for <%s>", url.toString()))
			.setThumbnail(url.toString());
			msg.getChannel().sendMessage(em.build()).queue();
			return;
		}
		resolveData(sauce);
	} catch (IOException e) {
		e.printStackTrace();
	}
	msg.getChannel().sendMessage(em.build()).queue();
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:45,代码来源:SourceSearch.java


示例7: setStrictModeConfiguration

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
private void setStrictModeConfiguration() {
    StrictMode.ThreadPolicy policy;
    policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
}
 
开发者ID:CarlosTenorio,项目名称:vespapp-android,代码行数:6,代码来源:Vespapp.java


示例8: ArmeriaRetrofitBuilder

import retrofit2.Retrofit.Builder; //导入依赖的package包/类
/**
 * Creates a {@link ArmeriaRetrofitBuilder} with the specified {@link ClientFactory}.
 */
public ArmeriaRetrofitBuilder(ClientFactory clientFactory) {
    this.clientFactory = requireNonNull(clientFactory, "clientFactory");
    retrofitBuilder = new Retrofit.Builder();
}
 
开发者ID:line,项目名称:armeria,代码行数:8,代码来源:ArmeriaRetrofitBuilder.java



注:本文中的retrofit2.Retrofit.Builder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KafkaTestUtils类代码示例发布时间:2022-05-23
下一篇:
Java FontException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap