views:

304

answers:

2

So, I am using Google Contacts API to let users import their contacts from GMail.

I want the users to be able to select the contacts they want to import in my app, So currently I -

  1. GET a XML feed of all the contacts a user has.
  2. Parse it, and for each contact create a record in the imported_contacts table.
  3. Display the list to the user, with checkboxes, so the user can select which contacts it wants to import.
  4. When the user submits the form, I copy the selected contacts from imported_contacts to the main contacts table.

This works fine, but doesn't feel right. Can someone suggest a way to do so, without using a separate table(imported_contacts).

+3  A: 

Map the contacts from XML to objects in memory. Only save them to the main contacts table after the user has selected the ones she wants.

miller
But I am confused about what the view code in such a situation would look like (I am using Rails).
Asaxena
View would look no different. You'd be iterating through a collection, it's just that that collection would be of objects in memory, not a model that corresponds to a table.
miller
+3  A: 

Model View Controller.

Import the contacts into Contact objects, and store in a ContactRepository. All of this is completely in-memory, and is your Model.

When rendering this list in your View, each checkbox will have an ID which will relate to the ID of the Contact object in the Model.

When the user submits, your Controller will be able to interrogate the View for a list of the selected checkboxes (and their IDs), and then it's a case of going through the Model and creating the necessary rows in the database.

Duncan