Class: RokuBuilder::Linker

Inherits:
Util
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/linker.rb

Overview

Launch application, sending parameters

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



9
10
11
12
13
14
15
# File 'lib/roku_builder/plugins/linker.rb', line 9

def self.commands
  {
    deeplink: {device: true, stage: true},
    input: {device: true},
    applist: {device: true}
  }
end

.dependenciesObject



34
35
36
# File 'lib/roku_builder/plugins/linker.rb', line 34

def self.dependencies
  [Loader]
end

.parse_options(parser:, options:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/roku_builder/plugins/linker.rb', line 17

def self.parse_options(parser:,  options:)
  parser.separator "Commands:"
  parser.on("-o", "--deeplink OPTIONS", "Launch and Deeplink into app. Define options as keypairs (eg. \"a:b, c:d,e:f\") or name (eg. \"name\"). To use named deeplinks, including them in your config file: \"deeplinks\": { \"name\": \"a:b, c:d, e:f\" }") do |o|
    options[:deeplink] = o
  end
  parser.on("-i", "--input OPTIONS", "Deeplink into app. Define options as keypairs (eg. \"a:b, c:d,e:f\") or name (eg. \"name\"). To use named deeplinks, including them in your config file: \"deeplinks\": { \"name\": \"a:b, c:d, e:f\" }") do |o|
    options[:input] = o
  end
  parser.on("-A", "--app-list", "List currently installed apps") do
    options[:applist] = true
  end
  parser.separator "Options:"
  parser.on("-a", "--app ID", "Send App id for deeplinking") do |a|
    options[:app_id] = a
  end
end

Instance Method Details

#applist(options:) ⇒ Object

List currently installed apps

Parameters:

  • logger (Logger)

    System Logger



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/roku_builder/plugins/linker.rb', line 57

def applist(options:)
  path = "/query/apps"
  response = nil
  multipart_connection(port: 8060) do |conn|
    response = conn.get path
  end

  if response.success?
    regexp = /id="([^"]*)"\stype="([^"]*)"\sversion="([^"]*)">([^<]*)</
    apps = response.body.scan(regexp)
    printf("%30s | %10s | %10s | %10s\n", "title", "id", "type", "version")
    printf("---------------------------------------------------------------------\n")
    apps.each do |app|
      printf("%30s | %10s | %10s | %10s\n", app[3], app[0], app[1], app[2])
    end
  end
end

Deeplink to an app



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

def deeplink(options:, device: nil)
  get_device(device: device) do |device|
    if options.has_source?
      Loader.new(config: @config).sideload(options: options, device: device)
    end
    app_id = options[:app_id]
    app_id ||= "dev"
    path = "/launch/#{app_id}"
    send_options(path: path, options: options[:deeplink], device: device)
  end
end

#input(options:) ⇒ Object



51
52
53
# File 'lib/roku_builder/plugins/linker.rb', line 51

def input(options:)
  send_options(path: "/input", options: options[:input])
end