Class: Miles::Audio
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(host, port = 80) ⇒ Audio
constructor
A new instance of Audio.
- #pause ⇒ Object
- #pause_spotify ⇒ Object
- #play ⇒ Object
- #play_spotify(track_link = nil) ⇒ Object
- #say(text) ⇒ Object
- #search_spotify(query) ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(host, port = 80) ⇒ Audio
Returns a new instance of Audio.
10 11 12 13 14 15 |
# File 'lib/miles/audio.rb', line 10 def initialize(host, port=80) @host = host @port = port @base_uri = "#{host}#{port != 80 ? ':' + @port.to_s : ''}" self.class.base_uri @base_uri end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
8 9 10 |
# File 'lib/miles/audio.rb', line 8 def base_uri @base_uri end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/miles/audio.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/miles/audio.rb', line 8 def port @port end |
Instance Method Details
#pause ⇒ Object
50 51 52 53 |
# File 'lib/miles/audio.rb', line 50 def pause response = self.class.get('/pause') return true end |
#pause_spotify ⇒ Object
39 40 41 42 43 |
# File 'lib/miles/audio.rb', line 39 def pause_spotify query = {'action' => 'pause'} response = self.class.post('/spotify', :body => query.to_json) return JSON.parse(response) end |
#play ⇒ Object
45 46 47 48 |
# File 'lib/miles/audio.rb', line 45 def play response = self.class.get('/play') return true end |
#play_spotify(track_link = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/miles/audio.rb', line 29 def play_spotify(track_link=nil) query = {'action' => 'play'} if not track_link.nil? query['link'] = track_link end response = self.class.post('/spotify', :body => query.to_json) return JSON.parse(response) end |
#say(text) ⇒ Object
17 18 19 20 21 |
# File 'lib/miles/audio.rb', line 17 def say(text) req = {'text' => text} response = self.class.post('/say', :body => req.to_json) return JSON.parse(response) end |
#search_spotify(query) ⇒ Object
23 24 25 26 27 |
# File 'lib/miles/audio.rb', line 23 def search_spotify(query) query['service'] = 'spotify' response = self.class.post('/search', :body => query.to_json) return JSON.parse(response) end |
#status ⇒ Object
55 56 57 58 |
# File 'lib/miles/audio.rb', line 55 def status response = self.class.get('/status') return JSON.parse(response) end |