public Notify(String url) throws RuntimeException { Preconditions.checkArgument(!Strings.isNullOrEmpty(url), "The URL may not be null or empty."); try { String hostPart = new URI(url).getHost(); // Validate the url. InetAddress.getByName(hostPart); } catch (URISyntaxException e) { throw new IllegalArgumentException("The given URI is not valid " + e.getMessage()); } catch (UnknownHostException e) { throw new IllegalArgumentException("The given URI is not valid " + e.getMessage()); } OkHttpClient okHttpClient = new OkHttpClient(); RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(url) .setErrorHandler(new NotifyErrorHandler()) .setClient(new OkClient(okHttpClient)) .build(); this.service = restAdapter.create(NotifyService.class); }
public static <T> T create(String url, Class<T> clazz) { try { String hostPart = new URI(url).getHost(); // Check whether it is a valide url. InetAddress.getByName(hostPart); } catch (URISyntaxException e) { throw new IllegalArgumentException("The given URI is not valid " + e.getMessage()); } catch (UnknownHostException e) { throw new IllegalArgumentException("The given URI is not valid " + e.getMessage()); } OkHttpClient okHttpClient = new OkHttpClient(); RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(url) .setErrorHandler(new HttpErrorHandler()) .setClient(new OkClient(okHttpClient)) .build(); return restAdapter.create(clazz); }
public PrometheusQuery(String url) throws RuntimeException { Preconditions.checkArgument(!Strings.isNullOrEmpty(url), "The URL may not be null or empty."); try { String hostPart = new URI(url).getHost(); // Validate the url. InetAddress.getByName(hostPart); } catch (URISyntaxException e) { throw new IllegalArgumentException("The given URI is not valid " + e.getMessage()); } catch (UnknownHostException e) { throw new IllegalArgumentException("The given URI is not valid " + e.getMessage()); } OkHttpClient okHttpClient = new OkHttpClient(); RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(url) .setErrorHandler(new MyErrorHandler()) .setClient(new OkClient(okHttpClient)) .build(); this.agent = restAdapter.create(PrometheusQueryService.class); }
@Override public RxGitterAuthenticationClient build() { restAdapterBuilder.setEndpoint(Constants.GitterEndpoints.GITTER_AUTHENTICATION_ENDPOINT); restAdapterBuilder.setErrorHandler(new ErrorHandler() { @Override public Throwable handleError(RetrofitError cause) { Throwable returnThrowable = cause; if (cause.getKind() == RetrofitError.Kind.HTTP) { if (cause.getResponse() != null) { GitterApiErrorResponse errorResponse = (GitterApiErrorResponse) cause.getBodyAs(GitterApiErrorResponse.class); if (errorResponse != null) { returnThrowable = new GitterApiException(errorResponse); returnThrowable.setStackTrace(cause.getStackTrace()); } } } return returnThrowable; } }); RxGitterAuthenticateApi api = restAdapterBuilder.build().create(RxGitterAuthenticateApi.class); return new RxGitterAuthenticationClient(api); } }
/** * Create and return a new archive service with the specified endpoint URL. * * @since 2.0 * @param endpointUrl endpoint URL, must not be null * @return a new archive service with the specified endpoint URL */ public ArchiveService createArchiveService(final String endpointUrl) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonArchivedSequenceConverter(jsonFactory)) .build().create(ArchiveService.class); }
/** * Create and return a new lookup service with the specified endpoint URL. * * @since 2.0 * @param endpointUrl endpoint URL, must not be null * @return a new overlap service with the specified endpoint URL */ public OverlapService createOverlapService(final String endpointUrl) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonOverlapConverter(jsonFactory)) .build().create(OverlapService.class); }
/** * Create and return a new variation service with the specified endpoint URL. * * @param endpointUrl endpoint URL, must not be null * @return a new variation service with the specified endpoint URL */ public VariationService createVariationService(final String endpointUrl) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonVariationConverter(jsonFactory)) .build().create(VariationService.class); }
/** * Create and return a new sequence service with the specified endpoint URL. * * @since 1.3 * @param endpointUrl endpoint URL, must not be null * @return a new sequence service with the specified endpoint URL */ public SequenceService createSequenceService(final String endpointUrl) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonSequenceConverter(jsonFactory)) .build().create(SequenceService.class); } }
@Provides @Singleton static SequenceService createSequenceService(@EndpointURL final String endpointUrl, final JsonFactory jsonFactory, final ErrorHandler errorHandler) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonSequenceConverter(jsonFactory)) .build().create(SequenceService.class); } }
@Provides @Singleton static OverlapService createOverlapService(@EndpointURL final String endpointUrl, final JsonFactory jsonFactory, final ErrorHandler errorHandler) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonOverlapConverter(jsonFactory)) .build().create(OverlapService.class); }
/** * Create and return a new lookup service with the specified endpoint URL. * * @param endpointUrl endpoint URL, must not be null * @return a new lookup service with the specified endpoint URL */ public LookupService createLookupService(final String endpointUrl) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonLookupConverter(jsonFactory)) .build().create(LookupService.class); }
@Provides @Singleton OAuthGitHubWebFlow provideOAuthGitHubWebFlow(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) { RestAdapter restAdapter = new RestAdapter.Builder() .setErrorHandler(errorHandler) .setClient(new OkClient(okHttpClient)) .setConverter(new GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.BASIC) .setEndpoint("https://github.com") .build(); return restAdapter.create(OAuthGitHubWebFlow.class); }
@Provides @Singleton ReposTrendingApiService provideTrendingApiService(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) { RestAdapter restAdapter = new RestAdapter.Builder() .setErrorHandler(errorHandler) .setClient(new OkClient(okHttpClient)) .setConverter(new GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.BASIC) .setEndpoint("http://trending.codehub-app.com") .build(); return restAdapter.create(ReposTrendingApiService.class); }
public WeatherRestAdapter() { mRestAdapter = new RestAdapter.Builder() .setLogLevel(RestAdapter.LogLevel.FULL) .setEndpoint(WEATHER_URL) .setErrorHandler(new WeatherApiErrorHandler()) .build(); mApi = mRestAdapter.create(WeatherApi.class); // create the interface Log.d(TAG, "WeatherRestAdapter -- created"); }
@Provides Endpoints provideEndpoints() { return new RestAdapter.Builder() .setEndpoint(ConfigEndpoints.URL_BASE) .setErrorHandler(new ErrorHandler() { @Override public Throwable handleError(RetrofitError cause) { JsonObject jsonObject = (JsonObject) cause.getBodyAs(JsonObject.class); String message = jsonObject.get("error").getAsString(); return new RuntimeException(message); } }).build().create(Endpoints.class); } }
@Provides @Singleton static VariationService createVariationService(@EndpointURL final String endpointUrl, final JsonFactory jsonFactory, final ErrorHandler errorHandler) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonVariationConverter(jsonFactory)) .build().create(VariationService.class); }
@Provides @Singleton FirService provideFirService(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) { RestAdapter restAdapter = new RestAdapter.Builder() .setErrorHandler(errorHandler) .setClient(new OkClient(okHttpClient)) .setConverter(new GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.BASIC) .setEndpoint("http://api.fir.im") .build(); return restAdapter.create(FirService.class); }
@Provides @Singleton static ArchiveService createArchiveService(@EndpointURL final String endpointUrl, final JsonFactory jsonFactory, final ErrorHandler errorHandler) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonArchivedSequenceConverter(jsonFactory)) .build().create(ArchiveService.class); }
@Provides @Singleton RestAdapter provideRestAdapter(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) { return new RestAdapter.Builder() .setErrorHandler(errorHandler) .setClient(new OkClient(okHttpClient)) .setConverter(new GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.BASIC) // .setEndpoint("http://mock-api.com/TyTabSFqXNyqMpNw.mock") .setEndpoint("https://api.github.com") .build(); }
@Provides @Singleton static LookupService createLookupService(@EndpointURL final String endpointUrl, final JsonFactory jsonFactory, final ErrorHandler errorHandler) { return new RestAdapter.Builder() .setEndpoint(endpointUrl) .setErrorHandler(errorHandler) .setConverter(new JacksonLookupConverter(jsonFactory)) .build().create(LookupService.class); }