README.md in omnicontacts-0.3.4 vs README.md in omnicontacts-0.3.5

- old
+ new

@@ -1,13 +1,13 @@ # OmniContacts -Inspired by the popular OmniAuth, OmniContacts is a library that enables users of an application to import contacts -from their email or Facebook accounts. The email providers currently supported are Gmail, Yahoo and Hotmail. +Inspired by the popular OmniAuth, OmniContacts is a library that enables users of an application to import contacts +from their email or Facebook accounts. The email providers currently supported are Gmail, Yahoo and Hotmail. OmniContacts is a Rack middleware, therefore you can use it with Rails, Sinatra and any other Rack-based framework. OmniContacts uses the OAuth protocol to communicate with the contacts provider. Yahoo still uses OAuth 1.0, while - Facebook, Gmail and Hotmail support OAuth 2.0. + Facebook, Gmail and Hotmail support OAuth 2.0. In order to use OmniContacts, it is therefore necessary to first register your application with the provider and to obtain client_id and client_secret. ## Usage Add OmniContacts as a dependency: @@ -29,27 +29,40 @@ importer :facebook, "client_id", "client_secret" end ``` -Every importer expects `client_id` and `client_secret` as mandatory, while `:redirect_path` and `:ssl_ca_file` are optional. -Since Yahoo implements the version 1.0 of the OAuth protocol, naming is slightly different. Instead of `:redirect_path` you should use `:callback_path` as key in the hash providing the optional parameters. +Every importer expects `client_id` and `client_secret` as mandatory, while `:redirect_path` and `:ssl_ca_file` are optional. +Since Yahoo implements the version 1.0 of the OAuth protocol, naming is slightly different. Instead of `:redirect_path` you should use `:callback_path` as key in the hash providing the optional parameters. While `:ssl_ca_file` is optional, it is highly recommended to set it on production environments for obvious security reasons. On the other hand it makes things much easier to leave the default value for `:redirect_path` and `:callback path`, the reason of which will be clear after reading the following section. +## Register your application + +* For Gmail : [Google API Console](https://code.google.com/apis/console/) + +* For Yahoo : [Yahoo Developer Network](https://developer.apps.yahoo.com/projects) + +* For Hotmail : [Microsoft Developer Network](https://account.live.com/developers/applications/index) + +* For Facebook : [Facebook Developers](https://developers.facebook.com/apps) + +##### Note: +Please go through [MSDN](http://msdn.microsoft.com/en-us/library/cc287659.aspx) if above Hotmail link will not work. + ## Integrating with your Application -To use the Gem you first need to redirect your users to `/contacts/:importer`, where `:importer` can be facebook, gmail, yahoo or hotmail. +To use the Gem you first need to redirect your users to `/contacts/:importer`, where `:importer` can be facebook, gmail, yahoo or hotmail. No changes to `config/routes.rb` are needed for this step since OmniContacts 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` (or `:callback_path` for yahoo). If nothing is specified the default value is `/contacts/:importer/callback` (e.g. `/contacts/yahoo/callback`). This makes things simpler and you can just add the following line to `config/routes.rb`: ```ruby match "/contacts/:importer/callback" => "your_controller#callback" ``` -The list of contacts can be accessed via the `omnicontacts.contacts` key in the environment hash and it consists of a simple array of hashes. +The list of contacts can be accessed via the `omnicontacts.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: <table> <tr> <th>Provider</th> @@ -57,10 +70,17 @@ <th>:id</th> <th>:profile_picture</th> <th>:name</th> <th>:first_name</th> <th>:last_name</th> + <th>:address_1</th> + <th>:address_2</th> + <th>:city</th> + <th>:region</th> + <th>:postcode</th> + <th>:country</th> + <th>:phone_number</th> <th>:birthday</th> <th>:gender</th> <th>:relation</th> </tr> <tr> @@ -72,56 +92,87 @@ <td>X</td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> </tr> <tr> <td>Facebook</td> + <td></td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> <td>X</td> <td>X</td> <td>X</td> - <td>X</td> </tr> <tr> <td>Yahoo</td> <td>X</td> <td>X</td> <td></td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> + <td>X</td> <td></td> <td></td> + <td>X</td> + <td></td> + <td></td> </tr> <tr> <td>Hotmail</td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> <td>X</td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> <td>X</td> <td>X</td> <td></td> </tr> </table> Obviously it may happen that some fields are blank even if supported by the provider in the case that the contact did not provide any information about them. -The following snippet shows how to simply print name and email of each contact: +The information for the logged in user can also be accessed via 'omnicontacts.user' key in the environment hash. It consists of a simple hash which includes the same fields as above. + +The following snippet shows how to simply print name and email of each contact, and also the the name of logged in user: ```ruby def contacts_callback @contacts = request.env['omnicontacts.contacts'] - puts "List of contacts obtained from #{params[:importer]}:" + @user = request.env['omnicontacts.user'] + puts "List of contacts of #{@user[:name]} obtained from #{params[:importer]}:" @contacts.each do |contact| puts "Contact found: name => #{contact[:name]}, email => #{contact[:email]}" end end ``` @@ -140,12 +191,12 @@ importer :gmail, "xxx", "yyy", :max_results => 1000 ``` Yahoo requires you to configure the Permissions your application requires. Make sure to go the Yahoo website and to select Read permission for Contacts. -Hotmail presents a "peculiar" feature. Their API returns a Contact object which does not contain an e-mail field! -However, if the contact has either name, family name or both set to null, than there is a field called name which does contain the e-mail address. +Hotmail presents a "peculiar" feature. Their API returns a Contact object which does not contain an e-mail field! +However, if the contact has either name, family name or both set to null, than there is a field called name which does contain the e-mail address. This means that it may happen that an Hotmail contact does not contain the email field. ## Integration Testing You can enable test mode like this: @@ -173,37 +224,63 @@ page.should have_content("user@example.com") ``` ## Working on localhost -Since Hotmail and Facebook do not allow the usage of `localhost` as redirect path for the authorization step, a workaround is to use the `localtunnel` gem. -This gem is really useful when you need someone, the contacts provider in this case, to access your locally running application using a unique url. +Since Hotmail and Facebook do not allow the usage of `localhost` as redirect path for the authorization step, a workaround is to use `ngrok`. +This is really useful when you need someone, the contacts provider in this case, to access your locally running application using a unique url. -Install the Gem using RubyGems: +Install ngrok, download from: + +https://ngrok.com/ + +https://github.com/inconshreveable/ngrok + +Unzip the file ```bash -sudo gem install localtunnel +unzip /place/this/is/ngrok.zip ``` +Start your application +```bash +$ rails server -Start `localtunnel` passing your public SSH key and the port where your application is running: +=> Booting WEBrick +=> Rails 4.0.4 application starting in development on http://0.0.0.0:3000 +``` + +In a new terminal window, start the tunnel and pass the port where your application is running: ```bash -localtunnel -k ~/.ssh/id_rsa.pub 3000 +./ngrok 3000 ``` -Check the output to see something like +Check the output to see something like ```bash -Port 3000 is now publicly accessible from http://8bv2.localtunnel.com ... +ngrok (Ctrl+C to quit) + +Tunnel Status online +Version 1.6/1.5 +Forwarding http://274101c1e.ngrok.com -> 127.0.0.1:3000 +Forwarding https://274101c1e.ngrok.com -> 127.0.0.1:3000 +Web Interface 127.0.0.1:4040 +# Conn 0 +Avg Conn Time 0.00ms ``` -The printed Url is the one you can now use to access your application. +This window will show all network transaction that your locally hosted application is processing. +Ngrok will process all of the requests and responses on your localhost. Visit: +```bash +http://123456789.ngrok.com # replace 123456789 with your instance +``` + ## Example application Thanks to @sonianand11, you can find a full example of a Rails application using OmniContacts at: https://github.com/sonianand11/omnicontacts_example ## Thanks -As already mentioned above, a special thanks goes to @sonianand11 for implementing an example app. -Thanks also to @asmatameem for its huge contribution. He indeed added support for Facebook and for many fields which were missing before. +As already mentioned above, a special thanks goes to @sonianand11 for implementing an example app. +Thanks also to @asmatameem for her huge contribution. She indeed added support for Facebook and for many fields which were missing before. ## License Copyright (c) 2012-2013 Diego81