Class: Zencoder::CLI::Command::Jobs
- Defined in:
- lib/zencoder-cli/commands/jobs.rb
Class Method Summary collapse
- .create(args, global_options, command_options) ⇒ Object
- .run(args, global_options, command_options) ⇒ Object
Methods inherited from Base
Methods included from Helpers
#ask, #confirm, #display, #error, #format_date, #home_directory, #running_on_a_mac?, #running_on_windows?, #truncate
Class Method Details
.create(args, global_options, command_options) ⇒ Object
44 45 46 47 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 76 |
# File 'lib/zencoder-cli/commands/jobs.rb', line 44 def create(args, , ) arg = args.shift if arg.blank? puts "You must pass either a JSON string or the path to a file containing JSON." exit 1 end begin json = JSON.parse(arg.to_s.first == "{" ? arg : File.read(arg)) rescue JSON::ParserError => e puts "Invalid JSON: #{e.}" exit 1 rescue Errno::ENOENT => e puts e. exit 1 end response = Zencoder::Job.create(json, :base_url => Zencoder.base_url([:environment])).process_for_cli.body rows = [] rows << ["ID", response["id"]] rows << ["Test", response["test"]] if response["test"] puts table([{ :value => "Job", :colspan => 2 }], *rows) puts response["outputs"].each_with_index do |output, i| rows = [] rows << ["ID", output["id"]] rows << ["Label", output["label"]] if output["label"] rows << ["URL", output["url"]] puts table([{ :value => "Output ##{i+1}", :colspan => 2 }], *rows) puts end end |
.run(args, global_options, command_options) ⇒ Object
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 |
# File 'lib/zencoder-cli/commands/jobs.rb', line 16 def run(args, , ) jobs = Zencoder::Job.list(:base_url => Zencoder.base_url([:environment]), :per_page => [:number] || 10, :page => [:page] || 1, :state => [:state].try(:downcase)).process_for_cli.body if jobs.any? jobs_table = table do |t| t.headings = ["ID", "Created", "Filename", "Duration", "Size", "Test", "State"] jobs.each do |job| duration = job["job"]["input_media_file"]["duration_in_ms"] ? (job["job"]["input_media_file"]["duration_in_ms"]/1000).to_s+"s" : "---" filesize = job["job"]["input_media_file"]["file_size_bytes"] ? ("%0.2f" % (job["job"]["input_media_file"]["file_size_bytes"].to_f/1.megabyte))+" MB" : "---" t << [ job["job"]["id"], format_date(job["job"]["created_at"]), truncate(File.basename(job["job"]["input_media_file"]["url"]), :length => [:long] ? 256 : 25), { :value => duration, :alignment => :right }, { :value => filesize, :alignment => :right }, job["job"]["test"] ? "YES" : "NO", job["job"]["state"].titleize ] end end puts jobs_table else puts "No jobs found." end end |