Class: HackyHAL::DeviceControllers::Roku

Inherits:
Base
  • Object
show all
Defined in:
lib/hacky_hal/device_controllers/roku.rb

Constant Summary collapse

KEY_HOME =
"Home"
KEY_REVERSE =
"Rev"
KEY_FORWARD =
"Fwd"
KEY_PLAY =
"Play"
KEY_SELECT =
"Select"
KEY_LEFT =
"Left"
KEY_RIGHT =
"Right"
KEY_DOWN =
"Down"
KEY_UP =
"Up"
KEY_BACK =
"Back"
KEY_INSTANT_REPLAY =
"InstantReplay"
KEY_INFO =
"Info"
KEY_BACKSPACE =
"Backspace"
KEY_SEARCH =
"Search"
KEY_ENTER =
"Enter"
NAMED_KEYS =
Set.new([
  KEY_HOME, KEY_REVERSE, KEY_FORWARD, KEY_PLAY,
  KEY_SELECT, KEY_LEFT, KEY_RIGHT, KEY_DOWN,
  KEY_UP, KEY_BACK, KEY_INSTANT_REPLAY, KEY_INFO,
  KEY_BACKSPACE, KEY_SEARCH, KEY_ENTER
])

Instance Attribute Summary collapse

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Base

#log

Methods included from Options

#[]

Constructor Details

#initialize(options) ⇒ Roku

Returns a new instance of Roku.



38
39
40
41
42
43
44
45
46
# File 'lib/hacky_hal/device_controllers/roku.rb', line 38

def initialize(options)
  super(options)
  ensure_option(:device_resolver)

  resolver = Util.object_from_hash(options[:device_resolver], DeviceResolvers)
  @host_uri = resolver.uri

  log("Host found at: #{@host_uri.to_s}", :debug)
end

Instance Attribute Details

#host_uriObject (readonly)

Returns the value of attribute host_uri.



36
37
38
# File 'lib/hacky_hal/device_controllers/roku.rb', line 36

def host_uri
  @host_uri
end

Instance Method Details

#channel_listObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hacky_hal/device_controllers/roku.rb', line 48

def channel_list
  response = get_request("/query/apps")
  response_document = REXML::Document.new(response.body)
  
  response_document.elements.to_a("apps/app").map do |app|
    id = app.attributes["id"]
    version = app.attributes["version"]
    name = app.text

    {id: id, version: version, name: name}
  end
end

#icon(channel_id) ⇒ Object



65
66
67
68
# File 'lib/hacky_hal/device_controllers/roku.rb', line 65

def icon(channel_id)
  response = get_request("/query/icon/#{channel_id}")
  {type: response["content-type"], body: response.body}
end

#key_down(key) ⇒ Object



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

def key_down(key)
  post_request("/keydown/#{key_code(key)}")
end

#key_press(key) ⇒ Object



78
79
80
# File 'lib/hacky_hal/device_controllers/roku.rb', line 78

def key_press(key)
  post_request("/keypress/#{key_code(key)}")
end

#key_press_string(string) ⇒ Object



82
83
84
85
86
# File 'lib/hacky_hal/device_controllers/roku.rb', line 82

def key_press_string(string)
  string.chars.each do |char|
    key_press(char)
  end
end

#key_up(key) ⇒ Object



74
75
76
# File 'lib/hacky_hal/device_controllers/roku.rb', line 74

def key_up(key)
  post_request("/keyup/#{key_code(key)}")
end

#launch(channel_id, query_params = nil) ⇒ Object



61
62
63
# File 'lib/hacky_hal/device_controllers/roku.rb', line 61

def launch(channel_id, query_params = nil)
  post_request("/launch/#{channel_id}", query_params)
end