Class: YFantasy::Api::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/y_fantasy/api/authentication.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

YAHOO_CLIENT_ID =
YFantasy.config.yahoo_client_id
YAHOO_CLIENT_SECRET =
YFantasy.config.yahoo_client_secret
YAHOO_USERNAME =
YFantasy.config.yahoo_username
YAHOO_PASSWORD =
YFantasy.config.yahoo_password
REQUEST_AUTH_URL =
"https://api.login.yahoo.com/oauth2/request_auth?client_id=#{YAHOO_CLIENT_ID}&redirect_uri=oob&response_type=code"
GET_TOKEN_URL =
"https://api.login.yahoo.com/oauth2/get_token"
MSG_SEPARATOR =
"#" * 50

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject (readonly)

TODO: I don’t think any of these readers are needed besides access_token. Maybe the error ones?



26
27
28
# File 'lib/y_fantasy/api/authentication.rb', line 26

def access_token
  @access_token
end

.error_descObject (readonly)

TODO: I don’t think any of these readers are needed besides access_token. Maybe the error ones?



26
27
28
# File 'lib/y_fantasy/api/authentication.rb', line 26

def error_desc
  @error_desc
end

.error_typeObject (readonly)

TODO: I don’t think any of these readers are needed besides access_token. Maybe the error ones?



26
27
28
# File 'lib/y_fantasy/api/authentication.rb', line 26

def error_type
  @error_type
end

.expires_atObject (readonly)

TODO: I don’t think any of these readers are needed besides access_token. Maybe the error ones?



26
27
28
# File 'lib/y_fantasy/api/authentication.rb', line 26

def expires_at
  @expires_at
end

.refresh_tokenObject (readonly)

TODO: I don’t think any of these readers are needed besides access_token. Maybe the error ones?



26
27
28
# File 'lib/y_fantasy/api/authentication.rb', line 26

def refresh_token
  @refresh_token
end

Class Method Details

.access_token_valid?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/y_fantasy/api/authentication.rb', line 38

def access_token_valid?
  !!access_token && !!expires_at && Time.now.to_i < expires_at
end

.authenticateObject



28
29
30
31
32
33
34
35
36
# File 'lib/y_fantasy/api/authentication.rb', line 28

def authenticate
  return true if access_token_valid?

  if YFantasy.config.yahoo_refresh_token
    @refresh_token = YFantasy.config.yahoo_refresh_token
  end

  refresh_token? ? authenticate_with_refresh_token : authenticate_with_code
end