Class: Cielo24::Actions
- Inherits:
-
Object
- Object
- Cielo24::Actions
- 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'
Constants included from Cielo24
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
Instance Method Summary collapse
- #add_media_to_job_embedded(api_token, job_id, media_url) ⇒ Object
- #add_media_to_job_file(api_token, job_id, media_file) ⇒ Object
- #add_media_to_job_url(api_token, job_id, media_url) ⇒ Object
- #authorize_job(api_token, job_id) ⇒ Object
-
#create_job(api_token, job_name = nil, language = Language::ENGLISH, external_id = nil, sub_account = nil) ⇒ Object
JOB CONTROL ###.
- #delete_job(api_token, job_id) ⇒ Object
- #generate_api_key(api_token, username, force_new = false) ⇒ Object
- #get_caption(api_token, job_id, caption_format, caption_options = nil) ⇒ Object
- #get_element_list(api_token, job_id, elementlist_version = nil) ⇒ Object
- #get_job_info(api_token, job_id) ⇒ Object
- #get_job_list(api_token, options = nil) ⇒ Object
- #get_list_of_element_lists(api_token, job_id) ⇒ Object
- #get_media(api_token, job_id) ⇒ Object
- #get_transcript(api_token, job_id, transcript_options = nil) ⇒ Object
-
#initialize(base_url = 'https://api.cielo24.com') ⇒ Actions
constructor
A new instance of Actions.
-
#login(username, password = nil, api_securekey = nil, use_headers = false) ⇒ Object
ACCESS CONTROL ###.
- #logout(api_token) ⇒ Object
- #perform_transcription(api_token, job_id, fidelity, priority = nil, callback_uri = nil, turnaround_hours = nil, target_language = nil, options = nil) ⇒ Object
- #remove_api_key(api_token, api_securekey) ⇒ Object
- #update_password(api_token, new_password, sub_account = nil) ⇒ Object
Constructor Details
#initialize(base_url = 'https://api.cielo24.com') ⇒ Actions
Returns a new instance of Actions.
35 36 37 |
# File 'lib/cielo24/actions.rb', line 35 def initialize(base_url='https://api.cielo24.com') @base_url = base_url end |
Instance Attribute Details
#base_url ⇒ Object
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
152 153 154 |
# File 'lib/cielo24/actions.rb', line 152 def (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
139 140 141 142 143 144 145 146 |
# File 'lib/cielo24/actions.rb', line 139 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
148 149 150 |
# File 'lib/cielo24/actions.rb', line 148 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 |
#authorize_job(api_token, job_id) ⇒ Object
114 115 116 117 118 |
# File 'lib/cielo24/actions.rb', line 114 def (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 ###
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cielo24/actions.rb', line 101 def create_job(api_token, job_name=nil, language=Language::ENGLISH, external_id=nil, sub_account=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] = sub_account unless sub_account.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
120 121 122 123 124 |
# File 'lib/cielo24/actions.rb', line 120 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, username, force_new = false) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/cielo24/actions.rb', line 80 def generate_api_key(api_token, username, force_new=false) assert_argument(username, 'Username') query_hash = init_access_req_dict(api_token) query_hash[:account_id] = username 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
190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cielo24/actions.rb', line 190 def get_caption(api_token, job_id, caption_format, =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!(.get_hash) unless .nil? response = WebUtils.http_request(@base_url + GET_CAPTION_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash) if not .nil? and .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
204 205 206 207 208 209 |
# File 'lib/cielo24/actions.rb', line 204 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
126 127 128 129 130 |
# File 'lib/cielo24/actions.rb', line 126 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
132 133 134 135 136 137 |
# File 'lib/cielo24/actions.rb', line 132 def get_job_list(api_token, =nil) query_hash = init_access_req_dict(api_token) query_hash.merge!(.get_hash) unless .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
211 212 213 214 |
# File 'lib/cielo24/actions.rb', line 211 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
156 157 158 159 160 |
# File 'lib/cielo24/actions.rb', line 156 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
183 184 185 186 187 188 |
# File 'lib/cielo24/actions.rb', line 183 def get_transcript(api_token, job_id, =nil) query_hash = init_job_req_dict(api_token, job_id) query_hash.merge!(.get_hash) unless .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 ###
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cielo24/actions.rb', line 43 def login(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
64 65 66 67 68 |
# File 'lib/cielo24/actions.rb', line 64 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
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cielo24/actions.rb', line 162 def perform_transcription(api_token, job_id, fidelity, priority=nil, callback_uri=nil, turnaround_hours=nil, target_language=nil, =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] = .get_hash.to_json unless .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
89 90 91 92 93 94 95 |
# File 'lib/cielo24/actions.rb', line 89 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
70 71 72 73 74 75 76 77 78 |
# File 'lib/cielo24/actions.rb', line 70 def update_password(api_token, new_password, sub_account=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] = sub_account unless sub_account.nil? # Nothing returned WebUtils.http_request(@base_url + UPDATE_PASSWORD_PATH, 'POST', WebUtils::BASIC_TIMEOUT, nil, nil, query_hash) end |