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<DiscountCoupon> getDiscountCouponService(Number storeId, String code, String token) { try {// w w w. j a v a 2 s .com URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons/" + code); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (code == null) throw new IllegalArgumentException("No parameter code is set"); return new Request<DiscountCoupon>(getRequestExecutor(), builder.build()) { @Override public DiscountCoupon 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 DiscountCoupon(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> deleteDiscountCouponService(Number storeId, String code, String token) { try {/* www . j a va 2 s . c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons/" + code); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (code == null) throw new IllegalArgumentException("No parameter code 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<DeleteStatus> deleteProductImageApiUploadService(Number storeId, String token, Number id) { try {//from w ww .j a va 2 s . com URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/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"); 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<DeleteStatus> clearProductFilesApiUploadService(Number storeId, String token, Number id) { try {//from w w w. jav a2 s . co m URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/files"); 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"); 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> updateProductApiService(Number storeId, Number productId, String token, Product body) {/*from w w w.j a v a 2 s. c o m*/ try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + productId); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (productId == null) throw new IllegalArgumentException("No parameter productId 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<UpdateStatus> updateOrderOrderApiService(Number storeId, Number orderNumber, String token, Order body) {//from w w w. j a v a2s . c o m try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders/" + orderNumber); 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 (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<CustomerSearchResult> searchCustomerApiService(Number storeId, String keyword, String name, String email, Number minOrderCount, Number maxOrderCount, String sortBy, Number offset, Number limit, String token) {/*w w w.ja va 2 s.c o m*/ try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/customers"); if (keyword != null) builder.setParameter("keyword", keyword.toString()); if (name != null) builder.setParameter("name", name.toString()); if (email != null) builder.setParameter("email", email.toString()); if (minOrderCount != null) builder.setParameter("minOrderCount", minOrderCount.toString()); if (maxOrderCount != null) builder.setParameter("maxOrderCount", maxOrderCount.toString()); if (sortBy != null) builder.setParameter("sortBy", sortBy.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<CustomerSearchResult>(getRequestExecutor(), builder.build()) { @Override public CustomerSearchResult 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 CustomerSearchResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> clearProductGalleryApiUploadService(Number storeId, String token, Number id) { try {/*from w w w .j a v a 2 s . c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/gallery"); 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"); 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<DeleteStatus> deleteCategoryImageApiUploadService(Number storeId, String token, Number id) { try {// w w w . j a v a 2s . c o m URIBuilder builder = new URIBuilder(url + "/" + storeId + "/categories/" + id + "/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"); 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> updateDiscountCouponService(Number storeId, String code, String token, DiscountCoupon body) {/*from ww w . ja v a2s . c o m*/ try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons/" + code); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (code == null) throw new IllegalArgumentException("No parameter code 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); } }