Class: RokuBuilder::Packager

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

Overview

Method of packaging app 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

#package(app_name_version:, out_file:, password:) ⇒ Boolean

Sign and download the currently sideloaded app

Parameters:

  • app_name_version (String)

    The name and version of the package

  • out_file (String)

    Location to download signed package to

  • password (String)

    Password for the devices current key

Returns:

  • (Boolean)

    True on package success and download, false otherwise



11
12
13
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
# File 'lib/roku_builder/packager.rb', line 11

def package(app_name_version:, out_file:, password:)
  # Sign package
  path = "/plugin_package"
  conn = multipart_connection
  payload =  {
    mysubmit: "Package",
    app_name: app_name_version,
    passwd: password,
    pkg_time: Time.now.to_i
  }
  response = conn.post path, payload

  # Check for error
  failed = /(Failed: [^\.]*\.)/.match(response.body)
  return failed[1] if failed

  # Download signed package
  pkg = /<a href="pkgs[^>]*>([^<]*)</.match(response.body)[1]
  path = "/pkgs/#{pkg}"
  conn = Faraday.new(url: @url) do |f|
    f.request :digest, @dev_username, @dev_password
    f.adapter Faraday.default_adapter
  end
  response = conn.get path
  return false if response.status != 200

  File.open(out_file, 'w+') {|fp| fp.write(response.body)}
  true
end