Class: Configs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigs

Returns a new instance of Configs.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Configs.rb', line 13

def initialize
	@app_version = '1.0'
	#subsonic API protocol version
	@proto_version = '1.9.0'
	@appname = 'subcl'
	@max_search_results = 20 #default value
	@notifyMethod = "auto"
	@randomSongCount = 10

	@filename = File.expand_path("~/.subcl")
	unless File.file?(@filename)
		raise "Config file not found"
	end

	readConfigs
	#TODO optimally don't ping here - do this when the notification system is initialized
	ping
end

Instance Attribute Details

#app_versionObject (readonly)

Returns the value of attribute app_version.



10
11
12
# File 'lib/Configs.rb', line 10

def app_version
  @app_version
end

#appnameObject (readonly)

Returns the value of attribute appname.



9
10
11
# File 'lib/Configs.rb', line 9

def appname
  @appname
end

#max_search_resultsObject (readonly)

Returns the value of attribute max_search_results.



7
8
9
# File 'lib/Configs.rb', line 7

def max_search_results
  @max_search_results
end

#notifyMethodObject (readonly)

Returns the value of attribute notifyMethod.



8
9
10
# File 'lib/Configs.rb', line 8

def notifyMethod
  @notifyMethod
end

#proto_versionObject (readonly)

Returns the value of attribute proto_version.



6
7
8
# File 'lib/Configs.rb', line 6

def proto_version
  @proto_version
end

#pwordObject (readonly)

Returns the value of attribute pword.



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

def pword
  @pword
end

#randomSongCountObject (readonly)

Returns the value of attribute randomSongCount.



11
12
13
# File 'lib/Configs.rb', line 11

def randomSongCount
  @randomSongCount
end

#serverObject (readonly)

Returns the value of attribute server.



3
4
5
# File 'lib/Configs.rb', line 3

def server
  @server
end

#unameObject (readonly)

Returns the value of attribute uname.



4
5
6
# File 'lib/Configs.rb', line 4

def uname
  @uname
end

Instance Method Details

#pingObject

check to see if the server is reachable



58
59
60
61
62
63
64
65
# File 'lib/Configs.rb', line 58

def ping
	url = @server + "/rest/ping.view"
	begin
		Net::HTTP.get_response(URI.parse(url))
	rescue
		raise "Couldn't connect to server: #{@server}"
	end
end

#readConfigsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/Configs.rb', line 32

def readConfigs

	file = File.new(@filename, "r")
	while (line = file.gets) do
		spl = line.split(' ')
		if spl[0].eql? "server"
			@server = spl[1]
		elsif spl[0].eql? "username"
			@uname = spl[1]
		elsif spl[0].eql? "password"
			@pword = spl[1]
		elsif spl[0].eql? "max_search_results"
			@max_search_results = spl[1]
		elsif spl[0].eql? "notify_method"
			@notifyMethod = spl[1]
		elsif spl[0].eql? "random_song_count"
			@randomSongCount = spl[1]
		end
	end

	if @server == nil or @uname == nil or @pword == nil
		raise "Incorrect configuration file"
	end
end