newgistics 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/newgistics.rb +3 -0
- data/lib/newgistics/manifest_slip.rb +3 -3
- data/lib/newgistics/time_parsers.rb +11 -0
- data/lib/newgistics/time_parsers/american_datetime.rb +30 -0
- data/lib/newgistics/time_parsers/iso8601.rb +25 -0
- data/lib/newgistics/timestamp.rb +5 -21
- data/lib/newgistics/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64dcab77c965fb14c316ac1c00dc5ac9fac14824
|
4
|
+
data.tar.gz: 6dc6b36a937c9cb77c8cb62b564d5600ae3f6e28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aed4d616111d0261f497d74f0f9d1edc3f333069670b896c60ff1afaf0d4b9a74172fedb335af6676fd8617529c7c087fa6d9abb39f32dde00ba2a8004b946c
|
7
|
+
data.tar.gz: a4480045ea1b18c1915e929996e39df8c3b485d85ef376f8bb53db0c4e49d682590e82a073186e0f9f2e6f7c5d1ea16dd59c1c8faa0f9293f2c54821f5c781fa
|
data/lib/newgistics.rb
CHANGED
@@ -3,6 +3,9 @@ require "nokogiri"
|
|
3
3
|
require "faraday"
|
4
4
|
require "tzinfo"
|
5
5
|
|
6
|
+
require "newgistics/time_parsers"
|
7
|
+
require "newgistics/time_parsers/iso8601"
|
8
|
+
require "newgistics/time_parsers/american_datetime"
|
6
9
|
require "newgistics/api"
|
7
10
|
require "newgistics/default_logger"
|
8
11
|
require "newgistics/configuration"
|
@@ -2,10 +2,10 @@ module Newgistics
|
|
2
2
|
class ManifestSlip
|
3
3
|
include Newgistics::Model
|
4
4
|
|
5
|
-
attribute :actual_arrival_date, Timestamp
|
6
|
-
attribute :actual_received_date, Timestamp
|
5
|
+
attribute :actual_arrival_date, Timestamp, parser: TimeParsers.american_datetime
|
6
|
+
attribute :actual_received_date, Timestamp, parser: TimeParsers.american_datetime
|
7
7
|
attribute :carton_count, Integer
|
8
|
-
attribute :created_date, Timestamp
|
8
|
+
attribute :created_date, Timestamp, parser: TimeParsers.american_datetime
|
9
9
|
attribute :estimated_arrival_date, Date
|
10
10
|
attribute :manifest_id, String
|
11
11
|
attribute :manifest_name, String
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Newgistics
|
2
|
+
module TimeParsers
|
3
|
+
class AmericanDatetime
|
4
|
+
DATE_FORMAT = "%m/%d/%Y %I:%M %p %z".freeze
|
5
|
+
|
6
|
+
def parse(string)
|
7
|
+
date = date_with_timezone(string)
|
8
|
+
parse_date(date, string)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def date_with_timezone(string)
|
14
|
+
return string if includes_timezone?(string)
|
15
|
+
"#{string} #{Newgistics.time_zone.utc_offset}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def includes_timezone?(string)
|
19
|
+
string =~ /[+-]\d{2}:\d{2}\z/
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_date(date, fallback)
|
23
|
+
Time.strptime(date, DATE_FORMAT).
|
24
|
+
getlocal(Newgistics.local_time_zone.utc_offset)
|
25
|
+
rescue ArgumentError
|
26
|
+
fallback
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Newgistics
|
2
|
+
module TimeParsers
|
3
|
+
class ISO8601
|
4
|
+
def parse(string)
|
5
|
+
date = string.dup
|
6
|
+
unless includes_timezone?(string)
|
7
|
+
date << Newgistics.time_zone.utc_offset
|
8
|
+
end
|
9
|
+
parse_date(date, string)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def parse_date(date, fallback)
|
15
|
+
Time.iso8601(date).getlocal(Newgistics.local_time_zone.utc_offset)
|
16
|
+
rescue ArgumentError
|
17
|
+
fallback
|
18
|
+
end
|
19
|
+
|
20
|
+
def includes_timezone?(value)
|
21
|
+
value =~ /Z|[+-]\d{2}:\d{2}\z/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/newgistics/timestamp.rb
CHANGED
@@ -1,31 +1,15 @@
|
|
1
1
|
module Newgistics
|
2
2
|
class Timestamp < Virtus::Attribute
|
3
|
+
accept_options :parser
|
4
|
+
|
5
|
+
parser TimeParsers.iso8601
|
6
|
+
|
3
7
|
def coerce(value)
|
4
8
|
if value.is_a? String
|
5
|
-
|
9
|
+
options[:parser].parse(value)
|
6
10
|
else
|
7
11
|
value
|
8
12
|
end
|
9
13
|
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def coerce_string(value)
|
14
|
-
date = value.dup
|
15
|
-
unless includes_timezone?(value)
|
16
|
-
date << Newgistics.time_zone.utc_offset
|
17
|
-
end
|
18
|
-
parse_date(date, value)
|
19
|
-
end
|
20
|
-
|
21
|
-
def parse_date(date, fallback)
|
22
|
-
Time.iso8601(date).getlocal(Newgistics.local_time_zone.utc_offset)
|
23
|
-
rescue ArgumentError
|
24
|
-
fallback
|
25
|
-
end
|
26
|
-
|
27
|
-
def includes_timezone?(value)
|
28
|
-
value =~ /Z|[+-]\d{2}:\d{2}\z/
|
29
|
-
end
|
30
14
|
end
|
31
15
|
end
|
data/lib/newgistics/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newgistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Martinez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-09-
|
12
|
+
date: 2018-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: virtus
|
@@ -236,6 +236,9 @@ files:
|
|
236
236
|
- lib/newgistics/shipment_cancellation.rb
|
237
237
|
- lib/newgistics/shipment_update.rb
|
238
238
|
- lib/newgistics/string_helper.rb
|
239
|
+
- lib/newgistics/time_parsers.rb
|
240
|
+
- lib/newgistics/time_parsers/american_datetime.rb
|
241
|
+
- lib/newgistics/time_parsers/iso8601.rb
|
239
242
|
- lib/newgistics/time_zone.rb
|
240
243
|
- lib/newgistics/timestamp.rb
|
241
244
|
- lib/newgistics/version.rb
|