Android Open Source - Android-Print-SDK Submit Print Order Request






From Project

Back to project page Android-Print-SDK.

License

The source code is released under:

MIT License

If you think the Android project Android-Print-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ly.kite.print;
//from w w  w  .ja v  a  2 s .c  om
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by deonbotha on 09/02/2014.
 */
class SubmitPrintOrderRequest {
    private final PrintOrder printOrder;
    private BaseRequest req;

    public SubmitPrintOrderRequest(PrintOrder printOrder) {
        this.printOrder = printOrder;
    }

    public void submitForPrinting(final SubmitPrintOrderRequestListener listener) {
        assert req == null : "you can only submit a request once";

        JSONObject json = printOrder.getJSONRepresentation();
        String url = String.format("%s/v1/print", KitePrintSDK.getEnvironment().getPrintAPIEndpoint());
        req = new BaseRequest(BaseRequest.HttpMethod.POST, url, null, json.toString());
        req.start(new BaseRequest.BaseRequestListener() {
            @Override
            public void onSuccess(int httpStatusCode, JSONObject json) {
                try {
                    if (httpStatusCode >= 200 && httpStatusCode <= 299) {
                        String orderId = json.getString("print_order_id");
                        listener.onSubmissionComplete(SubmitPrintOrderRequest.this, orderId);
                    } else {
                        JSONObject error = json.getJSONObject("error");
                        String message = error.getString("message");
                        String errorCode = error.getString("code");
                        if (errorCode.equalsIgnoreCase("20")) {
                            // this error code indicates an original success response for the request. It's handy to report a success in this
                            // case as it may be that the client never received the original success response.
                            String orderId = json.getString("print_order_id");
                            listener.onSubmissionComplete(SubmitPrintOrderRequest.this, orderId);
                        } else {
                            listener.onError(SubmitPrintOrderRequest.this, new KitePrintSDKException(message));
                        }
                    }
                } catch (JSONException ex) {
                    listener.onError(SubmitPrintOrderRequest.this, ex);
                }
            }

            @Override
            public void onError(Exception ex) {
                listener.onError(SubmitPrintOrderRequest.this, ex);
            }
        });
    }

    public void cancelSubmissionForPrinting() {
        if (req != null) {
            req.cancel();
            req = null;
        }
    }

}




Java Source Code List

co.oceanlabs.sample.MainActivity.java
ly.kite.address.AddressBookActivity.java
ly.kite.address.AddressEditActivity.java
ly.kite.address.AddressSearchActivity.java
ly.kite.address.AddressSearchRequestListener.java
ly.kite.address.AddressSearchRequest.java
ly.kite.address.Address.java
ly.kite.address.Country.java
ly.kite.checkout.CheckoutActivity.java
ly.kite.checkout.OrderReceiptActivity.java
ly.kite.checkout.PaymentActivity.java
ly.kite.checkout.PrintOrderSummaryListAdapter.java
ly.kite.payment.CheckPromoCodeRequestListener.java
ly.kite.payment.CheckPromoRequest.java
ly.kite.payment.PayPalCardChargeListener.java
ly.kite.payment.PayPalCardVaultStorageListener.java
ly.kite.payment.PayPalCard.java
ly.kite.print.ApplyPromoCodeListener.java
ly.kite.print.AssetGetBytesLengthListener.java
ly.kite.print.AssetGetBytesListener.java
ly.kite.print.AssetUploadRequestListener.java
ly.kite.print.AssetUploadRequest.java
ly.kite.print.Asset.java
ly.kite.print.BaseRequest.java
ly.kite.print.KitePrintSDKException.java
ly.kite.print.KitePrintSDK.java
ly.kite.print.PrintJob.java
ly.kite.print.PrintOrderSubmissionListener.java
ly.kite.print.PrintOrder.java
ly.kite.print.PrintsPrintJob.java
ly.kite.print.ProductType.java
ly.kite.print.SubmitPrintOrderRequestListener.java
ly.kite.print.SubmitPrintOrderRequest.java