Class: Poke::API::Auth::GOOGLE

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/poke-api/auth/google.rb

Constant Summary collapse

GOOGLE_LOGIN_ANDROID_ID =
'9774d56d682e549c'.freeze
GOOGLE_LOGIN_SERVICE =
'audience:server:client_id:848232511240-7so421jotr' \
'2609rmqakceuu1luuq0ptb.apps.googleusercontent.com'.freeze
GOOGLE_LOGIN_APP =
'com.nianticlabs.pokemongo'.freeze
GOOGLE_LOGIN_CLIENT_SIG =
'321187995bc7cdc2b5fc91b11a96e2baa8602c62'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter=, log_level=, #logger

Constructor Details

#initialize(username, password, refresh_token) ⇒ GOOGLE

Returns a new instance of GOOGLE.



16
17
18
19
20
21
22
# File 'lib/poke-api/auth/google.rb', line 16

def initialize(username, password, refresh_token)
  @refresh_token = refresh_token
  @username      = username
  @password      = password
  @provider      = 'google'
  @expiry        = 0
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



8
9
10
# File 'lib/poke-api/auth/google.rb', line 8

def access_token
  @access_token
end

#expiryObject (readonly)

Returns the value of attribute expiry.



8
9
10
# File 'lib/poke-api/auth/google.rb', line 8

def expiry
  @expiry
end

#providerObject (readonly)

Returns the value of attribute provider.



8
9
10
# File 'lib/poke-api/auth/google.rb', line 8

def provider
  @provider
end

Instance Method Details

#connectObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/poke-api/auth/google.rb', line 24

def connect
  return access_token_from_refresh_token if @refresh_token
  logger.debug '[>] Fetching Google access token'

  token_request = perform_request('Token') do
    Gpsoauth::Auth.performMasterLogin(@username, @password, GOOGLE_LOGIN_ANDROID_ID)
  end

  auth_request = perform_request('Auth') do
    Gpsoauth::Auth.performOAuth(@username, token_request['Token'], GOOGLE_LOGIN_ANDROID_ID,
                                GOOGLE_LOGIN_SERVICE, GOOGLE_LOGIN_APP, GOOGLE_LOGIN_CLIENT_SIG)
  end

  @expiry = auth_request['Expiry'].to_i
  @access_token = auth_request['Auth']
end