Class: RokuBuilder::Loader
Overview
Load/Unload/Build roku applications
Instance Method Summary collapse
-
#build(build_version: nil, outfile: nil, content: nil) ⇒ String
Build an app to sideload later.
-
#init(root_dir: nil) ⇒ Object
Set the root directory.
-
#sideload(update_manifest: false, content: nil, infile: nil) ⇒ String
Sideload an app onto a roku device.
-
#unload ⇒ Object
Remove the currently sideloaded app.
Methods inherited from Util
#initialize, #multipart_connection, options_parse, #simple_connection
Constructor Details
This class inherits a constructor from RokuBuilder::Util
Instance Method Details
#build(build_version: nil, outfile: nil, content: nil) ⇒ String
Build an app to sideload later
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/roku_builder/loader.rb', line 54 def build(build_version: nil, outfile: nil, content: nil) build_version = ManifestManager.build_version(root_dir: @root_dir) unless build_version content ||= {} unless content and content[:folders] content[:folders] = Dir.entries(@root_dir).select {|entry| File.directory? File.join(@root_dir, entry) and !(entry =='.' || entry == '..') } end unless content and content[:files] content[:files] = Dir.entries(@root_dir).select {|entry| File.file? File.join(@root_dir, entry)} end content[:excludes] = [] unless content and content[:excludes] outfile = "/tmp/build_#{build_version}.zip" unless outfile File.delete(outfile) if File.exist?(outfile) io = Zip::File.open(outfile, Zip::File::CREATE) # Add folders to zip content[:folders].each do |folder| base_folder = File.join(@root_dir, folder) entries = Dir.entries(base_folder) entries.delete(".") entries.delete("..") writeEntries(@root_dir, entries, folder, content[:excludes], io) end # Add file to zip writeEntries(@root_dir, content[:files], "", content[:excludes], io) io.close() outfile end |
#init(root_dir: nil) ⇒ Object
Set the root directory
8 9 10 |
# File 'lib/roku_builder/loader.rb', line 8 def init(root_dir: nil) @root_dir = root_dir end |
#sideload(update_manifest: false, content: nil, infile: nil) ⇒ String
Sideload an app onto a roku device
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 45 |
# File 'lib/roku_builder/loader.rb', line 16 def sideload(update_manifest: false, content: nil, infile: nil) result = FAILED_SIDELOAD outfile = nil build_version = nil if infile build_version = ManifestManager.build_version(root_dir: infile) outfile = infile else # Update manifest if update_manifest build_version = ManifestManager.update_build(root_dir: @root_dir) else build_version = ManifestManager.build_version(root_dir: @root_dir) end outfile = build(build_version: build_version, content: content) end path = "/plugin_install" # Connect to roku and upload file conn = multipart_connection payload = { mysubmit: "Replace", archive: Faraday::UploadIO.new(outfile, 'application/zip') } response = conn.post path, payload # Cleanup File.delete(outfile) unless infile result = SUCCESS if response.status==200 and response.body=~/Install Success/ result = IDENTICAL_SIDELOAD if response.status==200 and response.body=~/Identical to previous version/ [result, build_version] end |
#unload ⇒ Object
Remove the currently sideloaded app
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/roku_builder/loader.rb', line 82 def unload() path = "/plugin_install" # Connect to roku and upload file conn = multipart_connection payload = { mysubmit: "Delete", archive: "" } response = conn.post path, payload if response.status == 200 and response.body =~ /Install Success/ return true end return false end |