Hey Everybody! LTLFTC
I'm working through an implementation using MASON2 at the moment to develop a uniform interface, I'm making good progress and am playing with some of the minutia and am looking to sanity check some thinking I have.
I will use the 'notification' payload to demonstrate the question I presently have. I am building, shock horror, a social style app and there are many different types of notifications that a user may receive. Here is a snip of a notification payload:
....
"id": "n001",
"dateCreated": "2014-12-17T20:09:53Z",
"dateViewed": null,
"dateFollowed": null,
"message": {
"id": "m001",
"sender": "Tom Habiford",
"title": "Gurgs!",
"digest": "Hey gurgich, you are not very bright!",
"dateSent": "2014-12-17T20:09:53Z",
"@controls": {
"is:follow": {
"type": "link",
"rel": "follow",
"href": "http://.../messages/m001",
"method": "GET",
"title": "link to this message record"
},
"is:image": {
"type": "image/png",
"rel": "image",
"href": "http://.../messages/m001/thumb",
"method": "GET",
"title": "link to thumbnail associated with this message"
}
}
}
.....
Now in this case the notification relates to a new message that the user has received, other alternative notifications can be for an upcoming event that the user follows, a user following this user or a request to enter into a contract has been received....
In my first naive implementation I have just used the "message" object inside the root of the message.
In an earlier attempt I had created a substructure to hold the details of what the notification was about, including a field that stated the type of notification. I'm thinking this is probably the best way to go, that way the client just needs to look at whatever is inside that substructure and not know what to look for in the root.
So this leads me to think that perhaps this is the best solution (change in red):
"id": "n001",
"dateCreated": "2014-12-17T20:09:53Z",
"dateViewed": null,
"dateFollowed": null,
"source": {
"message": {
"id": "m001",
"sender": "Tom Habiford",
"title": "Gurgs!",
"digest": "Hey gurgich, you are not very bright!",
"dateSent": "2014-12-17T20:09:53Z",
"@controls": {
"is:follow": {
"type": "link",
"rel": "follow",
"href": "http://.../messages/m001",
"method": "GET",
"title": "link to message record"
},
"is:image": {
"type": "image/png",
"href": "http://.../messages/m001/thumb",
"method": "GET",
"title": "link to thumbnail for account associated with message"
}
}
}
}
I think I'll use a different semantic descriptor than 'source' but you get the idea. To me this makes sense, anytime you get a notification (notifications can make one and only one notification) all you need to do is look inside the source object and you have everything you need to know.
So I guess I am just sanity checking here, my question is is there any reason NOT to nest the target of the notification i.e.: is there a reason why it would be better in the root, I cannot think of any.
Any input is welcome.
Thanks folks.
B