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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3910cde43ca69d279bc776428ee893c9aaed70dd21d14bcf5f637ec108eef2b3
4
- data.tar.gz: 8c31590d887d1e68541e735c5ad0d302ecc96050f272a7c93bfcc68ea2926c08
3
+ metadata.gz: '08e5b5de58601bf69863d094eaddd9a8b412bb771314853182dff8d74d977bab'
4
+ data.tar.gz: 3818f35a6bb58cf00f94c87f7257cb7a698a58a919c80c5718473923e4c7f836
5
5
  SHA512:
6
- metadata.gz: dd9cf1d59cff551e7b5d3de3eab163303adcb61531d6c519db4b2e3a9f9b590bd5f9d4062c2744adb597985c3cd7db01a7f040af076b1352abf9373a2f84fe02
7
- data.tar.gz: 7cf8c7d0cb1dedaa6129148480372a7aa57401d51a2e46a36bcafe43191633e8cf2115defed9dbf0c04e6f0358f34d13f41c6c405d84f04d8f9cda44dd06f783
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
- internal_to_extenal: {
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(:internal_to_extenal)
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
+
@@ -13,5 +13,5 @@ module PayloadTranslator
13
13
  configuration
14
14
  end
15
15
 
16
- VERSION = "0.3.0"
16
+ VERSION = "0.4.0"
17
17
  end
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.3.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