The HW Blog

Want to be updated? @opencoconut | Feed

Introducing a Java library

Bruno Celeste (@brunoceleste)

November 22, 2013 Features

Today, we are happy to announce the release of a Java library to integrate Coconut in your Java application in a snap.

We published the artifact on maven central so it's very straightforward to install and use it. Simply edit the pom.xml file and add the following:

<dependencies>
  <dependency>
    <groupId>com.coconut</groupId>
    <artifactId>coconut</artifactId>
    <version>0.1.0</version>
  </dependency>
</dependencies>

Now run mvn clean install in your favorite terminal. That's it, everything is installed and you are ready to go.

As always, the client is very simple and follows the same rules than other libraries we provide.

import com.coconut.api.CoconutClient;
import com.coconut.api.CoconutException;
import com.coconut.api.CoconutObject;
import com.coconut.api.CoconutParameters;

public class App {

        public static void main(String[] args) throws CoconutException {
                CoconutClient hw = new CoconutClient("k-apikey");
                CoconutObject account = hw.account();
                System.out.println("account: " + account.get("login"));

                // Transferring a video
                CoconutParameters params = new CoconutParameters();
                params.put("url", "http://test.com/test.mp4");
                params.put("title", "abc1234");
                params.put("ping_url", "http://mysite.com/ping/coconut?postid=abc1234");

                CoconutObject download = hw.create("download", params);
                System.out.println(download);

                // Creating a job
                params = new CoconutParameters();
                params.put("video_id", "ID");
                params.put("format_id", "ios_720p");
                params.put("ping_url", "http://mysite.com/ping/coconut?postid=abc1234");
                params.put("output_url", "s3://accesskey:secretkey@bucket/video/abc2134.mp4");

                CoconutObject job = hw.create("job", params);
                System.out.println(job);

                // Creating a Robot Job
                CoconutObject robotJob = hw.createRobotJob("path/to/coconut.ini");
                System.out.println(robotJob);

                // Generating thumbnails
                params = new CoconutParameters();
                params.put("video_id", "ID");
                params.put("number", "6");
                params.put("filename", "abc1234_#num#");
                params.put("ping_url", "http://mysite.com/ping/coconut?postid=abc1234");
                params.put("output_url", "s3://accesskey:secretkey@bucket/thumbnails");

                hw.create("preview/thumbnails", params);
        }

}

You can improve the library by forking it on Github.



Any Comment? Send us a message on Twitter @opencoconut
If you have questions or feedbacks, you can also contact us via our contact page