Search in sources :

Example 1 with SparkException

use of com.ciscospark.SparkException in project openhab1-addons by openhab.

the class CiscoSparkActionService method start.

private void start() {
    if (!isProperlyConfigured) {
        return;
    }
    try {
        logger.debug("Creating Cisco Spark client...");
        CiscoSpark.spark = createSpark();
        logger.debug("Retrieving user...");
        Person person = CiscoSpark.spark.people().path("/me").get();
        logger.info("Cisco Spark logged in as {}", person.getDisplayName());
    } catch (SparkException se) {
        logger.warn("Failed to initialized Cisco Spark", se);
    } catch (Exception e) {
        logger.warn("Failed to initialized Cisco Spark!", e);
    }
    logger.info("Cisco Spark has been successfully started");
}
Also used : SparkException(com.ciscospark.SparkException) Person(com.ciscospark.Person) SparkException(com.ciscospark.SparkException) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 2 with SparkException

use of com.ciscospark.SparkException in project openhab1-addons by openhab.

the class CiscoSpark method sparkMessage.

/**
     * Sends a Message via Cisco Spark
     *
     * @param msgTxt the Message to send
     * @param roomId the Room to which to send
     *
     * @return <code>true</code>, if sending the message has been successful and
     *         <code>false</code> in all other cases.
     */
@ActionDoc(text = "Sends a Message via Cisco Spark", returns = "<code>true</code>, if sending the tweet has been successful and <code>false</code> in all other cases.")
public static boolean sparkMessage(@ParamDoc(name = "msgTxt", text = "the Message to send") String msgTxt, @ParamDoc(name = "roomId", text = "the Room to which to send") String roomId) {
    if (!CiscoSparkActionService.isProperlyConfigured) {
        logger.debug("Cisco Spark is not yet configured > execution aborted!");
        return false;
    }
    // Validate message
    if (msgTxt == null || "".equals(msgTxt)) {
        logger.warn("Message can't be empty");
        return false;
    }
    // Validate room id
    try {
        UUID.fromString(roomId);
    } catch (IllegalArgumentException e) {
        logger.warn("Room id is not a UUID");
        return false;
    }
    try {
        logger.debug("Creating message");
        // Create the message
        Message msg = new Message();
        msg.setRoomId(roomId);
        msg.setMarkdown(msgTxt);
        logger.debug("About to send message");
        // send the Message
        spark.messages().post(msg);
        logger.debug("Successfully sent Message '{}'", msg.getMarkdown());
        return true;
    } catch (SparkException se) {
        logger.warn("Failed to send message.", se);
        return false;
    } catch (Exception e) {
        logger.warn("Failed to send message!", e);
        return false;
    }
}
Also used : Message(com.ciscospark.Message) SparkException(com.ciscospark.SparkException) AddressException(javax.mail.internet.AddressException) SparkException(com.ciscospark.SparkException) ActionDoc(org.openhab.core.scriptengine.action.ActionDoc)

Example 3 with SparkException

use of com.ciscospark.SparkException in project openhab1-addons by openhab.

the class CiscoSpark method sparkPerson.

/**
     * Sends a Message to a Person via Cisco Spark
     *
     * @param msgTxt the Message to send
     * @param personEmail the email of the person to which to send
     *
     * @return <code>true</code>, if sending the message has been successful and
     *         <code>false</code> in all other cases.
     */
@ActionDoc(text = "Sends a Message via Cisco Spark", returns = "<code>true</code>, if sending the tweet has been successful and <code>false</code> in all other cases.")
public static boolean sparkPerson(@ParamDoc(name = "msgTxt", text = "the Message to send") String msgTxt, @ParamDoc(name = "personEmail", text = "the email of the person to which to send") String personEmail) {
    if (!CiscoSparkActionService.isProperlyConfigured) {
        logger.warn("Cisco Spark is not yet configured > execution aborted!");
        return false;
    }
    // Validate message
    if (msgTxt == null || "".equals(msgTxt)) {
        logger.warn("Message can't be empty");
        return false;
    }
    // Validate email
    try {
        InternetAddress email = new InternetAddress(personEmail);
        email.validate();
    } catch (AddressException e) {
        logger.warn("Email address is not valid");
        return false;
    }
    try {
        logger.debug("Creating message");
        // Create the message
        Message msg = new Message();
        msg.setToPersonEmail(personEmail);
        msg.setMarkdown(msgTxt);
        logger.debug("About to send message");
        // send the Message
        spark.messages().post(msg);
        logger.debug("Successfully sent Message '{}'", msg.getMarkdown());
        return true;
    } catch (SparkException se) {
        logger.warn("Failed to send message.", se);
        return false;
    } catch (Exception e) {
        logger.warn("Failed to send message!", e);
        return false;
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Message(com.ciscospark.Message) SparkException(com.ciscospark.SparkException) AddressException(javax.mail.internet.AddressException) AddressException(javax.mail.internet.AddressException) SparkException(com.ciscospark.SparkException) ActionDoc(org.openhab.core.scriptengine.action.ActionDoc)

Aggregations

SparkException (com.ciscospark.SparkException)3 Message (com.ciscospark.Message)2 AddressException (javax.mail.internet.AddressException)2 ActionDoc (org.openhab.core.scriptengine.action.ActionDoc)2 Person (com.ciscospark.Person)1 InternetAddress (javax.mail.internet.InternetAddress)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1