Search code examples
clojureplivo

How to call this java library in clojure


I'm trying to translate this java code into clojure:

package com.plivo.api.samples.message;

import java.io.IOException;
import java.util.Collections;

import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.message.Message;
import com.plivo.api.models.message.MessageCreateResponse;

/**
* Example for Message create
*/
class MessageCreate {
    public static void main(String [] args) {
        Plivo.init();
        try {
            MessageCreateResponse response = Message.creator("14153336666", Collections.singletonList("14156667777"), "Test Message")
                .create();

            System.out.println(response);
        } catch (PlivoRestException | IOException e) {
            e.printStackTrace();
        }
    }
}

I don't even care about the error checking, I can't figure out how to get my code to run this line:

Message.creator("14153336666", Collections.singletonList("14156667777"), "Test Message")
                    .create();

I've imported the correct dependencies into my project.clj, I just don't know ho to do the java interop in a way where creator is recognized. Any help would be appreciated.


Solution

  • You should post any Clojure code you've written to try to solve the problem, but the calling convention is probably something like this:

    (let [creator (Message/creator "14153336666"
                                   (Collections/singletonList "14156667777")
                                   "Test Message")]
      (.create creator))