Skip to content

Commit a3c4639

Browse files
committed
Merge pull request #3 from Cielo24/feature/CLC-1055
Incorrect time format in ruby client
2 parents d086c31 + 609579a commit a3c4639

10 files changed

+61
-24
lines changed

cielo24_cli/cielo24-cli-0.0.5.gem

-7.5 KB
Binary file not shown.

cielo24_cli/cielo24-cli-0.0.6.gem

7.5 KB
Binary file not shown.

cielo24_cli/cielo24_cli.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
2020

2121
spec.add_development_dependency 'bundler', '~> 1.10.6'
2222

23-
spec.add_dependency 'cielo24', '~> 0.0.15'
23+
spec.add_dependency 'cielo24', '~> 0.0.16'
2424
spec.add_dependency 'thor', '~> 0.19.1'
2525
end
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cielo24CLI
2-
VERSION = '0.0.5'
3-
end
2+
VERSION = '0.0.6'
3+
end

cielo24_gem/cielo24-0.0.15.gem

-9.5 KB
Binary file not shown.

cielo24_gem/cielo24-0.0.16.gem

10 KB
Binary file not shown.

cielo24_gem/cielo24.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
2222

2323
spec.add_dependency 'httpclient', '~> 2.6.0.1'
2424
spec.add_dependency 'hashie', '~> 3.4.2'
25+
spec.add_dependency 'tzinfo', '~> 1.2.2'
2526
end

cielo24_gem/lib/cielo24/actions.rb

+44-19
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def login(username, password=nil, api_securekey=nil, use_headers=false)
5858
end
5959

6060
response = WebUtils.get_json(@base_url + LOGIN_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash, headers)
61-
return response['ApiToken']
61+
response['ApiToken']
6262
end
6363

