# omnigroupcontacts Inspired by the popular OmniContacts, OmniGroupContacts is a library that enables users of an application to import contacts from their email accounts with respect to group. The email providers currently supported are Gmail. OmniGroupContacts is a Rack middleware, therefore you can use it with Rails, Sinatra and any other Rack-based framework. OmniGroupContacts uses the OAuth protocol to communicate with the contacts provider. In order to use OmniGroupContacts, it is therefore necessary to first register your application with the provider and to obtain client_id and client_secret. ## Usage Add OmniGroupContacts as a dependency: ```ruby gem "omnigroupcontacts" ``` As for OmniAuth, there is a Builder facilitating the usage of multiple contacts importers. In the case of a Rails application, the following code could be placed at `config/initializers/omnigroupcontacts.rb`: ```ruby require "omnigroupcontacts" Rails.application.middleware.use OmniGroupContacts::Builder do importer :gmailgroup, "client_id", "client_secret", {:redirect_path => "/oauth2callback", :ssl_ca_file => "/etc/ssl/certs/curl-ca-bundle.crt"} end ``` ## Register your application * For Gmail : [Google API Console](https://code.google.com/apis/console/) ## Integrating with your Application To use the Gem you first need to redirect your users to `/group_contacts/:importer`, where `:importer` can be gmailgroup. No changes to `config/routes.rb` are needed for this step since omnigroupcontacts will be listening on that path and redirect the user to the email provider's website in order to authorize your app to access his contact list. Once that is done the user will be redirected back to your application, to the path specified in `:redirect_path`. If nothing is specified the default value is `/group_contacts/:importer/callback` (e.g. `/group_contacts/gmailgroup/callback`). This makes things simpler and you can just add the following line to `config/routes.rb`: ```ruby match "/group_contacts/:importer/callback" => "your_controller#callback" ``` The list of contacts can be accessed via the `omnigroupcontacts.contacts` key in the environment hash and it consists of a simple array of hashes. The following table shows which fields are supported by which provider:
Provider | :id | :profile_picture | :name | :first_name | :last_name | :address_1 | :address_2 | :city | :region | :postcode | :country | :phone_number | :birthday | :gender | :relation | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gmail | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X |