Skip to content

Commit 1d430e4

Browse files
committed
fix(orbility): time parsing
1 parent 3298423 commit 1d430e4

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

drivers/orbility/parking_rest_api.cr

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,25 @@ class Orbility::ParkingRestAPI < PlaceOS::Driver
3131
macro check(response, klass)
3232
%response = {{ response }}
3333
raise "error: #{%response.status}\n#{%response.body}" unless %response.success?
34-
%klass = {{klass}}.from_json(%response.body)
34+
%klass = begin
35+
{{klass}}.from_json(%response.body)
36+
rescue error
37+
logger.error { "error parsing response: #{%response.body}" }
38+
raise error
39+
end
3540
raise "error: #{%klass.to_pretty_json}" unless %klass.success?
3641
%klass
3742
end
3843

3944
macro basic_check(response)
4045
%response = {{ response }}
4146
raise "error: #{%response.status}\n#{%response.body}" unless %response.success?
42-
%conf = Confirmation.from_json(%response.body)
47+
%conf = begin
48+
Confirmation.from_json(%response.body)
49+
rescue error
50+
logger.error { "error parsing response: #{%response.body}" }
51+
raise error
52+
end
4353
if !%conf.success?
4454
logger.info { "basic request failed with: #{%conf.to_pretty_json}" }
4555
end

drivers/orbility/parking_rest_api_models.cr

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ module Orbility
5454

5555
module CreatedConverter
5656
FORMAT = "%Y-%m-%dT%H:%M:%S.%L"
57-
FORMAT_ALT = "%Y-%m-%dT%H:%M:%S"
5857

5958
def self.from_json(value : JSON::PullParser) : Time
59+
str = value.read_string
60+
61+
# the milliseconds may not exist or are not padded
62+
result = str.split('.', 2)
63+
timemain = result[0]
64+
if result.size == 1
65+
split = "000"
66+
else
67+
split = result[1].ljust(3, '0')
68+
end
69+
str = "#{timemain}.#{split}"
6070
Time.parse(value.read_string, FORMAT, Time::Location::UTC)
61-
rescue Time::Format::Error
62-
Time.parse(value.read_string, FORMAT_ALT, Time::Location::UTC)
6371
end
6472

6573
def self.to_json(value : Time, json : JSON::Builder) : Nil

drivers/orbility/parking_user_sync.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Orbility::ParkingUserSync < PlaceOS::Driver
1010

1111
descriptive_name "Orbility User Sync"
1212
generic_name :OrbilityUserSync
13-
description %(Grabs users from active directory, looks up swipe card numbers from gallagher and syncs these to orbility)
13+
description %(Grabs users from active directory, looks up swipe card numbers from gallagher and syncs these to orbility.)
1414

1515
default_settings({
1616
# Azure user group we want to sync

0 commit comments

Comments
 (0)