Class: ApiUserAuth::Providers::Google

Inherits:
Object
  • Object
show all
Defined in:
lib/api_user_auth/providers/google.rb

Overview

Get info from Google token

Constant Summary collapse

API_PATH =
'https://www.googleapis.com/plus/v1/people/me'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Google

Returns a new instance of Google.



9
10
11
12
# File 'lib/api_user_auth/providers/google.rb', line 9

def initialize(token)
  @token = token
  @data = {}
end

Class Method Details

.get_user(token) ⇒ Object



39
40
41
42
# File 'lib/api_user_auth/providers/google.rb', line 39

def self.get_user(token)
  g = Google.new(token)
  g.get_user_data
end

Instance Method Details

#api_info_urlObject



14
15
16
17
18
19
# File 'lib/api_user_auth/providers/google.rb', line 14

def api_info_url
  params = {
    access_token: @token
  }
  URI("#{API_PATH}?#{params.to_query}")
end

#get_user_dataObject



21
22
23
24
# File 'lib/api_user_auth/providers/google.rb', line 21

def get_user_data
  api_get_request
  user_data
end

#user_dataObject



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

def user_data
  {
    id: @data[:id], name: @data[:displayName],
    email: @data[:emails].first.try(:[], :value), provider: 'google',
    img_url: (@data[:image] || {}).try(:[], :url),
    info: {
      birthday: @data[:birthday],
      city: (@data[:hometown] || {}).try(:[], :name),
      gender: @data[:gender]
    }
  }
end