Class: RokuBuilder::Inspector

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

Overview

Collects information on a package for submission

Instance Method Summary collapse

Methods inherited from Util

#init, #initialize, #multipart_connection, options_parse, #simple_connection

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Instance Method Details

#inspect(pkg:, password:) ⇒ Hash

Inspects the given pkg

Parameters:

  • pkg (String)

    Path to the pkg to be inspected

  • password (String)

    Password for the given pkg

Returns:

  • (Hash)

    Package information. Contains the following keys:

    • app_name

    • dev_id

    • creation_date

    • dev_zip



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/roku_builder/inspector.rb', line 14

def inspect(pkg:, password:)

  # upload new key with password
  path = "/plugin_inspect"
  conn = multipart_connection
  payload =  {
    mysubmit: "Inspect",
    passwd: password,
    archive: Faraday::UploadIO.new(pkg, 'application/octet-stream')
  }
  response = conn.post path, payload

  app_name = /App Name:\s*<\/td>\s*<td>\s*<font[^>]*>([^<]*)<\/font>\s*<\/td>/.match(response.body)
  dev_id = nil
  creation_date = nil
  dev_zip = nil
  if app_name
    app_name = app_name[1]
    dev_id = /Dev ID:\s*<\/td>\s*<td>\s*<font[^>]*>([^<]*)<\/font>\s*<\/td>/.match(response.body)[1]
    creation_date = /new Date\(([^)]*)\)/.match(response.body.delete("\n"))[1]
    dev_zip = /dev.zip:\s*<\/td>\s*<td>\s*<font[^>]*>([^<]*)<\/font>\s*<\/td>/.match(response.body)[1]
  else
    app_name = /App Name:[^<]*<div[^>]*>([^<]*)<\/div>/.match(response.body)[1]
    dev_id = /Dev ID:[^<]*<div[^>]*><font[^>]*>([^<]*)<\/font><\/div>/.match(response.body)[1]
    creation_date = /new Date\(([^\/]*)\)/.match(response.body.delete("\n"))[1]
    dev_zip = /dev.zip:[^<]*<div[^>]*><font[^>]*>([^<]*)<\/font><\/div>/.match(response.body)[1]
  end

  return {app_name: app_name, dev_id: dev_id, creation_date: Time.at(creation_date.to_i).to_s, dev_zip: dev_zip}

end

#screencapture(out_folder:, out_file: nil) ⇒ Boolean

Capture a screencapture for the currently sideloaded app

Returns:

  • (Boolean)

    Success



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/roku_builder/inspector.rb', line 48

def screencapture(out_folder:, out_file: nil)
  path = "/plugin_inspect"
  conn = multipart_connection
  payload =  {
    mysubmit: "Screenshot",
    passwd: @dev_password,
    archive: Faraday::UploadIO.new("/dev/null", 'application/octet-stream')
  }
  response = conn.post path, payload

  path = /<img src="([^"]*)">/.match(response.body)
  return false unless path
  path = path[1]
  unless out_file
    out_file = /time=([^"]*)">/.match(response.body)
    out_file = "dev_#{out_file[1]}.jpg" if out_file
  end

  conn = simple_connection

  response = conn.get path

  File.open(File.join(out_folder, out_file), "w") do |io|
    io.write(response.body)
  end
  @logger.info "Screen captured to #{File.join(out_folder, out_file)}"
  return response.success?
end