Coder Social home page Coder Social logo

gmail-contacts's Introduction

gmail-contacts

A Ruby gem for getting a list of your Gmail contacts. Most of the code here has been extracted from mislav's contacts gem. It's been updated to work with Ruby 1.9 and Rails 3.

Installation

gem install gmail-contacts

or in your Gemfile:

gem 'gmail-contacts', :require => "gmail-contacts"

Usage

Get a link to the authorization URL:

GmailContacts::Google.authentication_url("http://mysite.com/invites")

The user will be redirected to the URL you pass and a token parameter will be sent along. Capture that token and then request the contacts:

GmailContacts::Google.new("some_token").contacts

Every Contact has a name and email fields:

GmailContacts::Google.new("some_token").contacts.each do |contact|
  puts "#{contact.name}: #{contact.email}"
end

Usage with Rails

First create the authorization link in one of your views:

# app/views/invites/new.html.erb
<%= link_to "Invite your Gmail contacts", GmailContacts::Google.authentication_url("http://mysite.com/invites") %>

Then create a controller action that receives the token and fetches the contacts:

# config/routes.rb
match "/invites" => "invites#index"

# app/controllers/invites_controller.rb
class InvitesController
  def index
    token = params[:token]
    @contacts = GmailContacts::Google.new("some_token").contacts
  end
end

Finally, iterate through the contacts in your view:

# app/views/invites/index.html.erb
<% @contacts.each do |contact| %>
  <span><strong><%= contact.name %></strong>: <% contact.email %></span>
<% end %>

gmail-contacts's People

Contributors

febuiles avatar mislav avatar pezra avatar pietern avatar

Watchers

 avatar  avatar

Forkers

rah00l

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.