JPachube - pachube thru Java in max

ygreq's icon

Hi everyone,

I don't have a clue about java, generally. But I found this tutorial about using JPachube . http://code.google.com/p/jpachube/wiki/BasicJPachubeTutorial

Do you know how I can put this into max?

Anyone willing to give a hand?

Guillaume Evrard's icon

hi,

i've just give a try, it works... here is a simple java class that allows you to get some data from pachube.

g

import Pachube.Feed;
import Pachube.Pachube;
import com.cycling74.max.MaxObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
*
* @author ge
*/
public class DataStream extends MaxObject {

private String StreamID = "";
private int dsid = 0;
Pachube p;
Feed f;

public DataStream(String id, int dsid) {
this.StreamID = id;
this.dsid = dsid;
p = new Pachube("your_api_key");
f = new Feed(p);
f.setId(id);
}

public void bang() {
String s = new String(p.getDatastream(f.getId(), this.dsid).getBody().getBytes());
outlet(0, s);

}

public void setFeedId(String s) {
this.StreamID = s;
this.f.setId(s);
}

public void setDataStreamId(int i) {
this.dsid = i;
}

public void getFeeds() {

try {
URL feedsurl = new URL("http://api.pachube.com/v2/feeds.xml?key=your_api_key");
URLConnection yc = feedsurl.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null) {
outlet(0, inputLine.toString());
}
in.close();
} catch (Exception e) {
}

}
}

ygreq's icon

Hey Guillaume!

I just read your message. I had a solution to help me update info on pachube, but that doesn't seem to work that well.

Can you please tell me how I can integrate what you posted? And maybe change it so it updates a feed instead of reading it?

Thank you so much,
ygreq