I'm using Java DDPClient (https://github.com/kutrumbo/java-ddp-client) and I am trying to insert data into a meteor application.
I do this from java:
DdpClient client;
try {
client = new DdpClient("localhost", 3000);
client.addObserver(this);
client.connect();
Object[] objArray = new Object[1];
objArray[0] = new String("{name:'peter andersson', phone:'12345678'}");
client.call("createNewCustomer", objArray);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (Exception ex) {
System.out.println("Exception:" + ex.getLocalizedMessage());
}
and this in Meteor (collection Customers)
Meteor.methods({
"createNewCustomer" : function(options) {
var ret = {};
options.replace(/(\b[^:]+):'([^']+)'/g, function ($0, param, value) {
ret[param] = value;
});
Customers.insert(ret);
}
});
It works, however it seems like unnecessary work to code it into a string and then decode it to a javascript hashmap.
I have tried creating an array of Objects (Strings) but no matter how I do it it doesnt work as expected.
What's the "proper" way of doing it?
EDIT:
My wish is that the Meteor code would look like this:
Meteor.methods({
"createNewCustomer" : function(options) {
Customers.insert(options);
}
});
I guess what I want to know is how to send from Java (using Java DDP Client) so that no decoding is necessary in Meteor.