delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

ValidatedMethod and mMeteor.call #80

Closed romaluca closed 8 years ago

romaluca commented 8 years ago

Hi! I'm try to follow the new guide of Meteor 1.3 for my project. So i saw that in their example they use ValidateMethod for define methods like in this file: https://github.com/meteor/todos/blob/master/imports/api/lists/methods.js

the problem is that if i use the validate:

validate: new SimpleSchema({
    listId: { type: String },
    newName: { type: String },
  }).validator(),

and if in android i use your method:

mMeteor.call("myMethod", new Object[] { listId, newName });

i receive an error:

The first argument of validate() or validateOne() must be an object.

How can i do?

Thanks!

ocram commented 8 years ago

Thanks for your feedback!

The error message says that the first argument must be an object but judging from your code new Object[] { listId, newName }, your first argument is either a string or an integer, depending on what the exact type of listId is.

An object in JavaScript would be a Map in Java.

Does this help?

romaluca commented 8 years ago

Hi, I tried like you said. And it works! But doesn' t work with dates. I have getstartat that returns a Date:

Map<String, Object> contestMap = new HashMap<>();
contestMap.put("name", c.getName());
contestMap.put("startAt", c.getStartAt());
...
meteor.call("contests.update",  new Object[] { contestMap }, new ResultListener() {

Where getStartAt returns a date. In meteor i receive this:

{ name: 'Sdfsdd',
  startAt: 1459442641702,
...
}

And in android i receive the error:

validation-error Start at must be a Date

Is a my problem or is a bug library?

Thanks for your help!

ocram commented 8 years ago

@romaluca Great to hear that it works :)

Let's discuss the date issue in a separate issue: https://github.com/delight-im/Android-DDP/issues/82

I've already added an explanation there that might help you.