Class: Cielo24Command::Application

Inherits:
Thor
  • Object
show all
Includes:
Cielo24
Defined in:
lib/cielo24_command/application.rb

Instance Method Summary collapse

Instance Method Details

#add_embedded_media_to_jobObject



182
183
184
185
186
187
188
189
# File 'lib/cielo24_command/application.rb', line 182

def add_embedded_media_to_job
  puts "Adding embedded media to job..."
  actions = initialize_actions
  token = get_token(actions)
  task_id = actions.add_media_to_job_embedded(token, options[:j], options[:m])
  puts "Task ID: " + task_id
  print_url()
end

#add_media_to_jobObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/cielo24_command/application.rb', line 158

def add_media_to_job
  puts "Adding media to job..."
  actions = initialize_actions
  token = get_token(actions)
  if !options[:m].nil?
    task_id = actions.add_media_to_job_url(token, options[:j], options[:m])
  elsif !options[:M].nil?
    file = File.new(File.absolute_path(options[:M]), "r")
    task_id = actions.add_media_to_job_file(token, options[:j], file)
  else
    raise ArgumentError.new("Media URL or local file path must be supplied")
  end
  puts "Task ID: " + task_id
  print_url()
end

#authorizeObject



140
141
142
143
144
145
146
147
# File 'lib/cielo24_command/application.rb', line 140

def authorize
  puts "Authorizing job..."
  actions = initialize_actions
  token = get_token(actions)
  actions.authorize_job(token, options[:j])
  print_url()
  puts "Authorized successfully"
end

#createObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/cielo24_command/application.rb', line 81

def create

  if options[:m].nil? and options[:M].nil?
    puts "Media URL or local file path must be supplied"
    exit(1)
  end

  puts "Creating job..."
  actions = initialize_actions
  token = get_token(actions)
  mash = actions.create_job(token, options[:n], options[:l])
  puts "Job ID: " + mash.JobId
  puts "Task ID: " + mash.TaskId
  print_url()

  puts "Adding media..."
  if !options[:m].nil?
    task_id = actions.add_media_to_job_url(token, mash.JobId, options[:m])
  elsif !options[:M].nil?
    file = File.new(File.absolute_path(options[:M]), "r")
    task_id = actions.add_media_to_job_file(token, mash.JobId, file)
  end
  puts "Task ID: " + task_id
  print_url()

  puts "Performing transcription..."

  # Parse option hash
  jobopts = PerformTranscriptionOptions.new
  jobopts.populate_from_hash(options[:J])

  task_id = actions.perform_transcription(token, mash.JobId, options[:f], options[:P], options[:C], options[:T], options[:t], jobopts)
  puts "Task ID: " + task_id
  print_url()
end

#deleteObject



124
125
126
127
128
129
130
131
# File 'lib/cielo24_command/application.rb', line 124

def delete
  puts "Deleting job..."
  actions = initialize_actions
  token = get_token(actions)
  task_id = actions.delete_job(token, options[:j])
  puts "Task ID: " + task_id
  print_url()
end

#generate_api_keyObject



309
310
311
312
313
314
315
316
# File 'lib/cielo24_command/application.rb', line 309

def generate_api_key
  puts "Generating API key..."
  actions = initialize_actions
  token = get_token(actions)
  key = actions.generate_api_key(token, options[:u], options[:F])
  print_url()
  puts "API Secure Key: " + key
end

#get_captionObject



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/cielo24_command/application.rb', line 232

def get_caption
  puts "Getting caption..."
  actions = initialize_actions
  token = get_token(actions)

  # Parse options
  caption_opts = CaptionOptions.new
  caption_opts.populate_from_hash(options[:O])

  caption = actions.get_caption(token, options[:j], options[:c], caption_opts)
  print_url()
  puts caption
end

#get_elementlistObject



277
278
279
280
281
282
283
284
# File 'lib/cielo24_command/application.rb', line 277

