Class: RokuBuilder::Navigator

Inherits:
Util
  • Object
show all
Defined in:
lib/roku_builder/navigator.rb

Overview

Navigation methods

Instance Method Summary collapse

Methods inherited from Util

#initialize, #multipart_connection, options_parse, #simple_connection

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Instance Method Details

#initObject

Setup navigation commands



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/roku_builder/navigator.rb', line 7

def init
  @commands = {
    up: "Up",
    down: "Down",
    right: "Right",
    left: "Left",
    select: "Select",
    back: "Back",
    home: "Home",
    rew: "Rev",
    ff: "Fwd",
    play: "Play",
    replay: "InstantReplay"
  }

  @screens = {
    platform: [:home, :home, :home, :home, :home, :ff, :play, :rew, :play, :ff],
    secret: [:home, :home, :home, :home, :home, :ff, :ff, :ff, :rew, :rew],
    secret2: [:home, :home, :home, :home, :home, :up, :right, :down, :left, :up],
    channels: [:home, :home, :home, :up, :up, :left, :right, :left, :right, :left],
    developer: [:home, :home, :home, :up, :up, :right, :left, :right, :left, :right],
    wifi: [:home, :home, :home, :home, :home, :up, :down, :up, :down, :up],
    antenna: [:home, :home, :home, :home, :home, :ff, :down, :rew, :down, :ff],
    bitrate: [:home, :home, :home, :home, :home, :rew, :rew, :rew, :ff, :ff],
    network: [:home, :home, :home, :home, :home, :right, :left, :right, :left, :right],
    reboot: [:home, :home, :home, :home, :home, :up, :rew, :rew, :ff, :ff]
  }
end

Send a navigation command to the roku device

Parameters:

  • command (Symbol)

    The smbol of the command to send

Returns:

  • (Boolean)

    Success



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/roku_builder/navigator.rb', line 39

def nav(command:)
  if @commands.has_key?(command)
    conn = multipart_connection(port: 8060)

    path = "/keypress/#{@commands[command]}"
    response = conn.post path
    return response.success?
  else
    return false
  end
end

#screen(type:) ⇒ Boolean

Show the commands for one of the roku secret screens

Parameters:

  • type (Symbol)

    The type of screen to show

Returns:

  • (Boolean)

    Screen found



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/roku_builder/navigator.rb', line 67

def screen(type:)
  if @screens.has_key?(type)
    display = []
    count = []
    @screens[type].each do |command|
      if display.count > 0 and  display[-1] == command
        count[-1] = count[-1] + 1
      else
        display.push(command)
        count.push(1)
      end
    end
    string = ""
    display.each_index do |i|
      if count[i] > 1
        string = string + @commands[display[i]]+" x "+count[i].to_s+", "
      else
        string = string + @commands[display[i]]+", "
      end
    end
    @logger.unknown(string.strip)
  else
    return false
  end
  true
end

#screensObject

Show avaiable roku secret screens



95
96
97
# File 'lib/roku_builder/navigator.rb', line 95

def screens
  @screens.keys.each {|screen| @logger.unknown(screen)}
end

#type(text:) ⇒ Boolean

Type text on the roku device

Parameters:

  • text (String)

    The text to type on the device

Returns:

  • (Boolean)

    Success



54
55
56
57
58
59
60
61
62
# File 'lib/roku_builder/navigator.rb', line 54

def type(text:)
  conn = multipart_connection(port: 8060)
  text.split(//).each do |c|
    path = "/keypress/LIT_#{CGI::escape(c)}"
    response = conn.post path
    return false unless response.success?
  end
  return true
end