faraday-xml 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.md +10 -1
- data/lib/faraday/xml/response.rb +17 -17
- data/lib/faraday/xml/version.rb +1 -1
- data/lib/faraday/xml.rb +1 -1
- 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: 6d4bf34c7cdf9c459325cce7cc6c4571057eafa9d9d0f3937badf593a7edf4e0
|
4
|
+
data.tar.gz: 905237976614eba95b0a5ff2a5089c537ecc2d6f27c18e23a622e81d30ab7dba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a15dc8568124039c2297460033ab55447197358977523a2245d1e1470f44d0ce1f9602ff0998c8cb3f63a77c64bebf70ad3b20d5c8f956b0ffb32e270d175e15
|
7
|
+
data.tar.gz: 5805e36c1f2418ad1428eae2c1129feb54734fa321b0f5cbcc2e8cd34c2327f9a4189ec7888e6de3b031bbac353023f7749525a5772e5f265f3ed94d71d7f555
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,9 +29,18 @@ gem install faraday-xml
|
|
29
29
|
## Usage
|
30
30
|
|
31
31
|
```ruby
|
32
|
+
require 'faraday'
|
32
33
|
require 'faraday/xml'
|
33
34
|
|
34
|
-
|
35
|
+
conn = Faraday.new do |builder|
|
36
|
+
builder.headers.update(
|
37
|
+
"Accept" => "application/xml",
|
38
|
+
"Content-Type" => "application/xml;charset=UTF-8",
|
39
|
+
)
|
40
|
+
|
41
|
+
# or builder.use Faraday::XML::Response
|
42
|
+
builder.response :xml # decode response bodies from XML
|
43
|
+
end
|
35
44
|
```
|
36
45
|
|
37
46
|
## Development
|
data/lib/faraday/xml/response.rb
CHANGED
@@ -4,18 +4,28 @@ module Faraday
|
|
4
4
|
module XML
|
5
5
|
# Parse response bodies as XML
|
6
6
|
class Response < Faraday::Middleware
|
7
|
-
def initialize(app = nil,
|
7
|
+
def initialize(app = nil, options = {})
|
8
8
|
super(app)
|
9
|
-
@parser_options = parser_options
|
10
|
-
@content_types = Array(content_type)
|
11
|
-
@preserve_raw = preserve_raw
|
9
|
+
@parser_options = options[:parser_options]
|
10
|
+
@content_types = Array(options.fetch(:content_type, /\bxml$/))
|
11
|
+
@preserve_raw = options.fetch(:preserve_raw, false)
|
12
12
|
end
|
13
|
+
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
|
13
14
|
|
14
15
|
# @param env [Faraday::Env] the environment of the response being processed.
|
15
16
|
def on_complete(env)
|
16
17
|
process_response(env) if parse_response?(env)
|
17
18
|
end
|
18
19
|
|
20
|
+
def parser
|
21
|
+
@parser ||= nil
|
22
|
+
if @parser.nil?
|
23
|
+
@parser = set_parser
|
24
|
+
@parser && test_parser
|
25
|
+
end
|
26
|
+
@parser or raise 'Missing dependencies ActiveSupport::XmlMini or MultiXml'
|
27
|
+
end
|
28
|
+
|
19
29
|
private
|
20
30
|
|
21
31
|
def process_response(env)
|
@@ -32,19 +42,10 @@ module Faraday
|
|
32
42
|
end
|
33
43
|
|
34
44
|
def test_parser
|
35
|
-
parse(
|
45
|
+
parse('<success>true</success>')
|
36
46
|
end
|
37
47
|
|
38
|
-
def
|
39
|
-
@parser ||= nil
|
40
|
-
if @parser.nil?
|
41
|
-
@parser = set_parser
|
42
|
-
@parser && test_parser
|
43
|
-
end
|
44
|
-
@parser or raise 'Missing dependencies ActiveSupport::XmlMini or MultiXml'
|
45
|
-
end
|
46
|
-
|
47
|
-
def set_parser
|
48
|
+
def set_parser # rubocop:disable Metrics/MethodLength
|
48
49
|
@parser ||=
|
49
50
|
begin
|
50
51
|
require 'multi_xml'
|
@@ -53,10 +54,9 @@ module Faraday
|
|
53
54
|
end
|
54
55
|
rescue LoadError # rubocop:disable Lint/SuppressedException
|
55
56
|
end
|
56
|
-
@parser ||=
|
57
|
+
@parser ||= # rubocop:disable Naming/MemoizedInstanceVariableName
|
57
58
|
begin
|
58
59
|
require 'active_support'
|
59
|
-
# require 'active_support/isolated_execution_state'
|
60
60
|
require 'active_support/xml_mini'
|
61
61
|
require 'active_support/core_ext/hash/conversions'
|
62
62
|
require 'active_support/core_ext/array/conversions'
|
data/lib/faraday/xml/version.rb
CHANGED
data/lib/faraday/xml.rb
CHANGED
@@ -7,7 +7,7 @@ module Faraday
|
|
7
7
|
# The Faraday::XML middleware main module
|
8
8
|
module XML
|
9
9
|
# Load middleware with
|
10
|
-
# conn.
|
10
|
+
# conn.use Faraday::XML::Response
|
11
11
|
# or
|
12
12
|
# conn.response :xml
|
13
13
|
Faraday::Response.register_middleware(xml: Faraday::XML::Response)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Fleischer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -162,8 +162,8 @@ licenses:
|
|
162
162
|
- MIT
|
163
163
|
metadata:
|
164
164
|
bug_tracker_uri: https://github.com/gemhome/faraday-xml/issues
|
165
|
-
changelog_uri: https://github.com/gemhome/faraday-xml/blob/v0.0
|
166
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-xml/0.0
|
165
|
+
changelog_uri: https://github.com/gemhome/faraday-xml/blob/v0.1.0/CHANGELOG.md
|
166
|
+
documentation_uri: http://www.rubydoc.info/gems/faraday-xml/0.1.0
|
167
167
|
homepage_uri: https://github.com/gemhome/faraday-xml
|
168
168
|
rubygems_mfa_required: 'true'
|
169
169
|
source_code_uri: https://github.com/gemhome/faraday-xml
|