Class: RokuBuilder::Util

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

Overview

Super class for device utilities This class defines a common initializer and allows subclasses to define their own secondary initializer

Direct Known Subclasses

Inspector, Keyer, Linker, Loader, Monitor, Navigator, Packager, Tester

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip:, user:, password:, logger:, init_params: nil) ⇒ Util

Common initializer of device utils

Parameters:

  • ip (String)

    IP address of roku device

  • user (String)

    Username for roku device

  • password (String)

    Password for roku device



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roku_builder/util.rb', line 12

def initialize(ip:, user:, password:, logger:, init_params: nil)
  @device_config = {
    ip: ip,
    user: user,
    password: password
  }
  @roku_ip_address = ip
  @dev_username = user
  @dev_password = password
  @url = "http://#{@roku_ip_address}"
  @logger = logger
  if init_params
    init(**init_params)
  else
    init
  end
end

Class Method Details

.options_parse(options:) ⇒ Hash

Parses a string into and options hash

Parameters:

  • options (String)

    string of options in the format “a:b, c:d”

Returns:

  • (Hash)

    Options hash generated



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/roku_builder/util.rb', line 62

def self.options_parse(options:)
  parsed = {}
  opts = options.split(/,\s*/)
  opts.each do |opt|
    opt = opt.split(":")
    key = opt.shift.to_sym
    value = opt.join(":")
    parsed[key] = value
  end
  parsed
end

Instance Method Details

#initObject

Second initializer to be overwriten



31
32
33
# File 'lib/roku_builder/util.rb', line 31

def init
  #Override in subclass
end

#multipart_connection(port: nil) ⇒ Faraday

Generates a multipart Faraday connection with digest credentials

Parameters:

  • port (Integer) (defaults to: nil)

    optional port to connect to

Returns:

  • (Faraday)

    The faraday connection



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/roku_builder/util.rb', line 47

def multipart_connection(port: nil)
  url = @url
  url = "#{url}:#{port}" if port
  Faraday.new(url: url) do |f|
    f.headers['Content-Type'] = Faraday::Request::Multipart.mime_type
    f.request :digest, @dev_username, @dev_password
    f.request :multipart
    f.request :url_encoded
    f.adapter Faraday.default_adapter
  end
end

#simple_connectionFaraday

Generates a simpe Faraday connection with digest credentials

Returns:

  • (Faraday)

    The faraday connection



37
38
39
40
41
42
# File 'lib/roku_builder/util.rb', line 37

def simple_connection
  Faraday.new(url: @url) do |f|
    f.request :digest, @dev_username, @dev_password
    f.adapter Faraday.default_adapter
  end
end