@Override public Promise<Response> asyncWithCache(@Nonnull AuthorizationGenerator authorizationGenerator, @Nonnull HttpMethod method, @Nonnull URI url, @Nonnull Map<String, String[]> parameters, @Nonnull Map<String, String> headers, @Nonnull InputStream body, @Nonnull String addonKey) { Request.Builder request = httpClient.newRequest(getFullUrl(method, url, parameters)); return async(authorizationGenerator, method, url, parameters, headers, body, addonKey, request); }
@Override public Promise<Response> asyncWithoutCache(@Nonnull AuthorizationGenerator authorizationGenerator, @Nonnull HttpMethod method, @Nonnull URI url, @Nonnull Map<String, String[]> parameters, @Nonnull Map<String, String> headers, @Nonnull InputStream body, @Nonnull String addonKey) { Request.Builder request = httpClient.newRequest(getFullUrl(method, url, parameters)); request.setCacheDisabled(); return async(authorizationGenerator, method, url, parameters, headers, body, addonKey, request); }
@Override public Promise<InputStream> getAttachment(URI attachmentUri) { return callAndParse(client().newRequest(attachmentUri).get(), new ResponseHandler<InputStream>() { @Override public InputStream handle(final Response request) throws JSONException, IOException { return request.getEntityStream(); } } ); }
protected final <T> Promise<Void> put(final URI uri, final T entity, final JsonGenerator<T> jsonGenerator) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .put(); return call(responsePromise); }
protected final Promise<Void> post(final URI uri, final String entity) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(entity) .setContentType(JSON_CONTENT_TYPE) .post(); return call(responsePromise); }
protected final <T> Promise<Void> post(final URI uri, final T entity, final JsonGenerator<T> jsonGenerator) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .post(); return call(responsePromise); }
protected final <I, T> Promise<T> putAndParse(final URI uri, I entity, final JsonGenerator<I> jsonGenerator, final JsonObjectParser<T> parser) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .put(); return callAndParse(responsePromise, parser); }
protected final Promise<Void> post(final URI uri, final String entity) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(entity) .setContentType(JSON_CONTENT_TYPE) .post(); return call(responsePromise); }
protected final <I, T> Promise<T> putAndParse(final URI uri, I entity, final JsonGenerator<I> jsonGenerator, final JsonObjectParser<T> parser) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .put(); return callAndParse(responsePromise, parser); }
protected final <I, T> Promise<T> postAndParse(final URI uri, I entity, final JsonGenerator<I> jsonGenerator, final JsonObjectParser<T> parser) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .post(); return callAndParse(responsePromise, parser); }
private DownloadResult<ResponsePromise> scheduleDownload(Language language, String baseUrl, String path) { URI uriToDownload = resolveUri(baseUrl, path); ResponsePromise responsePromise = httpClient .newRequest(uriToDownload) .setAccept(MediaType.APPLICATION_JSON) .get(); return new DownloadResult<>(language, uriToDownload, responsePromise); }
protected final <I, T> Promise<T> postAndParse(final URI uri, I entity, final JsonGenerator<I> jsonGenerator, final JsonObjectParser<T> parser) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .post(); return callAndParse(responsePromise, parser); }
protected final <T> Promise<Void> post(final URI uri, final T entity, final JsonGenerator<T> jsonGenerator) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(toEntity(jsonGenerator, entity)) .post(); return call(responsePromise); }
private Promise<Void> postAttachments(final URI attachmentsUri, final MultipartEntityBuilder multipartEntityBuilder) { final ResponsePromise responsePromise = client() .newRequest(attachmentsUri) .setEntity(new MultiPartEntityBuilder(multipartEntityBuilder.build())) .setHeader("X-Atlassian-Token", "nocheck") .post(); return call(responsePromise); }
protected final <T> Promise<T> postAndParse(final URI uri, final JSONObject entity, final JsonObjectParser<T> parser) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(entity.toString()) .setContentType(JSON_CONTENT_TYPE) .post(); return callAndParse(responsePromise, parser); }
protected final <T> Promise<T> postAndParse(final URI uri, final JSONObject entity, final JsonObjectParser<T> parser) { final ResponsePromise responsePromise = client.newRequest(uri) .setEntity(entity.toString()) .setContentType(JSON_CONTENT_TYPE) .post(); return callAndParse(responsePromise, parser); }
@Override public Promise<Either<ClientError, List<User>>> list() { return httpClient.newRequest("/users/list").get().<Either<ClientError, List<User>>>transform() .ok(parseJson("users", new TypeReference<List<User>>(){})) .others(ClientUtils.<List<User>>error()) .fail(ClientUtils.<List<User>>throwable()) .toPromise(); } }
@Override public Promise<Either<ClientError, List<Room>>> list() { return httpClient.newRequest("/rooms/list").get().<Either<ClientError, List<Room>>>transform() .ok(parseJson("rooms", new TypeReference<List<Room>>(){})) .others(ClientUtils.<List<Room>>error()) .fail(ClientUtils.<List<Room>>throwable()) .toPromise(); }
@Override public Promise<Either<ClientError, Status>> message(String roomIdOrName, String from, String message, Option<Message.Format> format, Option<Message.BackgroundColor> color, Option<Boolean> notify) { // TODO: validate params final Map<String, String> params = messageParametersAsMap(roomIdOrName, from, message, format, color, notify); return httpClient.newRequest("/rooms/message", "application/x-www-form-urlencoded", urlEncode(params)) .post().<Either<ClientError, Status>>transform() .ok(constantRight(Status.SENT)) .others(ClientUtils.<Status>error()) .fail(ClientUtils.<Status>throwable()) .toPromise(); }
@Override public Promise<Either<ClientError, Room>> create(String name, long ownerId, Option<Boolean> privacy, Option<String> topic, Option<Boolean> enableGuestAccess) { // TODO validate params final Map<String, String> params = createParametersAsMap(name, ownerId, privacy, topic, enableGuestAccess); return httpClient.newRequest("/rooms/create", "application/x-www-form-urlencoded", urlEncode(params)) .post().<Either<ClientError, Room>>transform() .ok(parseJson("room", Room.class)) .others(ClientUtils.<Room>error()) .fail(ClientUtils.<Room>throwable()) .toPromise(); }