cielo24-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9877a4c6719897593af314d57fd47f42c1faac88
4
+ data.tar.gz: 7fd0d83c54a89858a7eaa18418ddbc5cd5ccfd52
5
+ SHA512:
6
+ metadata.gz: 39e7de0e3f2dc273289cd8b91281b2b7f1103241d38705330696f488b1e1bb860a8cbbc2b2ffcd11211f031176b12236baf8e719ccf60422b7c0c765fe209ceb
7
+ data.tar.gz: ec84ea2ccb79debcfb8535ded3bd99d07f2f04902a35ddd7a4f824fd81b49fbf60b7819db1990e20ed82fd01f3e01efec0ba1eebd28626a95850b64a9f161fcf
data/bin/cielo24 ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cielo24'
4
+ require_relative "../lib/cielo24_command/application"
5
+ include Cielo24Command
6
+
7
+ begin
8
+ Application.start(ARGV)
9
+ rescue ArgumentError => e
10
+ puts "ERROR: " + e.message
11
+ exit(1)
12
+ rescue Cielo24::WebError => e
13
+ puts "ERROR: " + e.message
14
+ exit(1)
15
+ end
@@ -0,0 +1,5 @@
1
+ require "cielo24_command/version"
2
+
3
+ module Cielo24Command
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,403 @@
1
+ module Cielo24Command
2
+
3
+ require 'thor'
4
+ require 'cielo24'
5
+
6
+ class Application < Thor
7
+
8
+ include Cielo24
9
+
10
+ ENV["THOR_COLUMNS"] = "300" # Otherwise descriptions/help gets truncated (...)
11
+
12
+ # ALWAYS REQUIRED:
13
+ username_option = [:u, :required => false, :desc => "cielo24 username", :type => :string, :banner => "username", :hide => true]
14
+ password_option = [:p, :required => false, :desc => "cielo24 password", :banner => "password", :hide => true]
15
+ securekey_option = [:k, :required => false, :desc => "The API Secure Key", :banner => "securekey", :hide => true]
16
+ api_token_option = [:N, :required => false, :desc => "The API token of the current session", :banner => "token", :hide => true]
17
+ server_url_option =[:s, :required => false, :desc => "cielo24 server URL [https://api.cielo24.com]", :banner => "server_url", :hide => true, :default => "http://api.cielo24.com"]
18
+ # JOB CONTROL:
19
+ job_id_option = [:j, :required => true, :desc => "Job Id", :banner => "jobid"]
20
+ media_url_option = [:m, :required => false, :desc => "Media URL", :banner => "mediaurl"]
21
+ media_file_option = [:M, :required => false, :desc => "Local media file", :banner => "filepath"]
22
+ # OTHER OPTIONS:
23
+ header_option = [:H, :required => false, :desc => "Use headers", :default => false, :type => :boolean]
24
+ fidelity_option = [:f, :required => false, :desc => "Fidelity " + Fidelity.all, :banner => "fidelity", :default => Fidelity.PREMIUM]
25
+ priority_option = [:P, :required => false, :desc => "Priority " + Priority.all, :banner => "priority", :default => Priority.STANDARD]
26
+ source_language_option = [:l, :required => false, :desc => "Source language " + Language.all, :banner => "source", :default => Language.English]
27
+ target_language_option = [:t, :required => false, :desc => "Target language " + Language.all, :banner => "target", :default => Language.English]
28
+ job_name_option = [:n, :required => false, :desc => "Job name", :banner => "jobname"]
29
+ job_options_option = [:J, :required => false, :desc => "Job option (list key:value pairs after -J)", :banner => 'key:value', :type => :hash]
30
+ caption_options_option = [:O, :required => false, :desc => "Caption/transcript options (list key:value pairs after -O)", :banner => 'key:value', :type => :hash]
31
+ turn_around_hours_option = [:T, :required => false, :desc => "Turn around hours", :banner => "hours"]
32
+ callback_url_option = [:C, :required => false, :desc => "Callback URL", :banner => "callback"]
33
+ caption_format_option = [:c, :required => true, :desc => "Caption format " + CaptionFormat.all, :banner => "format", :default => CaptionFormat.SRT]
34
+ elementlist_version_option = [:e, :required => false, :desc => "ElementList Version", :banner => "version"]
35
+ force_new_option = [:F, :required => false, :desc => "Force new key", :default => false]
36
+ new_password_option = [:d, :required => true, :desc => "New password", :banner => "newpass"]
37
+ verbose_option = [:v, :require => false, :desc => "Verbose mode", :hide => true, :default => false, :type => :boolean]
38
+
39
+ class_option *server_url_option # Server URL can be specified for any action
40
+ class_option *verbose_option # Verbose mode can be specified for any action
41
+
42
+ desc "login", 'Performs a login action'
43
+ option :u, :required => true, :desc => "cielo24 username", :type => :string, :banner => "username"
44
+ option :p, :required => false, :desc => "cielo24 password", :banner => "password"
45
+ option :k, :required => false, :desc => "The API Secure Key", :banner => "securekey"
46
+ option *header_option
47
+ def login
48
+ puts "Performing a login action..."
49
+ actions = initialize_actions
50
+ token = actions.login(options[:u], options[:p], options[:k], options[:h])
51
+ print_url()
52
+ puts "API token: " + token
53
+ end
54
+
55
+ desc "logout", 'Performs a logout action'
56
+ option :N, :required => true, :desc => "The API token of the current session", :banner => "token"
57
+ def logout
58
+ puts "Performing a logout action..."
59
+ actions = initialize_actions
60
+ actions.logout(options[:N])
61
+ print_url()
62
+ puts "Logged out successfully"
63
+ end
64
+
65
+ desc "create", 'Creates a job'
66
+ option *fidelity_option
67
+ option *priority_option
68
+ option *source_language_option
69
+ option *target_language_option
70
+ option *media_url_option
71
+ option *media_file_option
72
+ option *job_name_option
73
+ option *job_options_option
74
+ option *turn_around_hours_option
75
+ option *callback_url_option
76
+ # always required (hidden)
77
+ option *username_option
78
+ option *password_option
79
+ option *securekey_option
80
+ option *api_token_option
81
+ def create
82
+
83
+ if options[:m].nil? and options[:M].nil?
84
+ puts "Media URL or local file path mus be supplied"
85
+ exit(1)
86
+ end
87
+
88
+ puts "Creating job..."
89
+ actions = initialize_actions
90
+ token = get_token(actions)
91
+ mash = actions.create_job(token, options[:n], options[:l])
92
+ puts "Job ID: " + mash.JobId
93
+ puts "Task ID: " + mash.TaskId
94
+ print_url()
95
+
96
+ puts "Adding media..."
97
+ if !options[:m].nil?
98
+ task_id = actions.add_media_to_job_url(token, mash.JobId, options[:m])
99
+ else !options[:M].nil?
100
+ file = File.new(File.absolute_path(options[:M]), "r")
101
+ task_id = actions.add_media_to_job_file(token, mash.JobId, file)
102
+ end
103
+ puts "Task ID: " + task_id
104
+ print_url()
105
+
106
+ puts "Performing transcription..."
107
+
108
+ # Parse option hash
109
+ jobopts = PerformTranscriptionOptions.new
110
+ jobopts.populate_from_hash(options[:J])
111
+
112
+ task_id = actions.perform_transcription(token, mash.JobId, options[:f], options[:P], options[:c], options[:T], options[:t], jobopts)
113
+ puts "Task ID: " + task_id
114
+ print_url()
115
+ end
116
+
117
+ desc "delete", 'Delete a job'
118
+ option *job_id_option
119
+ # always required (hidden)
120
+ option *username_option
121
+ option *password_option
122
+ option *securekey_option
123
+ option *api_token_option
124
+ def delete
125
+ puts "Deleting job..."
126
+ actions = initialize_actions
127
+ token = get_token(actions)
128
+ task_id = actions.delete_job(token, options[:j])
129
+ puts "Task ID: " + task_id
130
+ print_url()
131
+ end
132
+
133
+ desc "authorize", 'Authorize a job'
134
+ option *job_id_option
135
+ # always required (hidden)
136
+ option *username_option
137
+ option *password_option
138
+ option *securekey_option
139
+ option *api_token_option
140
+ def authorize
141
+ puts "Authorizing job..."
142
+ actions = initialize_actions
143
+ token = get_token(actions)
144
+ actions.authorize_job(token, options[:j])
145
+ print_url()
146
+ puts "Authorized successfully"
147
+ end
148
+
149
+ desc "add_media_to_job", 'Add media to job'
150
+ option *job_id_option
151
+ option *media_url_option
152
+ option *media_file_option
153
+ # always required (hidden)
154
+ option *username_option
155
+ option *password_option
156
+ option *securekey_option
157
+ option *api_token_option
158
+ def add_media_to_job
159
+ puts "Adding media to job..."
160
+ actions = initialize_actions
161
+ token = get_token(actions)
162
+ if !options[:m].nil?
163
+ task_id = actions.add_media_to_job_url(token, options[:j], options[:m])
164
+ elsif !options[:M].nil?
165
+ file = File.new(File.absolute_path(options[:M]), "r")
166
+ task_id = actions.add_media_to_job_file(token, options[:j], file)
167
+ else
168
+ raise ArgumentError.new("Media URL or local file path must be supplied")
169
+ end
170
+ puts "Task ID: " + task_id
171
+ print_url()
172
+ end
173
+
174
+ desc "add_embedded_media_to_job", 'Add embedded media to job'
175
+ option *job_id_option
176
+ option :m, :required => true, :desc => "Media URL", :banner => "mediaurl"
177
+ # always required (hidden)
178
+ option *username_option
179
+ option *password_option
180
+ option *securekey_option
181
+ option *api_token_option
182
+ def add_embedded_media_to_job
183
+ puts "Adding embedded media to job..."
184
+ actions = initialize_actions
185
+ token = get_token(actions)
186
+ task_id = actions.add_media_to_job_embedded(token, options[:j], options[:m])
187
+ puts "Task ID: " + task_id
188
+ print_url()
189
+ end
190
+
191
+ desc "list", 'Lists current jobs'
192
+ # always required (hidden)
193
+ option *username_option
194
+ option *password_option
195
+ option *securekey_option
196
+ option *api_token_option
197
+ def list
198
+ puts "Retrieving list..."
199
+ actions = initialize_actions
200
+ token = get_token(actions)
201
+ mash = actions.get_job_list(token)
202
+ print_url()
203
+ puts JSON.pretty_generate(JSON.parse(mash.to_json(nil)))
204
+ end
205
+
206
+ desc "list_elementlists", 'List ElementLists'
207
+ option *job_id_option
208
+ # always required (hidden)
209
+ option *username_option
210
+ option *password_option
211
+ option *securekey_option
212
+ option *api_token_option
213
+ def list_elementlists
214
+ puts "Listing Element Lists..."
215
+ actions = initialize_actions
216
+ token = get_token(actions)
217
+ array = actions.get_list_of_element_lists(token, options[:j])
218
+ print_url()
219
+ puts JSON.pretty_generate(array)
220
+ end
221
+
222
+ desc "get_caption", 'Get Caption'
223
+ option *job_id_option
224
+ option *caption_format_option
225
+ option *elementlist_version_option
226
+ option *caption_options_option
227
+ # always required (hidden)
228
+ option *username_option
229
+ option *password_option
230
+ option *securekey_option
231
+ option *api_token_option
232
+ def get_caption
233
+ puts "Getting caption..."
234
+ actions = initialize_actions
235
+ token = get_token(actions)
236
+
237
+ # Parse options
238
+ caption_opts = CaptionOptions.new
239
+ caption_opts.populate_from_hash(options[:O])
240
+
241
+ caption = actions.get_caption(token, options[:j], options[:c], caption_opts)
242
+ print_url()
243
+ puts caption
244
+ end
245
+
246
+ desc "get_transcript", 'Get Transcript'
247
+ option *job_id_option
248
+ option *elementlist_version_option
249
+ option *caption_options_option
250
+ # always required (hidden)
251
+ option *username_option
252
+ option *password_option
253
+ option *securekey_option
254
+ option *api_token_option
255
+ def get_transcript
256
+ puts "Getting transcript..."
257
+ actions = initialize_actions
258
+ token = get_token(actions)
259
+
260
+ # Parse options
261
+ transcription_opts = TranscriptionOptions.new
262
+ transcription_opts.populate_from_hash(options[:O])
263
+
264
+ transcript = actions.get_transcript(token, options[:j], transcription_opts)
265
+ print_url()
266
+ puts transcript
267
+ end
268
+
269
+ desc "get_elementlist", 'Get ElementList for JobId'
270
+ option *job_id_option
271
+ # always required (hidden)
272
+ option *username_option
273
+ option *password_option
274
+ option *securekey_option
275
+ option *api_token_option
276
+ def get_elementlist
277
+ puts "Getting ELement List..."
278
+ actions = initialize_actions
279
+ token = get_token(actions)
280
+ mash = actions.get_element_list(token, options[:j])
281
+ print_url()
282
+ puts JSON.pretty_generate(JSON.parse(mash.to_json(nil)))
283
+ end
284
+
285
+ desc "get_media", 'Get Media'
286
+ option *job_id_option
287
+ # always required (hidden)
288
+ option *username_option
289
+ option *password_option
290
+ option *securekey_option
291
+ option *api_token_option
292
+ def get_media
293
+ puts "Getting media..."
294
+ actions = initialize_actions
295
+ token = get_token(actions)
296
+ url = actions.get_media(token, options[:j])
297
+ print_url()
298
+ puts url
299
+ end
300
+
301
+ desc "generate_api_key", 'Generate API Secure Key'
302
+ option *force_new_option
303
+ # always required (hidden)
304
+ option *username_option
305
+ option *password_option
306
+ option *securekey_option
307
+ option *api_token_option
308
+ def generate_api_key
309
+ puts "Generating API key..."
310
+ actions = initialize_actions
311
+ token = get_token(actions)
312
+ key = actions.generate_api_key(token, options[:u], options[:F])
313
+ print_url()
314
+ puts "API Secure Key: " + key
315
+ end
316
+
317
+ desc "remove_api_key", 'Remove API Secure Key'
318
+ option :api_key, :aliases => 'k', :required => true, :desc => "The API Key to remove"
319
+ # always required (hidden)
320
+ option *username_option
321
+ option *password_option
322
+ option *securekey_option
323
+ option *api_token_option
324
+ def remove_api_key
325
+ puts "Removing API key..."
326
+ actions = initialize_actions
327
+ token = get_token(actions)
328
+ actions.remove_api_key(token, options[:k])
329
+ print_url()
330
+ puts "The key was successfully removed."
331
+ end
332
+
333
+ desc "update_password", 'Update Password'
334
+ option *new_password_option
335
+ # always required (hidden)
336
+ option *username_option
337
+ option *password_option
338
+ option *securekey_option
339
+ option *api_token_option
340
+ def update_password
341
+ puts "Updating password..."
342
+ actions = initialize_actions
343
+ token = get_token(actions)
344
+ actions.update_password(token, options[:d])
345
+ print_url()
346
+ puts "Password was updated successfully."
347
+ end
348
+
349
+ desc "job_info", 'Get Job Info'
350
+ option *job_id_option
351
+ # always required (hidden)
352
+ option *username_option
353
+ option *password_option
354
+ option *securekey_option
355
+ option *api_token_option
356
+ def job_info
357
+ puts "Getting Job Info..."
358
+ actions = initialize_actions
359
+ token = get_token(actions)
360
+ mash = actions.get_job_info(token, options[:j])
361
+ print_url()
362
+ puts JSON.pretty_generate(JSON.parse(mash.to_json(nil)))
363
+ end
364
+
365
+ # Method override, so that an "always required" message can be printed out before everything else
366
+ def help(arg=nil, arg2=nil)
367
+ super(arg, arg2)
368
+ puts "\nAlways required options:"
369
+ puts " -u=username \# cielo24 username"
370
+ puts " [-s=serverurl] \# cielo24 server URL"
371
+ puts " \# Default: https://api.cielo24.com"
372
+ puts "\n ++Either one of the following:"
373
+ puts " --------------------------------------------"
374
+ puts " -p=password \# cielo24 password"
375
+ puts " -k=securekey \# The API Secure Key"
376
+ puts " -N=token \# The API token of the current session"
377
+ puts " --------------------------------------------"
378
+ end
379
+
380
+ no_commands{
381
+ def private_login(actions, username, password, securekey)
382
+ raise ArgumentError.new("Username was not supplied.") if username.nil?
383
+ return actions.login(username, password, securekey, true)
384
+ end
385
+
386
+ def initialize_actions
387
+ actions = Actions.new
388
+ actions.base_url = options[:s] if !options[:s].nil?
389
+ return actions
390
+ end
391
+
392
+ def get_token(actions)
393
+ return (options[:N].nil?) ? private_login(actions, options[:u], options[:p], options[:k]) : options[:N]
394
+ end
395
+
396
+ def print_url
397
+ if(options[:v])
398
+ puts WebUtils.LAST_URL
399
+ end
400
+ end
401
+ }
402
+ end
403
+ end
@@ -0,0 +1,3 @@
1
+ module Cielo24Command
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cielo24-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Evgeny Chistyakov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cielo24
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Command line interface that allows you to make web API calls using cielo24
70
+ gem.
71
+ email:
72
+ - support@cielo24.com
73
+ executables:
74
+ - cielo24
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - lib/cielo24_command/application.rb
79
+ - lib/cielo24_command/version.rb
80
+ - lib/cielo24_command.rb
81
+ - bin/cielo24
82
+ homepage: http://cielo24.com
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.14
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Command line interface to cielo24 gem.
106
+ test_files: []