def get_elementlist
  puts "Getting ELement List..."
  actions = initialize_actions
  token = get_token(actions)
  mash = actions.get_element_list(token, options[:j], option[:e])
  print_url()
  puts JSON.pretty_generate(JSON.parse(mash.to_json(nil)))
end

#get_mediaObject



293
294
295
296
297
298
299
300
# File 'lib/cielo24_command/application.rb', line 293

def get_media
  puts "Getting media..."
  actions = initialize_actions
  token = get_token(actions)
  url = actions.get_media(token, options[:j])
  print_url()
  puts url
end

#get_transcriptObject



255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/cielo24_command/application.rb', line 255

def get_transcript
  puts "Getting transcript..."
  actions = initialize_actions
  token = get_token(actions)

  # Parse options
  transcription_opts = TranscriptionOptions.new
  transcription_opts.populate_from_hash(options[:O])

  transcript = actions.get_transcript(token, options[:j], transcription_opts)
  print_url()
  puts transcript
end

#help(arg = nil, arg2 = nil) ⇒ Object

Method override, so that an “always required” message can be printed out before everything else



367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/cielo24_command/application.rb', line 367

def help(arg=nil, arg2=nil)
  super(arg, arg2)
  puts "\nAlways required options:"
  puts "  -u=username          \# cielo24 username"
  puts "  [-s=serverurl]       \# cielo24 server URL"
  puts "                       \# Default: https://api.cielo24.com"
  puts "\n  ++Either one of the following:"
  puts "  --------------------------------------------"
  puts "  -p=password          \# cielo24 password"
  puts "  -k=securekey         \# The API Secure Key"
  puts "  -N=token             \# The API token of the current session"
  puts "  --------------------------------------------"
end

#job_infoObject



357
358
359
360
361
362
363
364
# File 'lib/cielo24_command/application.rb', line 357

def job_info
  puts "Getting Job Info..."
  actions = initialize_actions
  token = get_token(actions)
  mash = actions.get_job_info(token, options[:j])
  print_url()
  puts JSON.pretty_generate(JSON.parse(mash.to_json(nil)))
end

#listObject



197
198
199
200
201
202
203
204
# File 'lib/cielo24_command/application.rb', line 197

def list
  puts "Retrieving list..."
  actions = initialize_actions
  token = get_token(actions)
  mash = actions.get_job_list(token)
  print_url()
  puts JSON.pretty_generate(JSON.parse(mash.to_json(nil)))
end

#list_elementlistsObject



213
214
215
216
217
218
219
220
# File 'lib/cielo24_command/application.rb', line 213

def list_elementlists
  puts "Listing Element Lists..."
  actions = initialize_actions
  token = get_token(actions)
  array = actions.get_list_of_element_lists(token, options[:j])
  print_url()
  puts JSON.pretty_generate(array)
end

#loginObject



47
48
49
50
51
52
53
# File 'lib/cielo24_command/application.rb', line 47

def 
  puts "Performing a login action..."
  actions = initialize_actions
  token = actions.(options[:u], options[:p], options[:k], options[:h])
  print_url()
  puts "API token: " + token
end

#logoutObject



57
58
59
60
61
62
63
# File 'lib/cielo24_command/application.rb', line 57

def logout
  puts "Performing a logout action..."
  actions = initialize_actions
  actions.logout(options[:N])
  print_url()
  puts "Logged out successfully"
end

#remove_api_keyObject



325
326
327
328
329
330
331
332
# File 'lib/cielo24_command/application.rb', line 325

def remove_api_key
  puts "Removing API key..."
  actions = initialize_actions
  token = get_token(actions)
  actions.remove_api_key(token, options[:k])
  print_url()
  puts "The key was successfully removed."
end

#update_passwordObject



341
342
343
344
345
346
347
348
# File 'lib/cielo24_command/application.rb', line 341

def update_password
  puts "Updating password..."
  actions = initialize_actions
  token = get_token(actions)
  actions.update_password(token, options[:d])
  print_url()
  puts "Password was updated successfully."
end