faraday-encode_xml 0.1.0 → 0.2.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: 7250a2322ac3dac1774e8514f5acad9db83fe76eedb4f84609cc6e883d79d215
4
- data.tar.gz: b3c9dcaf39c8bff4a967a03367f62c740c682af8dd423821641dce66103df19a
3
+ metadata.gz: 31319300f2f2caadd574c957834b36822d699e9cfbe86d58bd5ab973d7af1e6a
4
+ data.tar.gz: 3d12939f46f9a0e990836e45f63b01e1ead88697e69f4cefba636083fc7e723f
5
5
  SHA512:
6
- metadata.gz: cd9e89c7aa7c30c4c4dd5dbae1930f8c2c7fe5581960a79b0c9cd574e9c8f27321b8c559095b3dc8029aadedb5444a2ecbb3956fec437dd45c064f3531280e7e
7
- data.tar.gz: e29bc25dc3425ef4db407ba3529fe1c353fb74a7d1a2c60c6099c1920fb907acb98e54c7dd5ca6b23de458179cc67990ca8f5d6c998b72709d87e157ea5685ea
6
+ metadata.gz: e17e4dfa0f180f6084a15af76829c4369d6505c936a0f9ac8d79aec1e17bfaa2f407799938e69d0d63d9542b08a6fcf8ad12bd69a1b0b258e9157a466c308eab
7
+ data.tar.gz: 889e4e528252ac6b0a39ca54c26929cf9a85a1868e7e849794ad9cda00ccf8a015bae9502f16921e147e11416bbb17719ee09aa6a4e317b1c3aa308b260dc7ff
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.2.0 (2021-10-20)
8
+
9
+ * Rework classes hierarchy to something more correct.
10
+ * Add usage example in README.
11
+
7
12
  ## 0.1.0 (2021-10-20)
8
13
 
9
14
  * Initial release.
data/README.md CHANGED
@@ -28,7 +28,22 @@ gem install faraday-encode_xml
28
28
  ```ruby
29
29
  require 'faraday/encode_xml'
30
30
 
31
- # TODO
31
+ connection = Faraday.new do |faraday|
32
+ ## This gem only encodes requests
33
+ faraday.request :xml
34
+
35
+ ## For responses deconding use `faraday_middleware` gem and such code:
36
+ # require 'faraday_middleware'
37
+ # faraday.response :xml
38
+
39
+ ## For example `httpbingo` responses as JSON, so let's enable it:
40
+ require 'faraday_middleware'
41
+ faraday.response :json
42
+ end
43
+
44
+ response = connection.post('https://httpbingo.org/post', { a: 1, b: 'foo', c: true })
45
+
46
+ puts response.body['data'] ## => <a>1</a><b>foo</b><c>true</c>
32
47
  ```
33
48
 
34
49
  ## Development
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'faraday'
4
+
3
5
  module Faraday
4
- class Middleware
6
+ module EncodeXML
5
7
  # Request middleware that encodes the body as XML.
6
8
  #
7
9
  # Processes only requests with matching Content-type or those without a type.
@@ -9,7 +11,7 @@ module Faraday
9
11
  # to XML MIME-type.
10
12
  #
11
13
  # Doesn't try to encode bodies that already are in string form.
12
- class EncodeXML < Faraday::Middleware
14
+ class Middleware < Faraday::Middleware
13
15
  CONTENT_TYPE = 'Content-Type'
14
16
  MIME_TYPE = 'application/xml'
15
17
 
@@ -44,10 +46,10 @@ module Faraday
44
46
 
45
47
  def process_request?(env)
46
48
  type = request_type(env)
47
- has_body?(env) && (type.empty? or type == MIME_TYPE)
49
+ body?(env) && (type.empty? or type == MIME_TYPE)
48
50
  end
49
51
 
50
- def has_body?(env)
52
+ def body?(env)
51
53
  (body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?)
52
54
  end
53
55
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module EncodeXML
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday/middleware/encode_xml'
4
- require 'faraday/encode_xml/version'
3
+ require_relative 'encode_xml/middleware'
4
+ require_relative 'encode_xml/version'
5
5
 
6
6
  module Faraday
7
7
  # This will be your middleware main module, though the actual middleware implementation will go
@@ -11,18 +11,18 @@ module Faraday
11
11
  # This step is totally optional, but it basically allows users to use a
12
12
  # custom symbol (in this case, `:my_middleware`), to use your middleware in their connections.
13
13
  # After calling this line, the following are both valid ways to set the middleware in a connection:
14
- # * conn.use Faraday::Middleware::MyMiddleware
14
+ # * conn.use Faraday::MyMiddleware::Middleware
15
15
  # * conn.use :my_middleware
16
16
  # Without this line, only the former method is valid.
17
- # Faraday::Middleware.register_middleware(encode_xml: Faraday::Middleware::EncodeXML)
17
+ # Faraday::Middleware.register_middleware(my_middleware: Faraday::MyMiddleware::Middleware)
18
18
 
19
19
  # Alternatively, you can register your middleware under Faraday::Request or Faraday::Response.
20
20
  # This will allow to load your middleware using the `request` or `response` methods respectively.
21
21
  #
22
22
  # Load middleware with conn.request :my_middleware
23
- Faraday::Request.register_middleware(xml: Faraday::Middleware::EncodeXML)
23
+ Faraday::Request.register_middleware(xml: Faraday::EncodeXML::Middleware)
24
24
 
25
25
  # Load middleware with conn.response :my_middleware
26
- # Faraday::Response.register_middleware(my_adapter: Faraday::Middleware::MyMiddleware)
26
+ # Faraday::Response.register_middleware(my_adapter: Faraday::MyMiddleware::Middleware)
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-encode_xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
@@ -205,15 +205,15 @@ files:
205
205
  - LICENSE.md
206
206
  - README.md
207
207
  - lib/faraday/encode_xml.rb
208
+ - lib/faraday/encode_xml/middleware.rb
208
209
  - lib/faraday/encode_xml/version.rb
209
- - lib/faraday/middleware/encode_xml.rb
210
210
  homepage: https://github.com/AlexWayfer/faraday-encode_xml
211
211
  licenses:
212
212
  - MIT
213
213
  metadata:
214
214
  bug_tracker_uri: https://github.com/AlexWayfer/faraday-encode_xml/issues
215
- changelog_uri: https://github.com/AlexWayfer/faraday-encode_xml/blob/v0.1.0/CHANGELOG.md
216
- documentation_uri: http://www.rubydoc.info/gems/faraday-encode_xml/0.1.0
215
+ changelog_uri: https://github.com/AlexWayfer/faraday-encode_xml/blob/v0.2.0/CHANGELOG.md
216
+ documentation_uri: http://www.rubydoc.info/gems/faraday-encode_xml/0.2.0
217
217
  homepage_uri: https://github.com/AlexWayfer/faraday-encode_xml
218
218
  source_code_uri: https://github.com/AlexWayfer/faraday-encode_xml
219
219
  wiki_uri: https://github.com/AlexWayfer/faraday-encode_xml/wiki