freddy 0.7.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb758155f28cc40f204be751ada8692d6c1a27d6
4
- data.tar.gz: af55428a80ba31588ccca3f3b768d42cf3ea7a23
3
+ metadata.gz: 69cad8d1350331740b83e02e458032607d66c7d5
4
+ data.tar.gz: ea149450c8ec4845362c231d3359e6798ac63d5d
5
5
  SHA512:
6
- metadata.gz: '0088398853c34ecc5ee1264393e65f5a97b41346c9b9d64b74f167e8e481bda6033fee0084008b14c21e7c114fa3e0485785ffa465b5a4e73991638fa1011cb3'
7
- data.tar.gz: '095cdbe724d8a489a2c86353f32c684a454ab5ee73f3fa789f27efd3a18f92d63a332fa28e57fcb8802b59efdd16fbe7cf44c9a9dfcb2c1e51091cee1ee4c5ca'
6
+ metadata.gz: c33ce48d240d3a4810e2972deb4fc95ad13445bb100f3936adc7ec8c728629f6a6df3821db2c53559b2d5d032c464f7e77b08cb4821cc0160390426767fa8185
7
+ data.tar.gz: 333c02f7d0769d9dc3b017c45fcda3d209e1672ce56a47b36f550e73bdf943cef954e51b22942a768b338c3b8a3fd4f4ad1d7d14c0e92d883e140320e76984b0
data/freddy.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  else
9
9
  spec.name = "freddy"
10
10
  end
11
- spec.version = '0.7.2'
11
+ spec.version = '1.0.0'
12
12
  spec.authors = ["Salemove TechMovers"]
13
13
  spec.email = ["techmovers@salemove.com"]
14
14
  spec.description = %q{Messaging API}
@@ -27,7 +27,7 @@ class Freddy
27
27
  end
28
28
 
29
29
  def self.dump(payload)
30
- Oj.dump(payload, mode: :compat)
30
+ Oj.dump(payload, mode: :compat, time_format: :xmlschema)
31
31
  end
32
32
  end
33
33
 
@@ -39,7 +39,21 @@ class Freddy
39
39
  end
40
40
 
41
41
  def self.dump(payload)
42
- JSON.dump(payload)
42
+ JSON.dump(serialize_time_objects(payload))
43
+ end
44
+
45
+ def self.serialize_time_objects(object)
46
+ if object.is_a?(Hash)
47
+ object.reduce({}) do |hash, (key, value)|
48
+ hash.merge(key => serialize_time_objects(value))
49
+ end
50
+ elsif object.is_a?(Array)
51
+ object.map(&method(:serialize_time_objects))
52
+ elsif object.is_a?(Time) || object.is_a?(Date)
53
+ object.iso8601
54
+ else
55
+ object
56
+ end
43
57
  end
44
58
  end
45
59
  end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freddy::Payload do
4
+ describe '#dump' do
5
+ it 'serializes time objects as iso8601 format strings' do
6
+ expect(dump(time: Time.utc(2016, 1, 4, 20, 18)))
7
+ .to eq('{"time":"2016-01-04T20:18:00Z"}')
8
+ end
9
+
10
+ it 'serializes time objects in an array as iso8601 format strings' do
11
+ expect(dump(time: [Time.utc(2016, 1, 4, 20, 18)]))
12
+ .to eq('{"time":["2016-01-04T20:18:00Z"]}')
13
+ end
14
+
15
+ it 'serializes time objects in a nested hash as iso8601 format strings' do
16
+ expect(dump(x: {time: Time.utc(2016, 1, 4, 20, 18)}))
17
+ .to eq('{"x":{"time":"2016-01-04T20:18:00Z"}}')
18
+ end
19
+
20
+ it 'serializes date objects as iso8601 format strings' do
21
+ expect(dump(date: Date.new(2016, 1, 4)))
22
+ .to eq('{"date":"2016-01-04"}')
23
+ end
24
+
25
+ it 'serializes date objects in an array as iso8601 format strings' do
26
+ expect(dump(date: [Date.new(2016, 1, 4)]))
27
+ .to eq('{"date":["2016-01-04"]}')
28
+ end
29
+
30
+ it 'serializes date objects in a nested hash as iso8601 format strings' do
31
+ expect(dump(x: {date: Date.new(2016, 1, 4)}))
32
+ .to eq('{"x":{"date":"2016-01-04"}}')
33
+ end
34
+
35
+ it 'serializes datetime objects as iso8601 format strings' do
36
+ expect(dump(datetime: DateTime.new(2016, 1, 4, 20, 18)))
37
+ .to eq('{"datetime":"2016-01-04T20:18:00+00:00"}')
38
+ end
39
+
40
+ it 'serializes datetime objects in an array as iso8601 format strings' do
41
+ expect(dump(datetime: [DateTime.new(2016, 1, 4, 20, 18)]))
42
+ .to eq('{"datetime":["2016-01-04T20:18:00+00:00"]}')
43
+ end
44
+
45
+ it 'serializes datetime objects in a nested hash as iso8601 format strings' do
46
+ expect(dump(x: {datetime: DateTime.new(2016, 1, 4, 20, 18)}))
47
+ .to eq('{"x":{"datetime":"2016-01-04T20:18:00+00:00"}}')
48
+ end
49
+
50
+ def dump(payload)
51
+ described_class.dump(payload)
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove TechMovers
@@ -124,6 +124,7 @@ files:
124
124
  - spec/freddy/error_response_spec.rb
125
125
  - spec/freddy/freddy_spec.rb
126
126
  - spec/freddy/message_handler_spec.rb
127
+ - spec/freddy/payload_spec.rb
127
128
  - spec/freddy/responder_handler_spec.rb
128
129
  - spec/freddy/sync_response_container_spec.rb
129
130
  - spec/integration/concurrency_spec.rb
@@ -160,6 +161,7 @@ test_files:
160
161
  - spec/freddy/error_response_spec.rb
161
162
  - spec/freddy/freddy_spec.rb
162
163
  - spec/freddy/message_handler_spec.rb
164
+ - spec/freddy/payload_spec.rb
163
165
  - spec/freddy/responder_handler_spec.rb
164
166
  - spec/freddy/sync_response_container_spec.rb
165
167
  - spec/integration/concurrency_spec.rb