Class: Gista::UserToken

Inherits:
Object
  • Object
show all
Defined in:
lib/gista/user_token.rb

Overview

Acquire and store an OAuth authorization token in the user's home directory.

See Also:

Constant Summary collapse

DEFAULT_CONFIG_FILE =

Default path to file to store the token in

Returns:

  • (String)
File.expand_path('~/.gista')

Instance Attribute Summary collapse

Instance Method Summary collapse

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(authoriser, token_file = nil)
  @authoriser, @token_file = authoriser, token_file
end

Instance Attribute Details

#authoriser#fetch (readonly)

when calling fetch('token').

Returns:

  • (#fetch)

    any object that returns the token to use



14
15
16
# File 'lib/gista/user_token.rb', line 14

def authoriser
  @authoriser
end

Instance Method Details

#tokenString

Return the user token. Either read it from disk, or request a new token with the Github API using the credentials from creds.

Returns:

  • (String)


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_fileString

Returns path to file containing a re-usable token.

Returns:

  • (String)

    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