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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 777d8a0d7887223960c5ec14c5be37e7ceb50a8c7cd0abf33a070330f8c57a6d
4
- data.tar.gz: de298ca9f99ff381b232996351d33bcbc72ff8343d3ee8f8ab24cfdaf0f15c32
3
+ metadata.gz: 6d4bf34c7cdf9c459325cce7cc6c4571057eafa9d9d0f3937badf593a7edf4e0
4
+ data.tar.gz: 905237976614eba95b0a5ff2a5089c537ecc2d6f27c18e23a622e81d30ab7dba
5
5
  SHA512:
6
- metadata.gz: 1933ead1a4cf3a3de25e773c2e3787df00962ae2039a0182051b2dea3fee6abe029901ca3129b66fdf23129f65b309731061a8f3cd2af860e6c134e24e3dfe69
7
- data.tar.gz: 8dd8bcb901bbdcede8df0e077ffc20a1db75d2b9cb78cc973b9a5dbcb26ccd64b7721792c4ee91f2cda4753402a633e32fe16cd7706b15de584e697f0bdd0735
6
+ metadata.gz: a15dc8568124039c2297460033ab55447197358977523a2245d1e1470f44d0ce1f9602ff0998c8cb3f63a77c64bebf70ad3b20d5c8f956b0ffb32e270d175e15
7
+ data.tar.gz: 5805e36c1f2418ad1428eae2c1129feb54734fa321b0f5cbcc2e8cd34c2327f9a4189ec7888e6de3b031bbac353023f7749525a5772e5f265f3ed94d71d7f555
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## [Unreleased](https://github.com/gemhome/faraday-xml/compare/v0.1.0...main)
4
+
5
+ ## [0.1.0](https://github.com/gemhome/faraday-xml/blob/v0.1.0) (2023-01-12)
4
6
 
5
7
  * Initial release.
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
- # TODO
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
@@ -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, parser_options: nil, content_type: /\bxml$/, preserve_raw: false)
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("<success>true</success>")
45
+ parse('<success>true</success>')
36
46
  end
37
47
 
38
- def parser # rubocop:disable Metrics/MethodLength
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'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module XML
5
- VERSION = '0.0.1'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  end
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.response Faraday::XML::Response
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.1
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-12 00:00:00.000000000 Z
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.1/CHANGELOG.md
166
- documentation_uri: http://www.rubydoc.info/gems/faraday-xml/0.0.1
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