Class: Shellify::User
- Inherits:
-
RSpotify::User
- Object
- RSpotify::User
- Shellify::User
- Defined in:
- lib/shellify/user.rb
Constant Summary collapse
- USER_FILE =
'/spotify_user.json'
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #configured? ⇒ Boolean
-
#initialize(config_dir) ⇒ User
constructor
A new instance of User.
- #save! ⇒ Object
Constructor Details
#initialize(config_dir) ⇒ User
Returns a new instance of User.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shellify/user.rb', line 9 def initialize(config_dir) @config_dir = config_dir @user_file_path = config_dir + USER_FILE create_user_file write_default_user load_persisted_user super({ 'credentials' => { 'token' => @token, 'refresh_token' => @refresh_token, 'access_refresh_callback' => access_refresh_callback, }, 'id' => @id, }) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/shellify/user.rb', line 5 def id @id end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
5 6 7 |
# File 'lib/shellify/user.rb', line 5 def refresh_token @refresh_token end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/shellify/user.rb', line 5 def token @token end |
Instance Method Details
#configured? ⇒ Boolean
25 26 27 |
# File 'lib/shellify/user.rb', line 25 def configured? !@token.empty? && !@refresh_token.empty? && !@id.empty? end |
#save! ⇒ Object
29 30 31 32 33 |
# File 'lib/shellify/user.rb', line 29 def save! File.open(@user_file_path, 'w') do |file| file.write(JSON.pretty_generate({ id: @id, token: @token, refresh_token: @refresh_token })) end end |