connect_client 0.1.6 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/connect_client/event.rb +29 -7
- data/lib/connect_client/version.rb +1 -1
- data/spec/connect_client/event_spec.rb +47 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4f5f77d9bb4be74830e2c2a4921f01ebcf6543b
|
4
|
+
data.tar.gz: 0c782098f59c0f62db7fcd46b40186d739417415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88c98456e2bd3446e63693f84bb5d00633be29a590e3cbdb4ea569d4f4ebc26ea3bade73667fce044d449a0fc26b8d586ee2f595043a4c6994cbe9fe1b85dec2
|
7
|
+
data.tar.gz: 65e8ab5e8bb0287257fe6e8395575a3d9945e57be2e3b22eebc1f1b09a31ac22be3f8dcbeff687e03fc49b81eedaf59ac946ab1b7227cd564e99390e9a7964a6
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ All of the documentation can be found at [http://docs.getconnect.io](http://docs
|
|
27
27
|
|
28
28
|
## Support
|
29
29
|
|
30
|
-
Get your questions answered and join in with the connect community at [http://docs.getconnect.io/
|
30
|
+
Get your questions answered and join in with the connect community at [http://docs.getconnect.io/discuss](http://docs.getconnect.io/discuss).
|
31
31
|
|
32
32
|
## Contributing
|
33
33
|
|
data/lib/connect_client/event.rb
CHANGED
@@ -10,13 +10,8 @@ module ConnectClient
|
|
10
10
|
attr_reader :data
|
11
11
|
|
12
12
|
def initialize(data)
|
13
|
-
event_data_defaults = { id: SecureRandom.uuid, timestamp: Time.now
|
14
|
-
@data = event_data_defaults.merge(data)
|
15
|
-
|
16
|
-
if (@data[:timestamp].respond_to? :iso8601)
|
17
|
-
@data[:timestamp] = @data[:timestamp].iso8601
|
18
|
-
end
|
19
|
-
|
13
|
+
event_data_defaults = { id: SecureRandom.uuid, timestamp: Time.now }
|
14
|
+
@data = map_iso_dates event_data_defaults.merge(data)
|
20
15
|
validate
|
21
16
|
end
|
22
17
|
|
@@ -33,6 +28,33 @@ module ConnectClient
|
|
33
28
|
def to_s
|
34
29
|
"Event Data: #{@data}"
|
35
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def map_iso_dates(data)
|
35
|
+
utc_converter = lambda { |value|
|
36
|
+
value_to_convert = value
|
37
|
+
map_utc = lambda { |value_item| utc_converter.call(value_item) }
|
38
|
+
|
39
|
+
return value_to_convert.map(&map_utc) if value_to_convert.respond_to? :map
|
40
|
+
|
41
|
+
value_to_convert = value_to_convert.to_time if value_to_convert.respond_to? :to_time
|
42
|
+
value_to_convert = value_to_convert.utc if value_to_convert.respond_to? :utc
|
43
|
+
value_to_convert = value_to_convert.iso8601 if value_to_convert.respond_to? :iso8601
|
44
|
+
|
45
|
+
value_to_convert
|
46
|
+
}
|
47
|
+
|
48
|
+
mappedData = data.map do |key, value|
|
49
|
+
if value.is_a? Hash
|
50
|
+
[key, map_iso_dates(value)]
|
51
|
+
else
|
52
|
+
[key, utc_converter.call(value)]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Hash[mappedData]
|
57
|
+
end
|
36
58
|
end
|
37
59
|
|
38
60
|
class EventDataValidationError < StandardError
|
@@ -44,4 +44,51 @@ describe ConnectClient::Event do
|
|
44
44
|
connect_event = ConnectClient::Event.new({foo: 'bar', timestamp: iso_date})
|
45
45
|
connect_event.data[:timestamp].must_equal iso_date
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should turn Time into iso8601" do
|
49
|
+
iso_date = '2015-07-01T04:07:57Z'
|
50
|
+
some_time = Time.parse('2015-07-01T05:07:57+01:00')
|
51
|
+
|
52
|
+
nested_hash_values = {
|
53
|
+
this: {
|
54
|
+
is: {
|
55
|
+
nested: [[some_time]]
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
connect_event = ConnectClient::Event.new(nested_hash_values)
|
61
|
+
connect_event.data[:this][:is][:nested][0][0].must_equal iso_date
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should turn DateTime into iso8601" do
|
65
|
+
iso_date = '2015-07-01T04:07:57Z'
|
66
|
+
some_date_time = DateTime.parse('2015-07-01T05:07:57+01:00')
|
67
|
+
|
68
|
+
nested_hash_values = {
|
69
|
+
this: {
|
70
|
+
is: {
|
71
|
+
nested: [[some_date_time]]
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
connect_event = ConnectClient::Event.new(nested_hash_values)
|
77
|
+
connect_event.data[:this][:is][:nested][0][0].must_equal iso_date
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should turn Date into iso8601" do
|
81
|
+
some_date = Date.parse('2015-07-01')
|
82
|
+
|
83
|
+
nested_hash_values = {
|
84
|
+
this: {
|
85
|
+
is: {
|
86
|
+
nested: [[some_date]]
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
connect_event = ConnectClient::Event.new(nested_hash_values)
|
92
|
+
connect_event.data[:this][:is][:nested][0][0].must_equal some_date.to_time.utc.iso8601
|
93
|
+
end
|
47
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connect_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Connect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|