Search in sources :

Example 1 with ConnectionRequest

use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.

the class Message method sendMessageViaCloudSync.

/**
 * <p>Send an email message using the Codename One cloud to send the message, notice that this API
 * will only work for pro accounts.</p>
 * <script src="https://gist.github.com/codenameone/8229c1d4627ab3a1f17e.js"></script>
 *
 * @param sender the name of the sender, notice all email will arrive from Codename One to avoid spam issues
 * @param recipient the email for the recipient
 * @param recipientName the display name for the recipient
 * @param subject e-mail subject
 * @param plainTextBody when sending an HTML message you should also attach a plain text fallback message,
 * this is redundant if the email is a plain text message to begin with
 * @return true if sending succeeded
 */
public boolean sendMessageViaCloudSync(String sender, String recipient, String recipientName, String subject, String plainTextBody) {
    ConnectionRequest r = createMessage(sender, recipient, recipientName, subject, plainTextBody);
    r.setFailSilently(true);
    NetworkManager.getInstance().addToQueueAndWait(r);
    return r.getResposeCode() == 200;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 2 with ConnectionRequest

use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.

the class Push method createPushMessage.

private static ConnectionRequest createPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort) {
    ConnectionRequest cr = new ConnectionRequest();
    cr.setPost(true);
    cr.setUrl(Display.getInstance().getProperty("cloudServerURL", "https://codename-one.appspot.com/") + "sendPushMessage");
    cr.addArgument("packageName", Display.getInstance().getProperty("package_name", ""));
    cr.addArgument("email", Display.getInstance().getProperty("built_by_user", ""));
    if (deviceKey != null) {
        cr.addArgument("device", deviceKey);
    }
    cr.addArgument("type", "1");
    cr.addArgument("auth", googleAuthKey);
    cr.addArgument("certPassword", iosCertificatePassword);
    cr.addArgument("cert", iosCertificateURL);
    cr.addArgument("body", body);
    cr.addArgument("burl", bbUrl);
    cr.addArgument("bbAppId", bbApp);
    cr.addArgument("bbPass", bbPass);
    cr.addArgument("bbPort", bbPort);
    if (production) {
        cr.addArgument("production", "true");
    } else {
        cr.addArgument("production", "false");
    }
    cr.setFailSilently(true);
    return cr;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 3 with ConnectionRequest

use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.

the class VServAds method createAdRequest.

/**
 * {@inheritDoc}
 */
protected ConnectionRequest createAdRequest() {
    ConnectionRequest con = new ConnectionRequest() {

        protected void handleErrorResponseCode(int code, String message) {
            failed = true;
        }

        protected void handleException(Exception err) {
            failed = true;
            Log.e(err);
        }

        private String getString(Hashtable h, String n) {
            Object v = h.get(n);
            if (v == null) {
                return null;
            }
            if (v instanceof Vector) {
                return (String) ((Vector) v).elementAt(0);
            }
            return (String) v;
        }

        protected void readResponse(InputStream input) throws IOException {
            JSONParser parser = new JSONParser();
            Hashtable h = parser.parse(new InputStreamReader(input, "UTF-8"));
            if (h.size() == 0) {
                return;
            }
            backgroundColor = Integer.parseInt((String) ((Hashtable) ((Vector) h.get("style")).elementAt(0)).get("background-color"), 16);
            Hashtable actionHash = ((Hashtable) ((Vector) h.get("action")).elementAt(0));
            actionNotify = getString(actionHash, "notify");
            if (actionNotify == null) {
                actionNotify = getString(actionHash, "notify-once");
            }
            destination = (String) actionHash.get("data");
            Hashtable renderHash = ((Hashtable) ((Vector) h.get("render")).elementAt(0));
            contentType = (String) renderHash.get("type");
            renderNotify = getString(renderHash, "notify");
            if (renderNotify == null) {
                renderNotify = getString(renderHash, "notify-once");
            }
            imageURL = (String) renderHash.get("data");
        }
    };
    con.setUrl(URL);
    con.setPost(false);
    con.addArgument("zoneid", getZoneId());
    con.addArgument("ua", Display.getInstance().getProperty("User-Agent", ""));
    con.addArgument("app", "1");
    con.addArgument("aid", Display.getInstance().getProperty("androidId", ""));
    con.addArgument("uuid", Display.getInstance().getProperty("uuid", ""));
    con.addArgument("im", Display.getInstance().getProperty("imei", ""));
    con.addArgument("sw", "" + Display.getInstance().getDisplayWidth());
    con.addArgument("sh", "" + Display.getInstance().getDisplayHeight());
    con.addArgument("mn", Display.getInstance().getProperty("AppName", ""));
    con.addArgument("vs3", "1");
    con.addArgument("partnerid", "1");
    con.addArgument("zc", "" + category);
    if (countryCode != null) {
        con.addArgument("cc", countryCode);
    }
    if (networkCode != null) {
        con.addArgument("nc", networkCode);
    }
    if (locale != null) {
        con.addArgument("lc", locale);
    }
    return con;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) InputStreamReader(java.io.InputStreamReader) Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) JSONParser(com.codename1.io.JSONParser) Vector(java.util.Vector) IOException(java.io.IOException)

Example 4 with ConnectionRequest

use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.

the class VServAds method getAdDestination.

/**
 * {@inheritDoc}
 */
protected String getAdDestination() {
    if (actionNotify != null && actionNotify.length() > 0) {
        ConnectionRequest c = new ConnectionRequest();
        c.setFailSilently(true);
        c.setUrl(actionNotify);
        c.setPost(false);
        NetworkManager.getInstance().addToQueue(c);
    }
    return destination;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 5 with ConnectionRequest

use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.

the class RequestBuilder method createRequest.

private ConnectionRequest createRequest(boolean parseJson) {
    ConnectionRequest req = new Connection(parseJson);
    for (String key : pathParams.keySet()) {
        url = com.codename1.util.StringUtil.replaceAll(url, "{" + key + "}", pathParams.get(key));
    }
    if (contentType != null) {
        req.setContentType(contentType);
    }
    req.setReadResponseForErrors(true);
    req.setDuplicateSupported(true);
    req.setUrl(url);
    req.setHttpMethod(method);
    req.setPost(method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT") || method.equalsIgnoreCase("PATCH"));
    if (body != null) {
        req.setRequestBody(body);
        req.setWriteRequest(true);
    }
    if (timeout != null) {
        req.setTimeout(timeout);
    }
    for (String key : queryParams.keySet()) {
        req.addArgument(key, queryParams.get(key));
    }
    for (String key : headers.keySet()) {
        req.addRequestHeader(key, headers.get(key));
    }
    return req;
}
Also used : GZConnectionRequest(com.codename1.io.gzip.GZConnectionRequest) ConnectionRequest(com.codename1.io.ConnectionRequest)

Aggregations

ConnectionRequest (com.codename1.io.ConnectionRequest)41 IOException (java.io.IOException)11 GZConnectionRequest (com.codename1.io.gzip.GZConnectionRequest)7 InputStream (java.io.InputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Map (java.util.Map)6 JSONParser (com.codename1.io.JSONParser)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 InputStreamReader (java.io.InputStreamReader)5 InfiniteProgress (com.codename1.components.InfiniteProgress)4 NetworkEvent (com.codename1.io.NetworkEvent)4 Dialog (com.codename1.ui.Dialog)4 Form (com.codename1.ui.Form)4 ActionListener (com.codename1.ui.events.ActionListener)3 DataInputStream (java.io.DataInputStream)3 Hashtable (java.util.Hashtable)3 Component (com.codename1.ui.Component)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Vector (java.util.Vector)2