Module: Roku::Client

Includes:
HTTParty
Defined in:
lib/roku/client.rb

Constant Summary collapse

KEYS =
%i[
  Home
  Rev
  Fwd
  Play
  Select
  Left
  Right
  Down
  Up
  Back
  InstantReplay
  Info
  Backspace
  Search
  Enter
  FindRemote
  VolumeDown
  VolumeMute
  VolumeUp
  PowerOff
  InputTuner
  InputHDMI1
  InputHDMI2
  InputHDMI3
  InputHDMI4
  InputAV1
].freeze

Class Method Summary collapse

Class Method Details

.active_appObject



49
50
51
52
# File 'lib/roku/client.rb', line 49

def active_app
  app = get('/query/active-app').parsed_response['active_app']['app']
  App.parse(app)
end

.appsObject



43
44
45
46
47
# File 'lib/roku/client.rb', line 43

def apps
  get('/query/apps').parsed_response['apps']['app'].map do |app|
    App.parse(app)
  end
end

.device_infoObject



54
55
56
# File 'lib/roku/client.rb', line 54

def device_info
  get('/query/device-info').parsed_response['device_info']
end

.find_device!Object



38
39
40
41
# File 'lib/roku/client.rb', line 38

def find_device!
  address = ENV.fetch('ROKU_HOST') { Roku::Discover.search }
  base_uri(address)
end

.input(options = {}) ⇒ Object



96
97
98
# File 'lib/roku/client.rb', line 96

def input(options = {})
  post('/input', options)
end

.install(app_id) ⇒ Object



70
71
72
# File 'lib/roku/client.rb', line 70

def install(app_id)
  post("/install/#{app_id}").success?
end

.keydown(key) ⇒ Object



86
87
88
89
# File 'lib/roku/client.rb', line 86

def keydown(key)
  return unless KEYS.include?(key.to_sym)
  post("/keydown/#{key}").success?
end

.keypress(key) ⇒ Object



81
82
83
84
# File 'lib/roku/client.rb', line 81

def keypress(key)
  return unless KEYS.include?(key.to_sym)
  post("/keypress/#{key}").success?
end

.keyup(key) ⇒ Object



91
92
93
94
# File 'lib/roku/client.rb', line 91

def keyup(key)
  return unless KEYS.include?(key.to_sym)
  post("/keyup/#{key}").success?
end

.launch(app_id) ⇒ Object



66
67
68
# File 'lib/roku/client.rb', line 66

def launch(app_id)
  post("/launch/#{app_id}").success?
end

.send_text(string) ⇒ Object



74
75
76
77
78
79
# File 'lib/roku/client.rb', line 74

def send_text(string)
  string.split('').map do |c|
    next if c == ' '
    post("/keypress/#{c}").success?
  end.all?
end

.tv_active_channelObject



62
63
64
# File 'lib/roku/client.rb', line 62

def tv_active_channel
  get('/query/tv-active-channel').parsed_response['tv_channel']
end

.tv_channelsObject



58
59
60
# File 'lib/roku/client.rb', line 58

def tv_channels
  get('/query/tv-channels').parsed_response['tv_channels']
end