Class: Oauth::Contacts::Google

Inherits:
OAuth2 show all
Defined in:
lib/oauth/contacts/google.rb

Constant Summary

Constants inherited from OAuth2

OAuth2::VERSION

Instance Attribute Summary

Attributes inherited from OAuth2

#code

Attributes inherited from Base

#access_token, #callback_url, #consumer

Instance Method Summary collapse

Methods inherited from OAuth2

#version

Constructor Details

#initializeGoogle

Returns a new instance of Google.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/oauth/contacts/google.rb', line 9

def initialize
  super
  @callback_url = Settings.oauth.contacts.google.callback_url

  opts = { key: Settings.oauth.contacts.google.key, secret: Settings.oauth.contacts.google.secret,
    extra: { site: 'https://accounts.google.com',
      authorize_url: '/o/oauth2/auth',
      token_url: '/o/oauth2/token',
      max_redirects: 5,
      raise_errors: true,
      token_method: :post,
      connection_opts: {} # [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday with
    } }

  @consumer = ::OAuth2::Client.new(opts[:key], opts[:secret], opts[:extra])
end

Instance Method Details

#authorize_urlObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oauth/contacts/google.rb', line 26

def authorize_url
  scopes = Settings.oauth.contacts.google.scopes

  extra_params = { scope: scopes.join(' '),
    redirect_uri: callback_url,
    response_type: 'code',
    access_type: 'offline',
    approval_prompt: 'force',
    state: 'google' }

  consumer.auth_code.authorize_url( extra_params )
end

#contactsObject



40
41
42
43
44
45
# File 'lib/oauth/contacts/google.rb', line 40

def contacts
  token!

  request = "https://www.google.com/m8/feeds/contacts/default/full?alt=json"
  @contacts = normalize(access_token.get(request, :parse => :json).parsed)
end