Class: Cielo24::Actions

Inherits:
Object
  • Object
show all
Includes:
Cielo24, Errno, Hashie
Defined in:
lib/cielo24/actions.rb

Constant Summary collapse

API_VERSION =
1
LOGIN_PATH =
'/api/account/login'
LOGOUT_PATH =
'/api/account/logout'
UPDATE_PASSWORD_PATH =
'/api/account/update_password'
GENERATE_API_KEY_PATH =
'/api/account/generate_api_key'
REMOVE_API_KEY_PATH =
'/api/account/remove_api_key'
CREATE_JOB_PATH =
'/api/job/new'
AUTHORIZE_JOB_PATH =
'/api/job/authorize'
DELETE_JOB_PATH =
'/api/job/del'
GET_JOB_INFO_PATH =
'/api/job/info'
GET_JOB_LIST_PATH =
'/api/job/list'
ADD_MEDIA_TO_JOB_PATH =
'/api/job/add_media'
ADD_EMBEDDED_MEDIA_TO_JOB_PATH =
'/api/job/add_media_url'
GET_MEDIA_PATH =
'/api/job/media'
PERFORM_TRANSCRIPTION =
'/api/job/perform_transcription'
GET_TRANSCRIPT_PATH =
'/api/job/get_transcript'
GET_CAPTION_PATH =
'/api/job/get_caption'
GET_ELEMENT_LIST_PATH =
'/api/job/get_elementlist'
GET_LIST_OF_ELEMENT_LISTS_PATH =
'/api/job/list_elementlists'
AGGREGATE_STATISTICS_PATH =
'/api/job/aggregate_statistics'

Constants included from Cielo24

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url = 'https://api.cielo24.com') ⇒ Actions

Returns a new instance of Actions.



36
37
38
# File 'lib/cielo24/actions.rb', line 36

def initialize(base_url='https://api.cielo24.com')
  @base_url = base_url
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



13
14
15
# File 'lib/cielo24/actions.rb', line 13

def base_url
  @base_url
end

Instance Method Details

#add_media_to_job_embedded(api_token, job_id, media_url) ⇒ Object



153
154
155
# File 'lib/cielo24/actions.rb', line 153

def add_media_to_job_embedded(api_token, job_id, media_url)
  send_media_url(api_token, job_id, media_url, ADD_EMBEDDED_MEDIA_TO_JOB_PATH)
end

#add_media_to_job_file(api_token, job_id, media_file) ⇒ Object



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

def add_media_to_job_file(api_token, job_id, media_file)
  assert_argument(media_file, 'Media File')
  query_hash = init_job_req_dict(api_token, job_id)
  file_size = File.size(media_file.path)
  response = WebUtils.get_json(@base_url + ADD_MEDIA_TO_JOB_PATH, 'POST', nil, query_hash,
                               {'Content-Type' => 'video/mp4', 'Content-Length' => file_size}, media_file)
  response['TaskId']
end

#add_media_to_job_url(api_token, job_id, media_url) ⇒ Object



149
150
151
# File 'lib/cielo24/actions.rb', line 149

def add_media_to_job_url(api_token, job_id, media_url)
  send_media_url(api_token, job_id, media_url, ADD_MEDIA_TO_JOB_PATH)
end

#aggregate_statistics(api_token, metrics = nil, group_by = nil, start_date = nil, end_date = nil, sub_account = nil) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
# File 'lib/cielo24/actions.rb', line 217

