class Channels::Client
Public Class Methods
new(host, port=57000)
click to toggle source
# File lib/rbchannels.rb, line 9 def initialize(host, port=57000) self.class.base_uri "http://#{host}:#{port}/api" end
Public Instance Methods
channel_down()
click to toggle source
# File lib/rbchannels.rb, line 38 def channel_down command('channel_down') end
channel_up()
click to toggle source
# File lib/rbchannels.rb, line 34 def channel_up command('channel_up') end
favorite_channels()
click to toggle source
# File lib/rbchannels.rb, line 17 def favorite_channels request("GET", "/favorite_channels") if response.is_a?(Array) response else [] end end
notify(title, message)
click to toggle source
# File lib/rbchannels.rb, line 102 def notify(title, message) data = {title: title, message: message} command("notify", data) end
pause()
click to toggle source
# File lib/rbchannels.rb, line 54 def pause command('pause') end
play_channel(channel_number)
click to toggle source
# File lib/rbchannels.rb, line 90 def play_channel(channel_number) command("play/channel/#{channel_number}") end
play_recording(recording_id)
click to toggle source
# File lib/rbchannels.rb, line 94 def play_recording(recording_id) command("play/recording/#{recording_id}") end
previous_channel()
click to toggle source
# File lib/rbchannels.rb, line 42 def previous_channel command('previous_channel') end
resume()
click to toggle source
# File lib/rbchannels.rb, line 58 def resume command('resume') end
seek(seconds=0)
click to toggle source
# File lib/rbchannels.rb, line 66 def seek(seconds=0) command("seek/#{seconds}") end
seek_backward()
click to toggle source
# File lib/rbchannels.rb, line 74 def seek_backward command('seek_backward') end
seek_forward()
click to toggle source
# File lib/rbchannels.rb, line 70 def seek_forward command('seek_forward') end
skip_backward()
click to toggle source
# File lib/rbchannels.rb, line 82 def skip_backward command('skip_backward') end
skip_forward()
click to toggle source
# File lib/rbchannels.rb, line 78 def skip_forward command('skip_forward') end
status()
click to toggle source
# File lib/rbchannels.rb, line 13 def status request("GET", "/status") end
stop()
click to toggle source
# File lib/rbchannels.rb, line 62 def stop command('stop') end
toggle_cc()
click to toggle source
# File lib/rbchannels.rb, line 30 def toggle_cc command('toggle_cc') end
toggle_mute()
click to toggle source
# File lib/rbchannels.rb, line 26 def toggle_mute command('toggle_mute') end
toggle_pause()
click to toggle source
# File lib/rbchannels.rb, line 46 def toggle_pause command('toggle_pause') end
toggle_record()
click to toggle source
# File lib/rbchannels.rb, line 50 def toggle_record command('toggle_record') end
Private Instance Methods
command(named_command, data=nil)
click to toggle source
# File lib/rbchannels.rb, line 133 def command(named_command, data=nil) return request('POST', '/' + named_command, data) end
request(method, path, data=nil)
click to toggle source
# File lib/rbchannels.rb, line 109 def request(method, path, data=nil) headers = {"Content-Type": "application/json", "Accept": "application/json"} begin case method when "GET" response = self.class.get(path, headers: headers) when "POST" response = self.class.post(path, {body: data.to_json, headers: headers}) when "PUT" response = self.class.put(path, body: data.to_json, headers: headers) when "DELETE" response = self.class.delete(path, headers: headers) end if response response.parsed_response else {'status': 'error'} end rescue {'status': 'error'} end end