Class: TRMNLP::Commands::Push
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from TRMNLP::Commands::Base
Instance Method Details
#call ⇒ Object
9 10 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trmnlp/commands/push.rb', line 9 def call context.validate! authenticate! is_new = false api = APIClient.new(config) plugin_settings_id = .id || config.plugin.id if plugin_settings_id.nil? output 'Creating a new plugin on the server...' response = api.post_plugin_setting(name: 'New TRMNLP Plugin', plugin_id: 37) # hardcoded id for private_plugin plugin_settings_id = response.dig('data', 'id') is_new = true end unless is_new || .force answer = prompt("Plugin settings on the server will be overwritten. Are you sure? (y/n) ").downcase raise Error, 'aborting' unless answer == 'y' || answer == 'yes' end size = 0 Tempfile.create(binmode: true) do |temp_file| Zip::File.open(temp_file.path, Zip::File::CREATE) do |zip_file| paths.src_files.each do |file| zip_file.add(File.basename(file), file) end end response = api.post_plugin_setting_archive(plugin_settings_id, temp_file.path) paths.plugin_config.write(response.dig('data', 'settings_yaml')) size = File.size(temp_file.path) end output <<~HEREDOC Uploaded plugin (#{size} bytes) Dashboard: #{config.app.edit_plugin_settings_uri(plugin_settings_id)} HEREDOC if is_new output <<~HEREDOC IMPORTANT! Don't forget to add it to your device playlist! #{config.app.playlists_uri} HEREDOC end end |