def aggregate_statistics(api_token, metrics=nil, group_by=nil, start_date=nil, end_date=nil, =nil)
  query_hash = init_access_req_dict(api_token)
  query_hash[:metrics] = metrics.to_json unless metrics.nil?
  query_hash[:group_by] = group_by unless group_by.nil?
  query_hash[:start_date] = start_date unless start_date.nil?
  query_hash[:end_date] = end_date unless end_date.nil?
  # account_id parameter named sub_account for clarity
  query_hash[:account_id] =  unless .nil?
  response = WebUtils.get_json(@base_url + AGGREGATE_STATISTICS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  Mash.new(response)
end

#authorize_job(api_token, job_id) ⇒ Object



115
116
117
118
119
# File 'lib/cielo24/actions.rb', line 115

def authorize_job(api_token, job_id)
  query_hash = init_job_req_dict(api_token, job_id)
  # Nothing returned
  WebUtils.http_request(@base_url + AUTHORIZE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
end

#create_job(api_token, job_name = nil, language = Language::ENGLISH, external_id = nil, sub_account = nil) ⇒ Object

JOB CONTROL ###



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cielo24/actions.rb', line 102

def create_job(api_token, job_name=nil, language=Language::ENGLISH, external_id=nil, =nil)
  query_hash = init_access_req_dict(api_token)
  query_hash[:job_name] = job_name unless job_name.nil?
  query_hash[:language] = language unless language.nil?
  query_hash[:external_id] = external_id unless external_id.nil?
  # username parameter named sub_account for clarity
  query_hash[:username] =  unless .nil?

  response = WebUtils.get_json(@base_url + CREATE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  # Return a hash with JobId and TaskId
  Mash.new(response)
end

#delete_job(api_token, job_id) ⇒ Object



121
122
123
124
125
# File 'lib/cielo24/actions.rb', line 121

def delete_job(api_token, job_id)
  query_hash = init_job_req_dict(api_token, job_id)
  response = WebUtils.get_json(@base_url + DELETE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  response['TaskId']
end

#generate_api_key(api_token, sub_account = nil, force_new = false) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/cielo24/actions.rb', line 81

def generate_api_key(api_token, =nil, force_new=false)
  query_hash = init_access_req_dict(api_token)
  # account_id parameter named sub_account for clarity
  query_hash[:account_id] =  unless .nil?
  query_hash[:force_new] = force_new
  response = WebUtils.get_json(@base_url + GENERATE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  response['ApiKey']
end

#get_caption(api_token, job_id, caption_format, caption_options = nil) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/cielo24/actions.rb', line 191

def get_caption(api_token, job_id, caption_format, caption_options=nil)
  assert_argument(caption_format, 'Caption Format')
  query_hash = init_job_req_dict(api_token, job_id)
  query_hash[:caption_format] = caption_format
  query_hash.merge!(caption_options.get_hash) unless caption_options.nil?

  response = WebUtils.http_request(@base_url + GET_CAPTION_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
  if not caption_options.nil? and caption_options.build_url # If build_url is true
    JSON.parse(response)['CaptionUrl']
  else
    response # Else return raw caption text
  end
end

#get_element_list(api_token, job_id, elementlist_version = nil) ⇒ Object



205
206
207
208
209
210
# File 'lib/cielo24/actions.rb', line 205

def get_element_list(api_token, job_id, elementlist_version=nil)
  query_hash = init_job_req_dict(api_token, job_id)
  query_hash[:elementlist_version] = elementlist_version unless elementlist_version.nil?
  response = WebUtils.get_json(@base_url + GET_ELEMENT_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  Mash.new(response)
end

#get_job_info(api_token, job_id) ⇒ Object



127
128
129
130
131
# File 'lib/cielo24/actions.rb', line 127

def get_job_info(api_token, job_id)
  query_hash = init_job_req_dict(api_token, job_id)
  response = WebUtils.get_json(@base_url + GET_JOB_INFO_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  fix_job_info_offsets Mash.new(response)
end

#get_job_list(api_token, options = nil) ⇒ Object



133
134
135
136
137
138
# File 'lib/cielo24/actions.rb', line 133

def get_job_list(api_token, options=nil)
  query_hash = init_access_req_dict(api_token)
  query_hash.merge!(options.get_hash) unless options.nil?
  response = WebUtils.get_json(@base_url + GET_JOB_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  fix_job_list_offsets Mash.new(response)
end

#get_list_of_element_lists(api_token, job_id) ⇒ Object



212
213
214
215
# File 'lib/cielo24/actions.rb', line 212

def get_list_of_element_lists(api_token, job_id)
  query_hash = init_job_req_dict(api_token, job_id)
  WebUtils.get_json(@base_url + GET_LIST_OF_ELEMENT_LISTS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
end

#get_media(api_token, job_id) ⇒ Object



157
158
159
160
161
# File 'lib/cielo24/actions.rb', line 157

def get_media(api_token, job_id)
  query_hash = init_job_req_dict(api_token, job_id)
  response = WebUtils.get_json(@base_url + GET_MEDIA_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  response['MediaUrl']
end

#get_transcript(api_token, job_id, transcript_options = nil) ⇒ Object



184
185
186
187
188
189
# File 'lib/cielo24/actions.rb', line 184

def get_transcript(api_token, job_id, transcript_options=nil)
  query_hash = init_job_req_dict(api_token, job_id)
  query_hash.merge!(transcript_options.get_hash) unless transcript_options.nil?
  # Returns raw transcript text
  WebUtils.http_request(@base_url + GET_TRANSCRIPT_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
end

#login(username, password = nil, api_securekey = nil, use_headers = false) ⇒ Object

ACCESS CONTROL ###

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cielo24/actions.rb', line 44

def (username, password=nil, api_securekey=nil, use_headers=false)
  assert_argument(username, 'Username')
  raise ArgumentError.new('Password or API Secure Key must be supplied for login.') if (password.nil? and api_securekey.nil?)

  query_hash = init_version_dict
  headers = Hash.new

  if use_headers
    headers[:'x-auth-user'] = username
    headers[:'x-auth-password'] = password unless password.nil?
    headers[:'x-auth-securekey'] = api_securekey unless api_securekey.nil?
  else
    query_hash[:username] = username
    query_hash[:password] = password unless password.nil?
    query_hash[:securekey] = api_securekey unless api_securekey.nil?
  end

  response = WebUtils.get_json(@base_url + LOGIN_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash, headers)
  response['ApiToken']
end

#logout(api_token) ⇒ Object



65
66
67
68
69
# File 'lib/cielo24/actions.rb', line 65

def logout(api_token)
  query_hash = init_access_req_dict(api_token)
  # Nothing returned
  WebUtils.http_request(@base_url + LOGOUT_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
end

#perform_transcription(api_token, job_id, fidelity, priority = nil, callback_uri = nil, turnaround_hours = nil, target_language = nil, options = nil) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/cielo24/actions.rb', line 163

def perform_transcription(api_token,
                          job_id,
                          fidelity,
                          priority=nil,
                          callback_uri=nil,
                          turnaround_hours=nil,
                          target_language=nil,
                          options=nil)
  assert_argument(fidelity, 'Fidelity')
  query_hash = init_job_req_dict(api_token, job_id)
  query_hash[:transcription_fidelity] = fidelity
  query_hash[:priority] = priority unless priority.nil?
  query_hash[:callback_url] = callback_uri unless callback_uri.nil?
  query_hash[:turnaround_hours] = turnaround_hours unless turnaround_hours.nil?
  query_hash[:target_language] = target_language unless target_language.nil?
  query_hash[:options] = options.get_hash.to_json unless options.nil?

  response = WebUtils.get_json(@base_url + PERFORM_TRANSCRIPTION, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
  response['TaskId']
end

#remove_api_key(api_token, api_securekey) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/cielo24/actions.rb', line 90

def remove_api_key(api_token, api_securekey)
  assert_argument(api_securekey, 'API Secure Key')
  query_hash = init_access_req_dict(api_token)
  query_hash[:api_securekey] = api_securekey
  # Nothing returned
  WebUtils.http_request(@base_url + REMOVE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
end

#update_password(api_token, new_password, sub_account = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/cielo24/actions.rb', line 71

def update_password(api_token, new_password, =nil)
  assert_argument(new_password, 'New Password')
  query_hash = init_access_req_dict(api_token)
  query_hash[:new_password] = new_password
  # username parameter named sub_account for clarity
  query_hash[:username] =  unless .nil?
  # Nothing returned
  WebUtils.http_request(@base_url + UPDATE_PASSWORD_PATH, 'POST', WebUtils::BASIC_TIMEOUT, nil, nil, query_hash)
end