List of usage examples for org.apache.http.client.utils URIBuilder setParameter
public URIBuilder setParameter(final String param, final String value)
From source file:api.Client.java
public Request<DeleteStatus> deleteProductFileApiUploadService(Number storeId, String token, Number id, Number fileId) {//w w w .ja va 2 s. co m try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/files/" + fileId); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (fileId == null) throw new IllegalArgumentException("No parameter fileId is set"); return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) { @Override public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpDelete method = new HttpDelete(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new DeleteStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<OrderSearchResult> getOrdersOrderApiService(Number storeId, String token, Number limit, Number offset, String couponCode, Number orderNumber, Number totalFrom, Number totalTo, String customer, String createdFrom, String createdTo, String paymentMethod, String vendorNumber, String shippingMethod, String keywords, String fulfillmentStatus, String paymentStatus, String updatedFrom, String updatedTo) { try {/* w w w . j a v a 2 s .c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders"); if (token != null) builder.setParameter("token", token.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (couponCode != null) builder.setParameter("couponCode", couponCode.toString()); if (orderNumber != null) builder.setParameter("orderNumber", orderNumber.toString()); if (totalFrom != null) builder.setParameter("totalFrom", totalFrom.toString()); if (totalTo != null) builder.setParameter("totalTo", totalTo.toString()); if (customer != null) builder.setParameter("customer", customer.toString()); if (createdFrom != null) builder.setParameter("createdFrom", createdFrom.toString()); if (createdTo != null) builder.setParameter("createdTo", createdTo.toString()); if (paymentMethod != null) builder.setParameter("paymentMethod", paymentMethod.toString()); if (vendorNumber != null) builder.setParameter("vendorNumber", vendorNumber.toString()); if (shippingMethod != null) builder.setParameter("shippingMethod", shippingMethod.toString()); if (keywords != null) builder.setParameter("keywords", keywords.toString()); if (fulfillmentStatus != null) builder.setParameter("fulfillmentStatus", fulfillmentStatus.toString()); if (paymentStatus != null) builder.setParameter("paymentStatus", paymentStatus.toString()); if (updatedFrom != null) builder.setParameter("updatedFrom", updatedFrom.toString()); if (updatedTo != null) builder.setParameter("updatedTo", updatedTo.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<OrderSearchResult>(getRequestExecutor(), builder.build()) { @Override public OrderSearchResult execute(RequestExecutor executor) throws IOException, JSONException { HttpGet method = new HttpGet(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new OrderSearchResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> deleteProductGalleryImageApiUploadService(Number storeId, String token, Number id, Number fileId) {/*from w w w. ja v a 2 s . c o m*/ try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/gallery/" + fileId); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (fileId == null) throw new IllegalArgumentException("No parameter fileId is set"); return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) { @Override public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpDelete method = new HttpDelete(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new DeleteStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<Combination> getCombinationProductApiService(Number storeId, String token, Number id, Number combinationId) {//from ww w.j a v a2s .com try { URIBuilder builder = new URIBuilder( url + "/" + storeId + "/products/" + id + "/combinations/" + combinationId); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (combinationId == null) throw new IllegalArgumentException("No parameter combinationId is set"); return new Request<Combination>(getRequestExecutor(), builder.build()) { @Override public Combination execute(RequestExecutor executor) throws IOException, JSONException { HttpGet method = new HttpGet(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new Combination(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> deleteCombinationProductApiService(Number storeId, String token, Number id, Number combinationId) {//ww w . j a v a2 s. com try { URIBuilder builder = new URIBuilder( url + "/" + storeId + "/products/" + id + "/combinations/" + combinationId); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (combinationId == null) throw new IllegalArgumentException("No parameter combinationId is set"); return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) { @Override public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpDelete method = new HttpDelete(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new DeleteStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<UpdateStatus> updateCombinationProductApiService(Number storeId, String token, Number id, Number combinationId, Combination body) { try {// www . j a v a2 s. co m URIBuilder builder = new URIBuilder( url + "/" + storeId + "/products/" + id + "/combinations/" + combinationId); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (combinationId == null) throw new IllegalArgumentException("No parameter combinationId is set"); if (body == null) throw new IllegalArgumentException("No request body"); return new Request<UpdateStatus>(getRequestExecutor(), builder.build(), new StringEntity(body.asJson().toString(), ContentType.APPLICATION_JSON)) { @Override public UpdateStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPut method = new HttpPut(uri); method.setEntity(body); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new UpdateStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> deleteCombinationImageApiUploadService(Number storeId, String token, Number id, Number combinationId) {//from w w w . j a va 2 s .c om try { URIBuilder builder = new URIBuilder( url + "/" + storeId + "/products/" + id + "/combinations/" + combinationId + "/image"); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (combinationId == null) throw new IllegalArgumentException("No parameter combinationId is set"); return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) { @Override public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpDelete method = new HttpDelete(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new DeleteStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<UploadStatus> uploadCombinationImageApiUploadService(Number storeId, String token, Number id, Number combinationId, InputStream body) { try {//from w ww.j a v a 2 s .com URIBuilder builder = new URIBuilder( url + "/" + storeId + "/products/" + id + "/combinations/" + combinationId + "/image"); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (combinationId == null) throw new IllegalArgumentException("No parameter combinationId is set"); if (body == null) throw new IllegalArgumentException("No request body"); return new Request<UploadStatus>(getRequestExecutor(), builder.build(), createInputStreamEntity(body)) { @Override public UploadStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(uri); method.setEntity(body); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new UploadStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<UploadStatus> uploadOrderItemOptionFileApiUploadService(Number storeId, String token, Number orderNumber, Number itemId, String optionName, String fileName, InputStream body) { try {/*from ww w. j a v a 2 s .c om*/ URIBuilder builder = new URIBuilder( url + "/" + storeId + "/orders/" + orderNumber + "/items/" + itemId + "/options/" + optionName); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (orderNumber == null) throw new IllegalArgumentException("No parameter orderNumber is set"); if (itemId == null) throw new IllegalArgumentException("No parameter itemId is set"); if (optionName == null) throw new IllegalArgumentException("No parameter optionName is set"); if (fileName == null) throw new IllegalArgumentException("No parameter fileName is set"); builder.setParameter("fileName", fileName.toString()); if (body == null) throw new IllegalArgumentException("No request body"); return new Request<UploadStatus>(getRequestExecutor(), builder.build(), createInputStreamEntity(body)) { @Override public UploadStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(uri); method.setEntity(body); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new UploadStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> clearOrderItemOptionFilesApiUploadService(Number storeId, String token, Number orderNumber, Number itemId, String optionName) { try {/* w w w. j a va 2s .co m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders/" + orderNumber + "/items/" + itemId + "/options/" + optionName + "/files"); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (orderNumber == null) throw new IllegalArgumentException("No parameter orderNumber is set"); if (itemId == null) throw new IllegalArgumentException("No parameter itemId is set"); if (optionName == null) throw new IllegalArgumentException("No parameter optionName is set"); return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) { @Override public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpDelete method = new HttpDelete(uri); try { HttpResponse response = executor.execute(method); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("Unexpected HTTP status: " + response.getStatusLine()); } HttpEntity entity = response.getEntity(); if (entity == null) throw new JSONException("No response. Expected JSON object."); return new DeleteStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }