Services:DataService
From MacroDeckDevWiki
DataService provides data abstraction on top of ActiveRecord from Rails. Services are extremely encouraged to use our API for data storage and access rather than accessing DataItem and DataGroup (the models currently used by DataService) directly. DataService will also be able to handle remote sources in the future (so, a user can say they'd like to integrate a remote calendar with their local calendar and the data is transparent to upper layers other than being read only).
Contents |
Concepts
Data is broken down into two parts: data items and data groups.
Data Items
Data items are line-item pieces of data with a defined type, owner, creator, value, title, tags, permissions, and description. They can be integers (numbers), strings (actually, it's stored as TEXT in the database), and objects (i.e. Ruby hashes). You can store arrays as objects as well. Ideally, you'll store one piece of data per data item, but in some instances it may make sense to store extra data/metadata without using more than one data item. For example, a comment to a blog entry might have extra metadata (i.e. their nickname if they aren't logged in). Keep in mind, though, that you can store an integer, string, and object in a single data item. So, you could put the comment text in the string data, and create a Ruby hash with the user's information (i.e. nickname, email, url, etc.) and store it in the object field. You also do not need to do any conversion; pass the object, and we'll handle the rest.
Data Groups
The other part of data is data groups or data groupings. Basically, these are sets of data. Each data item should belong to a data grouping. Groupings are simple to work with and understand. For example, a user or group's blog is an example of a grouping: a grouping of blog entries. Each blog post is its own grouping as well: a grouping of comments. The same would apply for calendars and events (events are grouped into a calendar), contacts and address books (contacts are grouped into address books), and so on. Groupings which are branched off of data items (i.e. a blog entry's comments) should have the parent field set to the data item's ID.
Additionally, data groups may contain more than one type of data.
Future
Currently, in Services 0.1, the API is kind of wishy-washy. This will be improved in Services 0.2 and made clean. Don't depend on DataService's API being stable in this release!

