cielo24 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cielo24.rb +10 -11
- data/lib/cielo24/actions.rb +249 -245
- data/lib/cielo24/enums.rb +153 -145
- data/lib/cielo24/options.rb +219 -219
- data/lib/cielo24/version.rb +2 -2
- data/lib/cielo24/web_utils.rb +63 -65
- metadata +32 -22
- checksums.yaml +0 -7
data/lib/cielo24.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
require 'cielo24/
|
2
|
-
require 'cielo24/
|
3
|
-
require 'cielo24/
|
4
|
-
require 'cielo24/
|
5
|
-
|
6
|
-
|
7
|
-
require '
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
1
|
+
require 'cielo24/actions'
|
2
|
+
require 'cielo24/enums'
|
3
|
+
require 'cielo24/options'
|
4
|
+
require 'cielo24/web_utils'
|
5
|
+
|
6
|
+
require 'hashie'
|
7
|
+
require 'httpclient'
|
8
|
+
|
9
|
+
module Cielo24
|
10
|
+
end
|
data/lib/cielo24/actions.rb
CHANGED
@@ -1,246 +1,250 @@
|
|
1
|
-
module Cielo24
|
2
|
-
class Actions
|
3
|
-
|
4
|
-
require 'uri'
|
5
|
-
require 'hashie'
|
6
|
-
require_relative 'web_utils'
|
7
|
-
require_relative 'enums'
|
8
|
-
|
9
|
-
include
|
10
|
-
include
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
LOGIN_PATH =
|
17
|
-
LOGOUT_PATH =
|
18
|
-
UPDATE_PASSWORD_PATH =
|
19
|
-
GENERATE_API_KEY_PATH =
|
20
|
-
REMOVE_API_KEY_PATH =
|
21
|
-
CREATE_JOB_PATH =
|
22
|
-
AUTHORIZE_JOB_PATH =
|
23
|
-
DELETE_JOB_PATH =
|
24
|
-
GET_JOB_INFO_PATH =
|
25
|
-
GET_JOB_LIST_PATH =
|
26
|
-
ADD_MEDIA_TO_JOB_PATH =
|
27
|
-
ADD_EMBEDDED_MEDIA_TO_JOB_PATH =
|
28
|
-
GET_MEDIA_PATH =
|
29
|
-
PERFORM_TRANSCRIPTION =
|
30
|
-
|
31
|
-
GET_CAPTION_PATH =
|
32
|
-
GET_ELEMENT_LIST_PATH =
|
33
|
-
GET_LIST_OF_ELEMENT_LISTS_PATH =
|
34
|
-
|
35
|
-
def initialize(base_url=
|
36
|
-
@base_url = base_url
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
headers[:'x-auth-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
query_hash
|
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
|
-
end
|
113
|
-
|
114
|
-
def
|
115
|
-
query_hash = init_job_req_dict(api_token, job_id)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
return
|
146
|
-
end
|
147
|
-
|
148
|
-
def
|
149
|
-
return send_media_url(api_token, job_id, media_url,
|
150
|
-
end
|
151
|
-
|
152
|
-
def
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
def
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
query_hash
|
185
|
-
|
186
|
-
|
187
|
-
return
|
188
|
-
end
|
189
|
-
|
190
|
-
def
|
191
|
-
|
192
|
-
query_hash
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
query_hash
|
213
|
-
|
214
|
-
return
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
{
|
238
|
-
end
|
239
|
-
|
240
|
-
def
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
1
|
+
module Cielo24
|
2
|
+
class Actions
|
3
|
+
|
4
|
+
require 'uri'
|
5
|
+
require 'hashie'
|
6
|
+
require_relative 'web_utils'
|
7
|
+
require_relative 'enums'
|
8
|
+
require 'json'
|
9
|
+
include Errno
|
10
|
+
include Hashie
|
11
|
+
include Cielo24
|
12
|
+
|
13
|
+
attr_accessor :base_url
|
14
|
+
|
15
|
+
API_VERSION = 1
|
16
|
+
LOGIN_PATH = '/api/account/login'
|
17
|
+
LOGOUT_PATH = '/api/account/logout'
|
18
|
+
UPDATE_PASSWORD_PATH = '/api/account/update_password'
|
19
|
+
GENERATE_API_KEY_PATH = '/api/account/generate_api_key'
|
20
|
+
REMOVE_API_KEY_PATH = '/api/account/remove_api_key'
|
21
|
+
CREATE_JOB_PATH = '/api/job/new'
|
22
|
+
AUTHORIZE_JOB_PATH = '/api/job/authorize'
|
23
|
+
DELETE_JOB_PATH = '/api/job/del'
|
24
|
+
GET_JOB_INFO_PATH = '/api/job/info'
|
25
|
+
GET_JOB_LIST_PATH = '/api/job/list'
|
26
|
+
ADD_MEDIA_TO_JOB_PATH = '/api/job/add_media'
|
27
|
+
ADD_EMBEDDED_MEDIA_TO_JOB_PATH = '/api/job/add_media_url'
|
28
|
+
GET_MEDIA_PATH = '/api/job/media'
|
29
|
+
PERFORM_TRANSCRIPTION = '/api/job/perform_transcription'
|
30
|
+
GET_TRANSCRIPT_PATH = '/api/job/get_transcript'
|
31
|
+
GET_CAPTION_PATH = '/api/job/get_caption'
|
32
|
+
GET_ELEMENT_LIST_PATH = '/api/job/get_elementlist'
|
33
|
+
GET_LIST_OF_ELEMENT_LISTS_PATH = '/api/job/list_elementlists'
|
34
|
+
|
35
|
+
def initialize(base_url='https://api.cielo24.com')
|
36
|
+
@base_url = base_url
|
37
|
+
end
|
38
|
+
|
39
|
+
######################
|
40
|
+
### ACCESS CONTROL ###
|
41
|
+
######################
|
42
|
+
|
43
|
+
def login(username, password=nil, api_securekey=nil, use_headers=false)
|
44
|
+
assert_argument(username, 'Username')
|
45
|
+
raise ArgumentError.new('Password or API Secure Key must be supplied for login.') if (password.nil? and api_securekey.nil?)
|
46
|
+
|
47
|
+
query_hash = init_version_dict
|
48
|
+
headers = Hash.new
|
49
|
+
|
50
|
+
if use_headers
|
51
|
+
headers[:'x-auth-user'] = username
|
52
|
+
headers[:'x-auth-password'] = password unless password.nil?
|
53
|
+
headers[:'x-auth-securekey'] = api_securekey unless api_securekey.nil?
|
54
|
+
else
|
55
|
+
query_hash[:username] = username
|
56
|
+
query_hash[:password] = password unless password.nil?
|
57
|
+
query_hash[:securekey] = api_securekey unless api_securekey.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
response = WebUtils.get_json(@base_url + LOGIN_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash, headers)
|
61
|
+
return response['ApiToken']
|
62
|
+
end
|
63
|
+
|
64
|
+
def logout(api_token)
|
65
|
+
query_hash = init_access_req_dict(api_token)
|
66
|
+
# Nothing returned
|
67
|
+
WebUtils.http_request(@base_url + LOGOUT_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_password(api_token, new_password, sub_account=nil)
|
71
|
+
assert_argument(new_password, 'New Password')
|
72
|
+
query_hash = init_access_req_dict(api_token)
|
73
|
+
query_hash[:new_password] = new_password
|
74
|
+
# username parameter named sub_account for clarity
|
75
|
+
query_hash[:username] = sub_account unless sub_account.nil?
|
76
|
+
# Nothing returned
|
77
|
+
WebUtils.http_request(@base_url + UPDATE_PASSWORD_PATH, 'POST', WebUtils::BASIC_TIMEOUT, nil, nil, query_hash)
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate_api_key(api_token, username, force_new=false)
|
81
|
+
assert_argument(username, 'Username')
|
82
|
+
query_hash = init_access_req_dict(api_token)
|
83
|
+
query_hash[:account_id] = username
|
84
|
+
query_hash[:force_new] = force_new
|
85
|
+
response = WebUtils.get_json(@base_url + GENERATE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
86
|
+
return response['ApiKey']
|
87
|
+
end
|
88
|
+
|
89
|
+
def remove_api_key(api_token, api_securekey)
|
90
|
+
assert_argument(api_securekey, 'API Secure Key')
|
91
|
+
query_hash = init_access_req_dict(api_token)
|
92
|
+
query_hash[:api_securekey] = api_securekey
|
93
|
+
# Nothing returned
|
94
|
+
WebUtils.http_request(@base_url + REMOVE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
95
|
+
end
|
96
|
+
|
97
|
+
###################
|
98
|
+
### JOB CONTROL ###
|
99
|
+
###################
|
100
|
+
|
101
|
+
def create_job(api_token, job_name=nil, language=Language::ENGLISH, external_id=nil, sub_account=nil)
|
102
|
+
query_hash = init_access_req_dict(api_token)
|
103
|
+
query_hash[:job_name] = job_name unless job_name.nil?
|
104
|
+
query_hash[:language] = language unless language.nil?
|
105
|
+
query_hash[:external_id] = external_id unless external_id.nil?
|
106
|
+
# username parameter named sub_account for clarity
|
107
|
+
query_hash[:username] = sub_account unless sub_account.nil?
|
108
|
+
|
109
|
+
response = WebUtils.get_json(@base_url + CREATE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
110
|
+
# Return a hash with JobId and TaskId
|
111
|
+
return Mash.new(response)
|
112
|
+
end
|
113
|
+
|
114
|
+
def authorize_job(api_token, job_id)
|
115
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
116
|
+
# Nothing returned
|
117
|
+
WebUtils.http_request(@base_url + AUTHORIZE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
118
|
+
end
|
119
|
+
|
120
|
+
def delete_job(api_token, job_id)
|
121
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
122
|
+
response = WebUtils.get_json(@base_url + DELETE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
123
|
+
return response['TaskId']
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_job_info(api_token, job_id)
|
127
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
128
|
+
response = WebUtils.get_json(@base_url + GET_JOB_INFO_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
129
|
+
return Mash.new(response)
|
130
|
+
end
|
131
|
+
|
132
|
+
def get_job_list(api_token, options=nil)
|
133
|
+
query_hash = init_access_req_dict(api_token)
|
134
|
+
query_hash.merge!(options.get_hash) unless options.nil?
|
135
|
+
response = WebUtils.get_json(@base_url + GET_JOB_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
136
|
+
return Mash.new(response)
|
137
|
+
end
|
138
|
+
|
139
|
+
def add_media_to_job_file(api_token, job_id, media_file)
|
140
|
+
assert_argument(media_file, 'Media File')
|
141
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
142
|
+
file_size = File.size(media_file.path)
|
143
|
+
response = WebUtils.get_json(@base_url + ADD_MEDIA_TO_JOB_PATH, 'POST', nil, query_hash,
|
144
|
+
{'Content-Type' => 'video/mp4', 'Content-Length' => file_size}, media_file)
|
145
|
+
return response['TaskId']
|
146
|
+
end
|
147
|
+
|
148
|
+
def add_media_to_job_url(api_token, job_id, media_url)
|
149
|
+
return send_media_url(api_token, job_id, media_url, ADD_MEDIA_TO_JOB_PATH)
|
150
|
+
end
|
151
|
+
|
152
|
+
def add_media_to_job_embedded(api_token, job_id, media_url)
|
153
|
+
return send_media_url(api_token, job_id, media_url, ADD_EMBEDDED_MEDIA_TO_JOB_PATH)
|
154
|
+
end
|
155
|
+
|
156
|
+
def get_media(api_token, job_id)
|
157
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
158
|
+
response = WebUtils.get_json(@base_url + GET_MEDIA_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
159
|
+
return response['MediaUrl']
|
160
|
+
end
|
161
|
+
|
162
|
+
def perform_transcription(api_token,
|
163
|
+
job_id,
|
164
|
+
fidelity,
|
165
|
+
priority=nil,
|
166
|
+
callback_uri=nil,
|
167
|
+
turnaround_hours=nil,
|
168
|
+
target_language=nil,
|
169
|
+
options=nil)
|
170
|
+
assert_argument(fidelity, 'Fidelity')
|
171
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
172
|
+
query_hash[:transcription_fidelity] = fidelity
|
173
|
+
query_hash[:priority] = priority unless priority.nil?
|
174
|
+
query_hash[:callback_url] = callback_uri unless callback_uri.nil?
|
175
|
+
query_hash[:turnaround_hours] = turnaround_hours unless turnaround_hours.nil?
|
176
|
+
query_hash[:target_language] = target_language unless target_language.nil?
|
177
|
+
query_hash[:options] = options.get_hash.to_json unless options.nil?
|
178
|
+
|
179
|
+
response = WebUtils.get_json(@base_url + PERFORM_TRANSCRIPTION, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
180
|
+
return response['TaskId']
|
181
|
+
end
|
182
|
+
|
183
|
+
def get_transcript(api_token, job_id, transcript_options=nil)
|
184
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
185
|
+
query_hash.merge!(transcript_options.get_hash) unless transcript_options.nil?
|
186
|
+
# Returns raw transcript text
|
187
|
+
return WebUtils.http_request(@base_url + GET_TRANSCRIPT_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_caption(api_token, job_id, caption_format, caption_options=nil)
|
191
|
+
assert_argument(caption_format, 'Caption Format')
|
192
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
193
|
+
query_hash[:caption_format] = caption_format
|
194
|
+
query_hash.merge!(caption_options.get_hash) unless caption_options.nil?
|
195
|
+
|
196
|
+
response = WebUtils.http_request(@base_url + GET_CAPTION_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
|
197
|
+
if not caption_options.nil? and caption_options.build_url # If build_url is true
|
198
|
+
return JSON.parse(response)['CaptionUrl']
|
199
|
+
else
|
200
|
+
return response # Else return raw caption text
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def get_element_list(api_token, job_id, elementlist_version=nil)
|
205
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
206
|
+
query_hash[:elementlist_version] = elementlist_version unless elementlist_version.nil?
|
207
|
+
response = WebUtils.get_json(@base_url + GET_ELEMENT_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
208
|
+
return Mash.new(response)
|
209
|
+
end
|
210
|
+
|
211
|
+
def get_list_of_element_lists(api_token, job_id)
|
212
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
213
|
+
response = WebUtils.get_json(@base_url + GET_LIST_OF_ELEMENT_LISTS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
214
|
+
return response
|
215
|
+
end
|
216
|
+
|
217
|
+
##############################
|
218
|
+
### PRIVATE HELPER METHODS ###
|
219
|
+
##############################
|
220
|
+
private
|
221
|
+
|
222
|
+
def send_media_url(api_token, job_id, media_url, path)
|
223
|
+
assert_argument(media_url, 'Media URL')
|
224
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
225
|
+
query_hash[:media_url] = media_url
|
226
|
+
response = WebUtils.get_json(@base_url + path, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
227
|
+
return response['TaskId']
|
228
|
+
end
|
229
|
+
|
230
|
+
def init_job_req_dict(api_token, job_id)
|
231
|
+
assert_argument(job_id, 'Job ID')
|
232
|
+
init_access_req_dict(api_token).merge({job_id: job_id})
|
233
|
+
end
|
234
|
+
|
235
|
+
def init_access_req_dict(api_token)
|
236
|
+
assert_argument(api_token, 'API Token')
|
237
|
+
init_version_dict.merge({api_token: api_token})
|
238
|
+
end
|
239
|
+
|
240
|
+
def init_version_dict()
|
241
|
+
{v: API_VERSION}
|
242
|
+
end
|
243
|
+
|
244
|
+
def assert_argument(arg, arg_name)
|
245
|
+
if arg.nil?
|
246
|
+
raise ArgumentError.new('Invalid argument - ' + arg_name)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
246
250
|
end
|