retrofit.client.Client Java Examples
The following examples show how to use
retrofit.client.Client.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrupalManager.java From drupalfit with MIT License | 6 votes |
public DrupalService getService(String endpoint) { if (endpoint == null) return mService; if (mService == null) { this.endpoint = endpoint; Client client = new OkClient(getOkHttpClient()); if (mRequestInterceptor == null) { mRequestInterceptor = new SimpleRequestInterceptor(); } mRequestInterceptor.cookie = cookie; mRequestInterceptor.accessToken = accessToken; mRequestInterceptor.xcsrfToken = xcsrfToken; mService = new RestAdapter.Builder() .setEndpoint(endpoint) .setRequestInterceptor(mRequestInterceptor) .setErrorHandler(new ErrorHandler()) .setClient(client) .setConverter(new retrofit.converter.JacksonConverter()) .setLogLevel(RestAdapter.LogLevel.FULL) // Do this for development too. .build().create(DrupalService.class); } return mService; }
Example #2
Source File: DrupalOAuth2Manager.java From drupalfit with MIT License | 6 votes |
public DrupalOAuth2Manager(Context context, String endpoint, String clientId, String clientSecret) { setContext(context); setEndpoint(endpoint); setClientId(clientId); setClientSecret(clientSecret); Client client = new OkClient(getOkHttpClient()); if (mRequestInterceptor == null) { mRequestInterceptor = new SimpleRequestInterceptor(); } mRequestInterceptor.cookie = cookie; RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(endpoint) .setRequestInterceptor(mRequestInterceptor) .setErrorHandler(new ErrorHandler()) .setClient(client) .setConverter(new retrofit.converter.JacksonConverter()) .build(); mService = restAdapter.create(DrupalOAuth2.class); }
Example #3
Source File: GithubConfig.java From echo with Apache License 2.0 | 6 votes |
@Bean public GithubService githubService( Endpoint githubEndpoint, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) { log.info("Github service loaded"); GithubService githubClient = new RestAdapter.Builder() .setEndpoint(githubEndpoint) .setConverter(new JacksonConverter()) .setClient(retrofitClient) .setLogLevel(RestAdapter.LogLevel.FULL) .setLog(new Slf4jRetrofitLogger(GithubService.class)) .build() .create(GithubService.class); return githubClient; }
Example #4
Source File: Platform.java From android-discourse with Apache License 2.0 | 6 votes |
@Override Client.Provider defaultClient() { final Client client; if (hasOkHttpOnClasspath()) { client = OkClientInstantiator.instantiate(); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { client = new AndroidApacheClient(); } else { client = new UrlConnectionClient(); } return new Client.Provider() { @Override public Client get() { return client; } }; }
Example #5
Source File: ApiModule.java From Pioneer with Apache License 2.0 | 5 votes |
@Provides @Singleton RestAdapter provideRestAdapter(Endpoint endpoint, Client client, ErrorHandler errorHandler) { return new RestAdapter.Builder() // .setClient(client) // .setEndpoint(endpoint) // .setErrorHandler(errorHandler) .build(); }
Example #6
Source File: RetrofitApacheClientBuilder.java From hello-pinnedcerts with MIT License | 5 votes |
public Client.Provider build() { return new Client.Provider() { public Client get() { return new ApacheClient(httpClientBuilder.build()); } }; }
Example #7
Source File: SpotifyServiceTest.java From spotify-web-api-android with MIT License | 5 votes |
@Before public void setUp() { mMockClient = mock(Client.class); RestAdapter restAdapter = new RestAdapter.Builder() .setClient(mMockClient) .setEndpoint(SpotifyApi.SPOTIFY_WEB_API_ENDPOINT) .build(); mSpotifyService = restAdapter.create(SpotifyService.class); mGson = new GsonBuilder().create(); }
Example #8
Source File: PagerDutyConfig.java From echo with Apache License 2.0 | 5 votes |
@Bean PagerDutyService pagerDutyService( Endpoint pagerDutyEndpoint, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) { log.info("Pager Duty service loaded"); return new RestAdapter.Builder() .setEndpoint(pagerDutyEndpoint) .setConverter(new JacksonConverter()) .setClient(retrofitClient) .setLogLevel(retrofitLogLevel) .setLog(new Slf4jRetrofitLogger(PagerDutyService.class)) .build() .create(PagerDutyService.class); }
Example #9
Source File: JiraConfig.java From echo with Apache License 2.0 | 5 votes |
@Bean JiraService jiraService( JiraProperties jiraProperties, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) { if (x509ConfiguredClient != null) { LOGGER.info("Using X509 Cert for Jira Client"); retrofitClient = x509ConfiguredClient; } RestAdapter.Builder builder = new RestAdapter.Builder() .setEndpoint(newFixedEndpoint(jiraProperties.getBaseUrl())) .setConverter(new JacksonConverter()) .setClient(retrofitClient) .setLogLevel(retrofitLogLevel) .setLog(new Slf4jRetrofitLogger(JiraService.class)); if (x509ConfiguredClient == null) { String credentials = String.format("%s:%s", jiraProperties.getUsername(), jiraProperties.getPassword()); final String basic = String.format("Basic %s", Base64.encodeBase64String(credentials.getBytes())); builder.setRequestInterceptor( request -> { request.addHeader("Authorization", basic); request.addHeader("Accept", "application/json"); }); } return builder.build().create(JiraService.class); }
Example #10
Source File: RestClientFactory.java From echo with Apache License 2.0 | 5 votes |
public Client getClient(Boolean insecure) { if (insecure) { return new OkClient(httpClientFactory.getInsecureClient()); } else { return new OkClient(); } }
Example #11
Source File: ApiModule.java From Pioneer with Apache License 2.0 | 5 votes |
@Provides @Singleton RestAdapter provideRestAdapter(Endpoint endpoint, Client client, ErrorHandler errorHandler) { return new RestAdapter.Builder() // .setClient(client) // .setEndpoint(endpoint) // .setErrorHandler(errorHandler) .build(); }
Example #12
Source File: ApiModule.java From dagger2-example with MIT License | 5 votes |
@Provides @Singleton RestAdapter provideRestAdapter(Endpoint endpoint, Client client) { return new RestAdapter.Builder() .setClient(client) .setLogLevel(RestAdapter.LogLevel.FULL) .setEndpoint(endpoint) .build(); }
Example #13
Source File: BaseNetworkJob.java From Mover with Apache License 2.0 | 5 votes |
public static <T> T create(String endpoint, Class<T> service, Client client){ RestAdapter adapter = new RestAdapter.Builder() .setEndpoint(endpoint) .setLogLevel(RestAdapter.LogLevel.BASIC) .setClient(client) .build(); return adapter.create(service); }
Example #14
Source File: Platform.java From android-discourse with Apache License 2.0 | 5 votes |
@Override Client.Provider defaultClient() { final Client client; if (hasOkHttpOnClasspath()) { client = OkClientInstantiator.instantiate(); } else { client = new UrlConnectionClient(); } return new Client.Provider() { @Override public Client get() { return client; } }; }
Example #15
Source File: RestAdapter.java From android-discourse with Apache License 2.0 | 5 votes |
/** * The HTTP client used for requests. */ public Builder setClient(Client.Provider clientProvider) { if (clientProvider == null) { throw new NullPointerException("Client provider may not be null."); } this.clientProvider = clientProvider; return this; }
Example #16
Source File: RestAdapter.java From android-discourse with Apache License 2.0 | 5 votes |
private RestAdapter(Server server, Client.Provider clientProvider, Executor httpExecutor, Executor callbackExecutor, RequestInterceptor requestInterceptor, Converter converter, Profiler profiler, ErrorHandler errorHandler, Log log, LogLevel logLevel) { this.server = server; this.clientProvider = clientProvider; this.httpExecutor = httpExecutor; this.callbackExecutor = callbackExecutor; this.requestInterceptor = requestInterceptor; this.converter = converter; this.profiler = profiler; this.errorHandler = errorHandler; this.log = log; this.logLevel = logLevel; }
Example #17
Source File: SecuredRestBuilder.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username, String password, String clientId, String clientSecret) { super(); this.client = client; this.tokenIssuingEndpoint = tokenIssuingEndpoint; this.username = username; this.password = password; this.clientId = clientId; this.clientSecret = clientSecret; }
Example #18
Source File: MockRestAdapter.java From uphold-sdk-android with MIT License | 5 votes |
public MockRestAdapter(final String responseString, final HashMap<String, String> headers) { this.exceptionReference = new AtomicReference<>(); this.requestReference = new AtomicReference<>(); this.resultReference = new AtomicReference<>(); this.mockRestAdapter = new UpholdRestAdapter(); this.restAdapter = new RestAdapter.Builder().setEndpoint(BuildConfig.API_SERVER_URL) .setRequestInterceptor(this.mockRestAdapter.getUpholdRequestInterceptor()) .setClient(new Client() { @Override public Response execute(Request request) throws IOException { requestReference.set(request); return new Response("some/url", 200, "reason", new ArrayList<Header>() {{ if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); add(new retrofit.client.Header(key, value)); } } }}, new TypedByteArray("application/json", responseString == null ? new byte[0] : responseString.getBytes())); } }).build(); this.mockRestAdapter.setAdapter(this.restAdapter); }
Example #19
Source File: SecuredRestBuilder.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username, String password, String clientId, String clientSecret) { super(); this.client = client; this.tokenIssuingEndpoint = tokenIssuingEndpoint; this.username = username; this.password = password; this.clientId = clientId; this.clientSecret = clientSecret; }
Example #20
Source File: RestAdapter.java From android-discourse with Apache License 2.0 | 5 votes |
/** * The HTTP client used for requests. */ public Builder setClient(final Client client) { if (client == null) { throw new NullPointerException("Client may not be null."); } return setClient(new Client.Provider() { @Override public Client get() { return client; } }); }
Example #21
Source File: TimeoutClientProvider.java From infobip-api-java-client with Apache License 2.0 | 5 votes |
@Override public Client get() { final OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setReadTimeout(configuration.getReadTimeout(), TimeUnit.MILLISECONDS); okHttpClient.setConnectTimeout(configuration.getConnectionTimeout(), TimeUnit.MILLISECONDS); return new OkClient(okHttpClient); }
Example #22
Source File: SecuredRestBuilder.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username, String password, String clientId, String clientSecret) { super(); this.client = client; this.tokenIssuingEndpoint = tokenIssuingEndpoint; this.username = username; this.password = password; this.clientId = clientId; this.clientSecret = clientSecret; }
Example #23
Source File: SecuredRestBuilder.java From mobilecloud-15 with Apache License 2.0 | 4 votes |
@Override public SecuredRestBuilder setClient(Client client) { this.client = client; return (SecuredRestBuilder) super.setClient(client); }
Example #24
Source File: TaskExecutor.java From droidcon-android-espresso with Apache License 2.0 | 4 votes |
public TaskExecutor(Client client) { this.client = client; }
Example #25
Source File: UberClient.java From uber-java-client with MIT License | 4 votes |
/** * Constructor * @param clientId * @param clientSecret * @param clientRedirectUri * @param client * @param logLevel */ public UberClient(String clientId, String clientSecret, String clientRedirectUri, String serverToken, Client client, boolean useSandbox, RestAdapter.LogLevel logLevel) { this.clientId = clientId; this.clientSecret = clientSecret; this.clientRedirectUri = clientRedirectUri; this.serverToken = serverToken; GsonBuilder gsonBuilder = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return new Date(json.getAsJsonPrimitive().getAsLong()); } }); OkHttpClient okHttpClient = new OkHttpClient(); gson = gsonBuilder.create(); RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(useSandbox ? sandboxApiUri : apiUri) .setRequestInterceptor(new RequestInterceptor() { @Override public void intercept(RequestFacade requestFacade) { if (hasAccessToken()) { requestFacade.addHeader("Authorization", "Bearer " + getAccessToken()); return; } else if (hasServerToken()) { requestFacade.addHeader("Authorization", "Token " + getServerToken()); } } }) .setErrorHandler(new ErrorHandler() { @Override public Throwable handleError(RetrofitError retrofitError) { if (retrofitError != null && retrofitError.getResponse() != null) { switch (retrofitError.getResponse().getStatus()) { case 401: //Unauthorized return new UnauthorizedException(); case 403: //Forbidden return new ForbiddenException(); } } return retrofitError; } }) .setLogLevel(logLevel) .setClient(client == null ? new OkClient(okHttpClient) : client) .setConverter(new GsonConverter(gson)) .build(); apiService = restAdapter.create(UberService.class); if (useSandbox) { sandboxService = restAdapter.create(SandboxService.class); } RestAdapter authRestAdapter = new RestAdapter.Builder() .setEndpoint(oAuthUri) .setLogLevel(logLevel) .setClient(client == null ? new OkClient(okHttpClient) : client) .setConverter(new GsonConverter(gson)) .build(); authService = authRestAdapter.create(UberAuthService.class); }
Example #26
Source File: ApiModule.java From Pioneer with Apache License 2.0 | 4 votes |
@Provides @Singleton Client provideClient(OkHttpClient client) { return new OkClient(client); }
Example #27
Source File: ConnectivityAwareUrlClient.java From MVPAndroidBootstrap with Apache License 2.0 | 4 votes |
public Client getWrappedClient() { return wrappedClient; }
Example #28
Source File: ConnectivityAwareUrlClient.java From MVPAndroidBootstrap with Apache License 2.0 | 4 votes |
public void setWrappedClient(Client wrappedClient) { this.wrappedClient = wrappedClient; }
Example #29
Source File: ConnectivityAwareUrlClient.java From RxAndroidBootstrap with Apache License 2.0 | 4 votes |
public ConnectivityAwareUrlClient(Context context, Client client) { this.context = context; this.wrappedClient = client; }
Example #30
Source File: PipelineTriggerConfiguration.java From echo with Apache License 2.0 | 4 votes |
@Bean public Client retrofitClient() { return new OkClient(); }