faraday-encode_xml 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +16 -1
- data/lib/faraday/{middleware/encode_xml.rb → encode_xml/middleware.rb} +6 -4
- data/lib/faraday/encode_xml/version.rb +1 -1
- data/lib/faraday/encode_xml.rb +6 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31319300f2f2caadd574c957834b36822d699e9cfbe86d58bd5ab973d7af1e6a
|
4
|
+
data.tar.gz: 3d12939f46f9a0e990836e45f63b01e1ead88697e69f4cefba636083fc7e723f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e17e4dfa0f180f6084a15af76829c4369d6505c936a0f9ac8d79aec1e17bfaa2f407799938e69d0d63d9542b08a6fcf8ad12bd69a1b0b258e9157a466c308eab
|
7
|
+
data.tar.gz: 889e4e528252ac6b0a39ca54c26929cf9a85a1868e7e849794ad9cda00ccf8a015bae9502f16921e147e11416bbb17719ee09aa6a4e317b1c3aa308b260dc7ff
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
-
|
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
|
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
|
-
|
49
|
+
body?(env) && (type.empty? or type == MIME_TYPE)
|
48
50
|
end
|
49
51
|
|
50
|
-
def
|
52
|
+
def body?(env)
|
51
53
|
(body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?)
|
52
54
|
end
|
53
55
|
|
data/lib/faraday/encode_xml.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
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(
|
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
|
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
|
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.
|
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.
|
216
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-encode_xml/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
|