6464
def logout(api_token)
@@ -83,7 +83,7 @@ def generate_api_key(api_token, username, force_new=false)
8383
query_hash[:account_id] = username
8484
query_hash[:force_new] = force_new
8585
response = WebUtils.get_json(@base_url + GENERATE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
86-
return response['ApiKey']
86+
response['ApiKey']
8787
end
8888

8989
def remove_api_key(api_token, api_securekey)
@@ -108,7 +108,7 @@ def create_job(api_token, job_name=nil, language=Language::ENGLISH, external_id=
108108

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

114114
def authorize_job(api_token, job_id)
@@ -120,20 +120,20 @@ def authorize_job(api_token, job_id)
120120
def delete_job(api_token, job_id)
121121
query_hash = init_job_req_dict(api_token, job_id)
122122
response = WebUtils.get_json(@base_url + DELETE_JOB_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
123-
return response['TaskId']
123+
response['TaskId']
124124
end
125125

126126
def get_job_info(api_token, job_id)
127127
query_hash = init_job_req_dict(api_token, job_id)
128128
response = WebUtils.get_json(@base_url + GET_JOB_INFO_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
129-
return Mash.new(response)
129+
fix_job_info_offsets Mash.new(response)
130130
end
131131

132132
def get_job_list(api_token, options=nil)
133133
query_hash = init_access_req_dict(api_token)
134134
query_hash.merge!(options.get_hash) unless options.nil?
135135
response = WebUtils.get_json(@base_url + GET_JOB_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
136-
return Mash.new(response)
136+
fix_job_list_offsets Mash.new(response)
137137
end
138138

139139
def add_media_to_job_file(api_token, job_id, media_file)
@@ -142,21 +142,21 @@ def add_media_to_job_file(api_token, job_id, media_file)
142142
file_size = File.size(media_file.path)
143143
response = WebUtils.get_json(@base_url + ADD_MEDIA_TO_JOB_PATH, 'POST', nil, query_hash,
144144
{'Content-Type' => 'video/mp4', 'Content-Length' => file_size}, media_file)
145-
return response['TaskId']
145+
response['TaskId']
146146
end
147147

148148
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)
149+
send_media_url(api_token, job_id, media_url, ADD_MEDIA_TO_JOB_PATH)
150150
end
151151

152152
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)
153+
send_media_url(api_token, job_id, media_url, ADD_EMBEDDED_MEDIA_TO_JOB_PATH)
154154
end
155155

156156
def get_media(api_token, job_id)
157157
query_hash = init_job_req_dict(api_token, job_id)
158158
response = WebUtils.get_json(@base_url + GET_MEDIA_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
159-
return response['MediaUrl']
159+
response['MediaUrl']
160160
end
161161

162162
def perform_transcription(api_token,
@@ -177,14 +177,14 @@ def perform_transcription(api_token,
177177
query_hash[:options] = options.get_hash.to_json unless options.nil?
178178

179179
response = WebUtils.get_json(@base_url + PERFORM_TRANSCRIPTION, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
180-
return response['TaskId']
180+
response['TaskId']
181181
end
182182

183183
def get_transcript(api_token, job_id, transcript_options=nil)
184184
query_hash = init_job_req_dict(api_token, job_id)
185185
query_hash.merge!(transcript_options.get_hash) unless transcript_options.nil?
186186
# Returns raw transcript text
187-
return WebUtils.http_request(@base_url + GET_TRANSCRIPT_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
187+
WebUtils.http_request(@base_url + GET_TRANSCRIPT_PATH, 'GET', WebUtils::DOWNLOAD_TIMEOUT, query_hash)
188188
end
189189

190190
def get_caption(api_token, job_id, caption_format, caption_options=nil)
@@ -195,23 +195,22 @@ def get_caption(api_token, job_id, caption_format, caption_options=nil)
195195

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

204204
def get_element_list(api_token, job_id, elementlist_version=nil)
205205
query_hash = init_job_req_dict(api_token, job_id)
206206
query_hash[:elementlist_version] = elementlist_version unless elementlist_version.nil?
207207
response = WebUtils.get_json(@base_url + GET_ELEMENT_LIST_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
208-
return Mash.new(response)
208+
Mash.new(response)
209209
end
210210

211211
def get_list_of_element_lists(api_token, job_id)
212212
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
213+
WebUtils.get_json(@base_url + GET_LIST_OF_ELEMENT_LISTS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
215214
end
216215

217216
##############################
@@ -224,7 +223,7 @@ def send_media_url(api_token, job_id, media_url, path)
224223
query_hash = init_job_req_dict(api_token, job_id)
225224
query_hash[:media_url] = media_url
226225
response = WebUtils.get_json(@base_url + path, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
227-
return response['TaskId']
226+
response['TaskId']
228227
end
229228

230229
def init_job_req_dict(api_token, job_id)
@@ -237,7 +236,7 @@ def init_access_req_dict(api_token)
237236
init_version_dict.merge({api_token: api_token})
238237
end
239238

240-
def init_version_dict()
239+
def init_version_dict
241240
{v: API_VERSION}
242241
end
243242

@@ -246,5 +245,31 @@ def assert_argument(arg, arg_name)
246245
raise ArgumentError.new('Invalid argument - ' + arg_name)
247246
end
248247
end
248+
249+
def fix_job_info_offsets(job_info)
250+
top_keys = %w(CreationDate StartDate DueDate CompletedDate ReturnDate AuthorizationDate)
251+
task_keys = %w(TaskRequestTime)
252+
job_info = fix_offsets(job_info, top_keys)
253+
job_info.Tasks = job_info.Tasks.map do |task_item|
254+
fix_offsets(task_item, task_keys)
255+
end
256+
job_info
257+
end
258+
259+
def fix_job_list_offsets(job_list)
260+
keys = %w(CreationDate CreationTime StartDate StartTime DueDate CompletedDate
261+
ReturnDate CompletedTime AuthorizationDate)
262+
job_list.ActiveJobs = job_list.ActiveJobs.map do |job_item|
263+
fix_offsets(job_item, keys)
264+
end
265+
job_list
266+
end
267+
268+
def fix_offsets(hash, keys)
269+
keys.each do |key|
270+
hash[key] = WebUtils.to_utc(hash[key])
271+
end
272+
hash
273+
end
249274
end
250275
end

cielo24_gem/lib/cielo24/version.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cielo24
2-
VERSION = '0.0.15'
3-
end
2+
VERSION = '0.0.16'
3+
end

cielo24_gem/lib/cielo24/web_utils.rb

+11
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ class WebUtils
55
require 'httpclient'
66
require 'timeout'
77
require 'logger'
8+
require 'tzinfo'
89
include JSON
910

1011
BASIC_TIMEOUT = 60 # seconds (1 minute)
1112
DOWNLOAD_TIMEOUT = 300 # seconds (5 minutes)
1213
UPLOAD_TIMEOUT = 60*60*24*7 # seconds (1 week)
14+
SERVER_TZ = 'America/Los_Angeles'
1315
LOGGER = Logger.new(STDOUT)
1416

1517
def self.get_json(uri, method, timeout, query=nil, headers=nil, body=nil)
@@ -42,6 +44,15 @@ def self.http_request(uri, method, timeout, query=nil, headers=nil, body=nil)
4244
raise TimeoutError.new('The HTTP session has timed out.')
4345
end
4446
end
47+
48+
def self.to_utc(s)
49+
return s if s.empty?
50+
tz = TZInfo::Timezone.get(SERVER_TZ)
51+
local = DateTime.iso8601(s)
52+
utc = tz.local_to_utc local
53+
format = '%Y-%m-%dT%H:%M:%S.%L%z' # iso8601 with milliseconds
54+
utc.strftime(format)
55+
end
4556
end
4657

4758
class WebError < StandardError

0 commit comments

Comments
 (0)