Class: Gista::UserToken
- Inherits:
-
Object
- Object
- Gista::UserToken
- Defined in:
- lib/gista/user_token.rb
Overview
Acquire and store an OAuth authorization token in the user's home directory.
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
Default path to file to store the token in
File.('~/.gista')
Instance Attribute Summary collapse
-
#authoriser ⇒ #fetch
readonly
when calling
fetch('token')
.
Instance Method Summary collapse
-
#initialize(authoriser, token_file = nil) ⇒ UserToken
constructor
A new instance of UserToken.
-
#token ⇒ String
Return the user token.
-
#token_file ⇒ String
Path to file containing a re-usable token.
Constructor Details
#initialize(authoriser, token_file = nil) ⇒ UserToken
Returns a new instance of UserToken.
16 17 18 |
# File 'lib/gista/user_token.rb', line 16 def initialize(, token_file = nil) @authoriser, @token_file = , token_file end |
Instance Attribute Details
#authoriser ⇒ #fetch (readonly)
when calling fetch('token')
.
14 15 16 |
# File 'lib/gista/user_token.rb', line 14 def @authoriser end |
Instance Method Details
#token ⇒ String
Return the user token. Either read it from disk, or request a new token
with the Github API using the credentials from creds
.
24 25 26 27 28 29 |
# File 'lib/gista/user_token.rb', line 24 def token return read_from_config_file if has_config_file? request_token.tap do |token| write_to_config_file(token) end end |
#token_file ⇒ String
Returns path to file containing a re-usable token.
32 33 34 |
# File 'lib/gista/user_token.rb', line 32 def token_file @token_file || DEFAULT_CONFIG_FILE end |