payload-translator 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/payload_translator/service_multiple.rb +18 -0
- data/lib/payload_translator.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08e5b5de58601bf69863d094eaddd9a8b412bb771314853182dff8d74d977bab'
|
4
|
+
data.tar.gz: 3818f35a6bb58cf00f94c87f7257cb7a698a58a919c80c5718473923e4c7f836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a0d7a728c6d7453e7e9c8b60ebe6e3efa704d7a03430cb48aa404fc85fb187e8dfd4a2153c880b10e13ab178f38ac6d02d3e95a43663246e1b82d333f55810
|
7
|
+
data.tar.gz: 680a16cdb5af7fb40296eef5763f5b5890d340f5cac55a7191718d477803006f10b71a48ac5ae9471203bca2653b4a575ef384b8f4d597bf873c19d10d2b287b
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ Store adapter configuration
|
|
94
94
|
```ruby
|
95
95
|
PayloadTranslator.configure do |config|
|
96
96
|
config.adapters_configurations = {
|
97
|
-
|
97
|
+
internal_to_external: {
|
98
98
|
"payload" => {
|
99
99
|
"id" => { "$field" => "_id" }
|
100
100
|
}
|
@@ -104,7 +104,22 @@ end
|
|
104
104
|
```
|
105
105
|
|
106
106
|
```ruby
|
107
|
-
translator = PayloadTranslator::Service.new(:
|
107
|
+
translator = PayloadTranslator::Service.new(:internal_to_external)
|
108
|
+
```
|
109
|
+
|
110
|
+
### Multiple translator
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
translator = PayloadTranslator::ServiceMultiple.new([:internal_to_external, :external_to_internal])
|
114
|
+
|
115
|
+
translated_response = translator.translate({"user_id" => 4 }) do |translated_payload|
|
116
|
+
response = Net::HTTP.post_form(
|
117
|
+
URI("https://jsonplaceholder.typicode.com/todos"),
|
118
|
+
translated_payload
|
119
|
+
).body
|
120
|
+
|
121
|
+
JSON.parse(response)
|
122
|
+
end
|
108
123
|
```
|
109
124
|
|
110
125
|
### Complex adapters
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PayloadTranslator
|
2
|
+
class ServiceMultiple < Service
|
3
|
+
attr_reader :translators
|
4
|
+
def initialize(adapter_configs_or_names, handlers: {}, formatters: {})
|
5
|
+
@translators = adapter_configs_or_names.map do |adapter_config_or_name|
|
6
|
+
Service.new(adapter_config_or_name, handlers: handlers, formatters: formatters)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def translate(payload, &block)
|
11
|
+
tranlated_payload = translators[0].translate(payload)
|
12
|
+
translators[1].translate(yield(tranlated_payload))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
data/lib/payload_translator.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payload-translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Savignano
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/payload_translator/field_resolver.rb
|
38
38
|
- lib/payload_translator/payload.rb
|
39
39
|
- lib/payload_translator/service.rb
|
40
|
+
- lib/payload_translator/service_multiple.rb
|
40
41
|
homepage: https://github.com/devmasx/payload-translator
|
41
42
|
licenses:
|
42
43
|
- MIT
|