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
- .active_app ⇒ Object
- .apps ⇒ Object
- .device_info ⇒ Object
- .find_device! ⇒ Object
- .input(options = {}) ⇒ Object
- .install(app_id) ⇒ Object
- .keydown(key) ⇒ Object
- .keypress(key) ⇒ Object
- .keyup(key) ⇒ Object
- .launch(app_id) ⇒ Object
- .send_text(string) ⇒ Object
- .tv_active_channel ⇒ Object
- .tv_channels ⇒ Object
Class Method Details
.active_app ⇒ Object
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 |
.apps ⇒ Object
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_info ⇒ Object
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( = {}) post('/input', ) 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_channel ⇒ Object
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_channels ⇒ Object
58 59 60 |
# File 'lib/roku/client.rb', line 58 def tv_channels get('/query/tv-channels').parsed_response['tv_channels'] end |