zencoder-cli 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/zencoder-cli/commands/base.rb +16 -0
- data/lib/zencoder-cli/commands/jobs.rb +43 -18
- data/lib/zencoder-cli/version.rb +1 -1
- metadata +4 -4
@@ -8,6 +8,22 @@ module Zencoder::CLI::Command
|
|
8
8
|
Zencoder::CLI::Command.commands.merge!({ name => commands })
|
9
9
|
end
|
10
10
|
|
11
|
+
def extract_id(args)
|
12
|
+
arg = args.shift
|
13
|
+
if arg.to_s.strip[/^\d+$/]
|
14
|
+
arg
|
15
|
+
else
|
16
|
+
print "Enter an ID: "
|
17
|
+
id = ask
|
18
|
+
if id.present?
|
19
|
+
id
|
20
|
+
else
|
21
|
+
puts "No ID given. Aborting."
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
11
27
|
end
|
12
28
|
end
|
13
29
|
end
|
@@ -7,7 +7,10 @@ module Zencoder::CLI::Command
|
|
7
7
|
t.opt :page, "Jobs page number. Default 1.", :type => Integer
|
8
8
|
t.opt :long, "Will not truncate filenames.", :default => false
|
9
9
|
t.opt :state, "Filter the job list by job state", :type => String
|
10
|
-
}}
|
10
|
+
}},
|
11
|
+
"jobs:create" => { :description => "Create a job by passing a JSON string or filename",
|
12
|
+
:help => "Create a job by passing either a JSON string or the path to a file containing JSON.\n\nExamples:\nzencoder jobs:create '{ \"input\": \"http://example.com/movie.mp4\" }'\nzencoder jobs:create /path/to/file.json",
|
13
|
+
:arguments => ["json_string_or_path_to_file"] }
|
11
14
|
class << self
|
12
15
|
|
13
16
|
def run(args, global_options, command_options)
|
@@ -38,6 +41,40 @@ module Zencoder::CLI::Command
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
44
|
+
def create(args, global_options, command_options)
|
45
|
+
arg = args.shift
|
46
|
+
if arg.blank?
|
47
|
+
puts "You must pass either a JSON string or the path to a file containing JSON."
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
begin
|
51
|
+
json = JSON.parse(arg.to_s.first == "{" ? arg : File.read(arg))
|
52
|
+
rescue JSON::ParserError => e
|
53
|
+
puts "Invalid JSON: #{e.message}"
|
54
|
+
exit 1
|
55
|
+
rescue Errno::ENOENT => e
|
56
|
+
puts e.message
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
response = Zencoder::Job.create(json, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli.body
|
61
|
+
|
62
|
+
rows = []
|
63
|
+
rows << ["ID", response["id"]]
|
64
|
+
rows << ["Test", response["test"]] if response["test"]
|
65
|
+
puts table([{ :value => "Job", :colspan => 2 }], *rows)
|
66
|
+
puts
|
67
|
+
|
68
|
+
response["outputs"].each_with_index do |output, i|
|
69
|
+
rows = []
|
70
|
+
rows << ["ID", output["id"]]
|
71
|
+
rows << ["Label", output["label"]] if output["label"]
|
72
|
+
rows << ["URL", output["url"]]
|
73
|
+
puts table([{ :value => "Output ##{i+1}", :colspan => 2 }], *rows)
|
74
|
+
puts
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
41
78
|
end
|
42
79
|
end
|
43
80
|
|
@@ -56,7 +93,7 @@ module Zencoder::CLI::Command
|
|
56
93
|
class << self
|
57
94
|
|
58
95
|
def run(args, global_options, command_options)
|
59
|
-
job_id =
|
96
|
+
job_id = extract_id(args)
|
60
97
|
job = Zencoder::Job.details(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli.body["job"]
|
61
98
|
rows = []
|
62
99
|
rows << ["ID", job["id"]]
|
@@ -128,40 +165,28 @@ module Zencoder::CLI::Command
|
|
128
165
|
end
|
129
166
|
|
130
167
|
def open(args, global_options, command_options)
|
131
|
-
job_id =
|
168
|
+
job_id = extract_id(args)
|
132
169
|
`open https://app.zencoder.com/jobs/#{job_id}`
|
133
170
|
end
|
134
171
|
|
135
172
|
def resubmit(args, global_options, command_options)
|
136
|
-
job_id =
|
173
|
+
job_id = extract_id(args)
|
137
174
|
response = Zencoder::Job.resubmit(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
|
138
175
|
puts "Job ##{job_id} resubmitted."
|
139
176
|
end
|
140
177
|
|
141
178
|
def cancel(args, global_options, command_options)
|
142
|
-
job_id =
|
179
|
+
job_id = extract_id(args)
|
143
180
|
response = Zencoder::Job.cancel(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
|
144
181
|
puts "Job ##{job_id} cancelled."
|
145
182
|
end
|
146
183
|
|
147
184
|
def delete(args, global_options, command_options)
|
148
|
-
job_id =
|
185
|
+
job_id = extract_id(args)
|
149
186
|
response = Zencoder::Job.delete(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
|
150
187
|
puts "Job ##{job_id} deleted."
|
151
188
|
end
|
152
189
|
|
153
|
-
|
154
|
-
private
|
155
|
-
|
156
|
-
def extract_job_id(args)
|
157
|
-
job_id = args.shift
|
158
|
-
method_name = caller.first[/`(.*)'$/, 1]
|
159
|
-
if !job_id.to_s.strip[/^\d+$/]
|
160
|
-
puts "You must specify the job to show. Try `zencoder job#{":"+method_name unless method_name == "run"} --help` for more information."
|
161
|
-
exit 1
|
162
|
-
end
|
163
|
-
job_id
|
164
|
-
end
|
165
190
|
end
|
166
191
|
|
167
192
|
end
|
data/lib/zencoder-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zencoder-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Arbini
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-23 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|