Search in sources :

Example 26 with Form

use of com.sun.jersey.api.representation.Form in project pwinty-java-sdk by OddPrints.

the class Pwinty method createOrderForm.

private Form createOrderForm(Order newOrder, Boolean useTrackedShipping) {
    Form form = new Form();
    form.add("recipientName", newOrder.getRecipientName());
    form.add("address1", newOrder.getAddress1());
    form.add("address2", newOrder.getAddress2());
    form.add("addressTownOrCity", newOrder.getAddressTownOrCity());
    form.add("stateOrCounty", newOrder.getStateOrCounty());
    form.add("postalOrZipCode", newOrder.getPostalOrZipCode());
    form.add("countryCode", newOrder.getCountryCode());
    form.add("destinationCountryCode", newOrder.getDestinationCountryCode());
    if (useTrackedShipping != null) {
        form.add("useTrackedShipping", useTrackedShipping);
    }
    form.add("payment", newOrder.getPayment());
    form.add("qualityLevel", newOrder.getQualityLevel());
    return form;
}
Also used : Form(com.sun.jersey.api.representation.Form)

Example 27 with Form

use of com.sun.jersey.api.representation.Form in project pwinty-java-sdk by OddPrints.

the class Pwinty method createOrder.

Order createOrder(Order newOrder, boolean useTrackedShipping) {
    Form form = createOrderForm(newOrder, useTrackedShipping);
    ClientResponse response = webResource.path("Orders").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).header("X-Pwinty-MerchantId", merchantId).header("X-Pwinty-REST-API-Key", apiKey).post(ClientResponse.class, form);
    Order createdOrder = createReponse(response, Order.class);
    createdOrder.setPwinty(this);
    for (Photo photo : newOrder.getPhotos()) {
        createdOrder.addPhoto(photo.getUrl(), photo.getType(), photo.getCopies(), photo.getSizing());
    }
    return createdOrder;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Form(com.sun.jersey.api.representation.Form)

Example 28 with Form

use of com.sun.jersey.api.representation.Form in project pwinty-java-sdk by OddPrints.

the class Pwinty method deletePhoto.

void deletePhoto(int orderId, int photoId) {
    Form form = new Form();
    ClientResponse response = webResource.path("Orders/" + orderId + "/Photos/" + photoId).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).header("X-Pwinty-MerchantId", merchantId).header("X-Pwinty-REST-API-Key", apiKey).delete(ClientResponse.class, form);
    throwIfBad(response);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Form(com.sun.jersey.api.representation.Form)

Example 29 with Form

use of com.sun.jersey.api.representation.Form in project pwinty-java-sdk by OddPrints.

the class Pwinty method addIssueToOrder.

Issue addIssueToOrder(int orderId, Issue issue) {
    Form form = new Form();
    form.add("issue", issue.getIssue().toString());
    form.add("action", issue.getAction().toString());
    if (issue.getIssueDetail() != null) {
        form.add("issueDetail", issue.getIssueDetail());
    }
    if (issue.getActionDetail() != null) {
        form.add("actionDetail", issue.getActionDetail());
    }
    ClientResponse response = webResource.path("Orders/" + orderId + "/Issues").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).header("X-Pwinty-MerchantId", merchantId).header("X-Pwinty-REST-API-Key", apiKey).post(ClientResponse.class, form);
    throwIfBad(response);
    return createReponse(response, Issue.class);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Form(com.sun.jersey.api.representation.Form)

Aggregations

Form (com.sun.jersey.api.representation.Form)29 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)16 Test (org.testng.annotations.Test)13 JSONObject (org.json.JSONObject)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 JSONEntitlement (com.sun.identity.entitlement.JSONEntitlement)4 EntitlementListener (com.sun.identity.entitlement.EntitlementListener)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 MalformedURLException (java.net.MalformedURLException)3 EncodingException (org.owasp.esapi.errors.EncodingException)3 Privilege (com.sun.identity.entitlement.Privilege)2 WebResource (com.sun.jersey.api.client.WebResource)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 JSONArray (org.json.JSONArray)2 DelegationPrivilege (com.sun.identity.delegation.DelegationPrivilege)1 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 NumericAttributeCondition (com.sun.identity.entitlement.NumericAttributeCondition)1 Client (com.sun.jersey.api.client.Client)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1