Class: Shellify::Config
- Inherits:
-
Object
- Object
- Shellify::Config
- 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
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#config_dir ⇒ Object
Returns the value of attribute config_dir.
Instance Method Summary collapse
- #configured? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #save! ⇒ Object
Constructor Details
#initialize ⇒ Config
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_id ⇒ Object
Returns the value of attribute client_id.
5 6 7 |
# File 'lib/shellify/config.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
5 6 7 |
# File 'lib/shellify/config.rb', line 5 def client_secret @client_secret end |
#config_dir ⇒ Object
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
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 |