cielo24 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cielo24.rb +9 -9
- data/lib/cielo24/actions.rb +287 -274
- data/lib/cielo24/enums.rb +153 -153
- data/lib/cielo24/options.rb +219 -219
- data/lib/cielo24/version.rb +3 -3
- data/lib/cielo24/web_utils.rb +101 -74
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed8f9b9f2fbd20edca9c999d8d3be9504304547d
|
4
|
+
data.tar.gz: 2d6127f5367b2778438c016c613de13d1ac6a8cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbce8d5f218e768aa47f2aa4a21f10baef1870cf09153f68175db86ed37b8afbab9f177c8c8234d0605eeec8e17efce24c34464e17dfa39a8dc2dc0ffc4a643e
|
7
|
+
data.tar.gz: 00c9011893639c32fe7c90717e6f9beab87422ab9b086c37aa37a596c3ac47fba129753992f00b54e0457206f5d6549316f2741cc70ad2eb4b250b1d79224764
|
data/lib/cielo24.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
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
|
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
10
|
end
|
data/lib/cielo24/actions.rb
CHANGED
@@ -1,275 +1,288 @@
|
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
headers[:'x-auth-
|
53
|
-
headers[:'x-auth-
|
54
|
-
|
55
|
-
|
56
|
-
query_hash[:
|
57
|
-
query_hash[:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
response
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
query_hash
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
query_hash = init_access_req_dict(api_token)
|
83
|
-
|
84
|
-
query_hash[:
|
85
|
-
|
86
|
-
response
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
query_hash
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
query_hash
|
104
|
-
query_hash[:
|
105
|
-
query_hash[:
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
response
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
query_hash
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
response
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
query_hash
|
173
|
-
query_hash[:
|
174
|
-
query_hash[:
|
175
|
-
query_hash[:
|
176
|
-
query_hash[:
|
177
|
-
query_hash[:
|
178
|
-
|
179
|
-
|
180
|
-
response
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
query_hash
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
query_hash
|
194
|
-
query_hash
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
query_hash
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
query_hash[:
|
225
|
-
response = WebUtils.get_json(@base_url +
|
226
|
-
response
|
227
|
-
end
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
def
|
235
|
-
assert_argument(
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
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
|
+
AGGREGATE_STATISTICS_PATH = '/api/job/aggregate_statistics'
|
35
|
+
|
36
|
+
def initialize(base_url='https://api.cielo24.com')
|
37
|
+
@base_url = base_url
|
38
|
+
end
|
39
|
+
|
40
|
+
######################
|
41
|
+
### ACCESS CONTROL ###
|
42
|
+
######################
|
43
|
+
|
44
|
+
def login(username, password=nil, api_securekey=nil, use_headers=false)
|
45
|
+
assert_argument(username, 'Username')
|
46
|
+
raise ArgumentError.new('Password or API Secure Key must be supplied for login.') if (password.nil? and api_securekey.nil?)
|
47
|
+
|
48
|
+
query_hash = init_version_dict
|
49
|
+
headers = Hash.new
|
50
|
+
|
51
|
+
if use_headers
|
52
|
+
headers[:'x-auth-user'] = username
|
53
|
+
headers[:'x-auth-password'] = password unless password.nil?
|
54
|
+
headers[:'x-auth-securekey'] = api_securekey unless api_securekey.nil?
|
55
|
+
else
|
56
|
+
query_hash[:username] = username
|
57
|
+
query_hash[:password] = password unless password.nil?
|
58
|
+
query_hash[:securekey] = api_securekey unless api_securekey.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
response = WebUtils.get_json(@base_url + LOGIN_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash, headers)
|
62
|
+
response['ApiToken']
|
63
|
+
end
|
64
|
+
|
65
|
+
def logout(api_token)
|
66
|
+
query_hash = init_access_req_dict(api_token)
|
67
|
+
# Nothing returned
|
68
|
+
WebUtils.http_request(@base_url + LOGOUT_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
def update_password(api_token, new_password, sub_account=nil)
|
72
|
+
assert_argument(new_password, 'New Password')
|
73
|
+
query_hash = init_access_req_dict(api_token)
|
74
|
+
query_hash[:new_password] = new_password
|
75
|
+
# username parameter named sub_account for clarity
|
76
|
+
query_hash[:username] = sub_account unless sub_account.nil?
|
77
|
+
# Nothing returned
|
78
|
+
WebUtils.http_request(@base_url + UPDATE_PASSWORD_PATH, 'POST', WebUtils::BASIC_TIMEOUT, nil, nil, query_hash)
|
79
|
+
end
|
80
|
+
|
81
|
+
def generate_api_key(api_token, sub_account=nil, force_new=false)
|
82
|
+
query_hash = init_access_req_dict(api_token)
|
83
|
+
# account_id parameter named sub_account for clarity
|
84
|
+
query_hash[:account_id] = sub_account unless sub_account.nil?
|
85
|
+
query_hash[:force_new] = force_new
|
86
|
+
response = WebUtils.get_json(@base_url + GENERATE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
87
|
+
response['ApiKey']
|
88
|
+
end
|
89
|
+
|
90
|
+
def remove_api_key(api_token, api_securekey)
|
91
|
+
assert_argument(api_securekey, 'API Secure Key')
|
92
|
+
query_hash = init_access_req_dict(api_token)
|
93
|
+
query_hash[:api_securekey] = api_securekey
|
94
|
+
# Nothing returned
|
95
|
+
WebUtils.http_request(@base_url + REMOVE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
96
|
+
end
|
97
|
+
|
98
|
+
###################
|
99
|
+
### JOB CONTROL ###
|
100
|
+
###################
|
101
|
+
|
102
|
+
def create_job(api_token, job_name=nil, language=Language::ENGLISH, external_id=nil, sub_account=nil)
|
103
|
+
query_hash = init_access_req_dict(api_token)
|
104
|
+
query_hash[:job_name] = job_name unless job_name.nil?
|
105
|
+
query_hash[:language] = language unless language.nil?
|
106
|
+
query_hash[:external_id] = external_id unless external_id.nil?
|
107
|
+
# username parameter named sub_account for clarity
|
108
|
+
query_hash[:username] = sub_account unless sub_account.nil?
|
109
|
+
|
110
|
+
response = WebUtils.get_json(@base_url + CREATE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
111
|
+
# Return a hash with JobId and TaskId
|
112
|
+
Mash.new(response)
|
113
|
+
end
|
114
|
+
|
115
|
+
def authorize_job(api_token, job_id)
|
116
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
117
|
+
# Nothing returned
|
118
|
+
WebUtils.http_request(@base_url + AUTHORIZE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
119
|
+
end
|
120
|
+
|
121
|
+
def delete_job(api_token, job_id)
|
122
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
123
|
+
response = WebUtils.get_json(@base_url + DELETE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
124
|
+
response['TaskId']
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_job_info(api_token, job_id)
|
128
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
129
|
+
response = WebUtils.get_json(@base_url + GET_JOB_INFO_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
130
|
+
fix_job_info_offsets Mash.new(response)
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_job_list(api_token, options=nil)
|
134
|
+
query_hash = init_access_req_dict(api_token)
|
135
|
+
query_hash.merge!(options.get_hash) unless options.nil?
|
136
|
+
response = WebUtils.get_json(@base_url + GET_JOB_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
137
|
+
fix_job_list_offsets Mash.new(response)
|
138
|
+
end
|
139
|
+
|
140
|
+
def add_media_to_job_file(api_token, job_id, media_file)
|
141
|
+
assert_argument(media_file, 'Media File')
|
142
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
143
|
+
file_size = File.size(media_file.path)
|
144
|
+
response = WebUtils.get_json(@base_url + ADD_MEDIA_TO_JOB_PATH, 'POST', nil, query_hash,
|
145
|
+
{'Content-Type' => 'video/mp4', 'Content-Length' => file_size}, media_file)
|
146
|
+
response['TaskId']
|
147
|
+
end
|
148
|
+
|
149
|
+
def add_media_to_job_url(api_token, job_id, media_url)
|
150
|
+
send_media_url(api_token, job_id, media_url, ADD_MEDIA_TO_JOB_PATH)
|
151
|
+
end
|
152
|
+
|
153
|
+
def add_media_to_job_embedded(api_token, job_id, media_url)
|
154
|
+
send_media_url(api_token, job_id, media_url, ADD_EMBEDDED_MEDIA_TO_JOB_PATH)
|
155
|
+
end
|
156
|
+
|
157
|
+
def get_media(api_token, job_id)
|
158
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
159
|
+
response = WebUtils.get_json(@base_url + GET_MEDIA_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
160
|
+
response['MediaUrl']
|
161
|
+
end
|
162
|
+
|
163
|
+
def perform_transcription(api_token,
|
164
|
+
job_id,
|
165
|
+
fidelity,
|
166
|
+
priority=nil,
|
167
|
+
callback_uri=nil,
|
168
|
+
turnaround_hours=nil,
|
169
|
+
target_language=nil,
|
170
|
+
options=nil)
|
171
|
+
assert_argument(fidelity, 'Fidelity')
|
172
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
173
|
+
query_hash[:transcription_fidelity] = fidelity
|
174
|
+
query_hash[:priority] = priority unless priority.nil?
|
175
|
+
query_hash[:callback_url] = callback_uri unless callback_uri.nil?
|
176
|
+
query_hash[:turnaround_hours] = turnaround_hours unless turnaround_hours.nil?
|
177
|
+
query_hash[:target_language] = target_language unless target_language.nil?
|
178
|
+
query_hash[:options] = options.get_hash.to_json unless options.nil?
|
179
|
+
|
180
|
+
response = WebUtils.get_json(@base_url + PERFORM_TRANSCRIPTION, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
181
|
+
response['TaskId']
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_transcript(api_token, job_id, transcript_options=nil)
|
185
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
186
|
+
query_hash.merge!(transcript_options.get_hash) unless transcript_options.nil?
|
187
|
+
# Returns raw transcript text
|
188
|
+
WebUtils.http_request(@base_url + GET_TRANSCRIPT_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
|
189
|
+
end
|
190
|
+
|
191
|
+
def get_caption(api_token, job_id, caption_format, caption_options=nil)
|
192
|
+
assert_argument(caption_format, 'Caption Format')
|
193
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
194
|
+
query_hash[:caption_format] = caption_format
|
195
|
+
query_hash.merge!(caption_options.get_hash) unless caption_options.nil?
|
196
|
+
|
197
|
+
response = WebUtils.http_request(@base_url + GET_CAPTION_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
|
198
|
+
if not caption_options.nil? and caption_options.build_url # If build_url is true
|
199
|
+
JSON.parse(response)['CaptionUrl']
|
200
|
+
else
|
201
|
+
response # Else return raw caption text
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def get_element_list(api_token, job_id, elementlist_version=nil)
|
206
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
207
|
+
query_hash[:elementlist_version] = elementlist_version unless elementlist_version.nil?
|
208
|
+
response = WebUtils.get_json(@base_url + GET_ELEMENT_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
209
|
+
Mash.new(response)
|
210
|
+
end
|
211
|
+
|
212
|
+
def get_list_of_element_lists(api_token, job_id)
|
213
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
214
|
+
WebUtils.get_json(@base_url + GET_LIST_OF_ELEMENT_LISTS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
215
|
+
end
|
216
|
+
|
217
|
+
def aggregate_statistics(api_token, metrics=nil, group_by=nil, start_date=nil, end_date=nil, sub_account=nil)
|
218
|
+
query_hash = init_access_req_dict(api_token)
|
219
|
+
query_hash[:metrics] = metrics.to_json unless metrics.nil?
|
220
|
+
query_hash[:group_by] = group_by unless group_by.nil?
|
221
|
+
query_hash[:start_date] = start_date unless start_date.nil?
|
222
|
+
query_hash[:end_date] = end_date unless end_date.nil?
|
223
|
+
# account_id parameter named sub_account for clarity
|
224
|
+
query_hash[:account_id] = sub_account unless sub_account.nil?
|
225
|
+
response = WebUtils.get_json(@base_url + AGGREGATE_STATISTICS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
226
|
+
Mash.new(response)
|
227
|
+
end
|
228
|
+
|
229
|
+
##############################
|
230
|
+
### PRIVATE HELPER METHODS ###
|
231
|
+
##############################
|
232
|
+
private
|
233
|
+
|
234
|
+
def send_media_url(api_token, job_id, media_url, path)
|
235
|
+
assert_argument(media_url, 'Media URL')
|
236
|
+
query_hash = init_job_req_dict(api_token, job_id)
|
237
|
+
query_hash[:media_url] = media_url
|
238
|
+
response = WebUtils.get_json(@base_url + path, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
|
239
|
+
response['TaskId']
|
240
|
+
end
|
241
|
+
|
242
|
+
def init_job_req_dict(api_token, job_id)
|
243
|
+
assert_argument(job_id, 'Job ID')
|
244
|
+
init_access_req_dict(api_token).merge({job_id: job_id})
|
245
|
+
end
|
246
|
+
|
247
|
+
def init_access_req_dict(api_token)
|
248
|
+
assert_argument(api_token, 'API Token')
|
249
|
+
init_version_dict.merge({api_token: api_token})
|
250
|
+
end
|
251
|
+
|
252
|
+
def init_version_dict
|
253
|
+
{v: API_VERSION}
|
254
|
+
end
|
255
|
+
|
256
|
+
def assert_argument(arg, arg_name)
|
257
|
+
if arg.nil?
|
258
|
+
raise ArgumentError.new('Invalid argument - ' + arg_name)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def fix_job_info_offsets(job_info)
|
263
|
+
top_keys = %w(CreationDate StartDate DueDate CompletedDate ReturnDate AuthorizationDate)
|
264
|
+
task_keys = %w(TaskRequestTime)
|
265
|
+
job_info = fix_offsets(job_info, top_keys)
|
266
|
+
job_info.Tasks = job_info.Tasks.map do |task_item|
|
267
|
+
fix_offsets(task_item, task_keys)
|
268
|
+
end
|
269
|
+
job_info
|
270
|
+
end
|
271
|
+
|
272
|
+
def fix_job_list_offsets(job_list)
|
273
|
+
keys = %w(CreationDate CreationTime StartDate StartTime DueDate CompletedDate
|
274
|
+
ReturnDate CompletedTime AuthorizationDate)
|
275
|
+
job_list.ActiveJobs = job_list.ActiveJobs.map do |job_item|
|
276
|
+
fix_offsets(job_item, keys)
|
277
|
+
end
|
278
|
+
job_list
|
279
|
+
end
|
280
|
+
|
281
|
+
def fix_offsets(hash, keys)
|
282
|
+
keys.each do |key|
|
283
|
+
hash[key] = WebUtils.to_utc(hash[key])
|
284
|
+
end
|
285
|
+
hash
|
286
|
+
end
|
287
|
+
end
|
275
288
|
end
|