Class: Shellify::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/shellify/config.rb

Constant Summary collapse

CONFIG_DIR =
"#{ENV['HOME']}/.config/shellify"
CONFIG_FILE =
"#{CONFIG_DIR}/config.json"
SPOTIFY_AUTHORIZATION_SCOPES =
%w[
  user-read-playback-state
  user-modify-playback-state
  user-read-currently-playing
  user-library-modify
  user-library-read
  playlist-modify-private
  playlist-read-collaborative
  playlist-read-private
  playlist-modify-public
].join(' ')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
26
# File 'lib/shellify/config.rb', line 21

def initialize
  @config_dir = CONFIG_DIR
  @config_file = CONFIG_FILE
  load_config
  RSpotify.authenticate(@client_id, @client_secret) if configured?
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



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

def client_secret
  @client_secret
end

#config_dirObject

Returns the value of attribute config_dir.



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

def config_dir
  @config_dir
end

Instance Method Details

#configured?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/shellify/config.rb', line 28

def configured?
  !@client_id.nil? && !@client_secret.nil?
end

#save!Object



32
33
34
35
36
# File 'lib/shellify/config.rb', line 32

def save!
  File.open(CONFIG_FILE, 'w') do |file|
    file.write(JSON.pretty_generate({ client_id: @client_id, client_secret: @client_secret }))
  end
end