Confirmed users
632
edits
(→Gmail) |
|||
| Line 89: | Line 89: | ||
== Importing == | == Importing == | ||
In order to avoid running into cross-origin issues in retrieving contacts, the retrieval will be performed in privileged code. This means that the window.mozLoop API will need new functions added to it in order to initiate contact import. | |||
The function for starting an import will be of the form: | |||
function startImport(importId, serviceParameters, newContactCallback, errorCallback) | |||
* '''importId''': A unique ID passed back to the caller in callbacks. This allows the caller to disambiguate between import operations in the case that there are multiple operations going on at the same time. | |||
* '''serviceParameters''': An object defining the service to import from. This must contain a "service" parameter. Certain services may require additional parameters. | |||
* '''newContactCallback''': A callback of the form <tt>function(importId, contact, progress, total)<tt>, called whenever a new contact is imported. Note that this contact may already exist in the database (that is, it may already have an entry with a matching "id" field), in which case the new contact should ''replace'' the existing entry. | |||
** ''importId'': The import ID passed in when startImport was called. | |||
** ''contact'': The contact in the format described above | |||
** ''progress'': The number of contacts that have been imported from this operation | |||
** ''total'': The total number of contacts in this current import operation. Set to '-1' if unknown. | |||
* '''errorCallback''': A callback of the form <tt>function(importId, error)<tt> | |||
** ''importId'': The import ID passed in when startImport was called. | |||
** ''error'': An [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error Error] object with information about the failure. | |||
window.mozLoop.startImport({service: "gmail"}, newContact, importError) | |||
=== Gmail === | === Gmail === | ||
| Line 99: | Line 118: | ||
# For each contact in the result: | # For each contact in the result: | ||
#* Translate the result into a contact object according the the table below. Note that some data may require manipulation to convert between the gmail format and the field described in mozContacts. | #* Translate the result into a contact object according the the table below. Note that some data may require manipulation to convert between the gmail format and the field described in mozContacts. | ||
#* Fire a callback to allow the UI to update. The callback should include the number of total contacts being imported, the number of contacts already imported (from this import), and the "id" field of the contact that was just imported. | #* Fire a callback to allow the UI to update. The callback should include the number of total contacts being imported, the number of contacts already imported (from this import), and the "id" field of the contact that was just imported. | ||