Class: Shellify::User

Inherits:
RSpotify::User
  • Object
show all
Defined in:
lib/shellify/user.rb

Constant Summary collapse

USER_FILE =
'/spotify_user.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/shellify/user.rb', line 5

def id
  @id
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



5
6
7
# File 'lib/shellify/user.rb', line 5

def refresh_token
  @refresh_token
end

#tokenObject

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

Returns:

  • (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