faraday-decode_xml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f3cdd8b85bd65538e376adc19b33cc4bc050d06e8433a5591db529ca7400031
4
+ data.tar.gz: d6103409bf9c1c364529cd4e9eb9c52e9e9328433f78b5f343c4d642043ed94a
5
+ SHA512:
6
+ metadata.gz: 97cf6349802faa8f89bf2d305efc396bf0be3778e3b02fd75f70404d536d59bc5ed7f9a0b0c7eb448d3a6c0ccab5e7e1def944ec1004ffd2c25d17d1f7febb68
7
+ data.tar.gz: bcef664a14c72703d4c6c0dd6207193069b8a5adb9b90f25b310545e5fe86d25b7199f486d6adf0aad9aa252397fc692287b2f9b473e63c0d6a6e3feec90100f
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ * Initial release.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Spencer Oberstadt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Faraday Decode XML
2
+
3
+ [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/soberstadt/faraday-decode_xml/ci)](https://github.com/soberstadt/faraday-decode_xml/actions?query=branch%3Amain)
4
+ [![Gem](https://img.shields.io/gem/v/faraday-decode_xml.svg?style=flat-square)](https://rubygems.org/gems/faraday-decode_xml)
5
+ [![License](https://img.shields.io/github/license/soberstadt/faraday-decode_xml.svg?style=flat-square)](LICENSE.md)
6
+
7
+ Faraday middleware for decoding XML requests.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'faraday-decode_xml'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```shell
20
+ bundle install
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```shell
26
+ gem install faraday-decode_xml
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require 'faraday/decode_xml'
33
+
34
+ Faraday.new do |faraday|
35
+ faraday.response :xml
36
+ end
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies.
42
+
43
+ Then, run `bin/test` to run the tests.
44
+
45
+ To install this gem onto your local machine, run `rake build`.
46
+
47
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`.
48
+ See how it works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/soberstadt/faraday-decode_xml).
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'multi_xml'
4
+
5
+ module Faraday
6
+ module DecodeXML
7
+ # Faraday middleware for decoding XML requests.
8
+ class Middleware < Faraday::Middleware
9
+ # @param env [Faraday::Env] the environment of the response being processed.
10
+ def on_complete(env)
11
+ process_response(env) if process_response_type?(response_type(env)) && parse_response?(env)
12
+ end
13
+
14
+ private
15
+
16
+ def process_response(env)
17
+ env.body = parse(env.body)
18
+ rescue Faraday::ParsingError => e
19
+ raise Faraday::ParsingError.new(e.wrapped_exception, env[:response])
20
+ end
21
+
22
+ def parse(body)
23
+ ::MultiXml.parse(body, {})
24
+ rescue StandardError, SyntaxError => e
25
+ raise e if e.is_a?(SyntaxError)
26
+
27
+ raise Faraday::ParsingError, e
28
+ end
29
+
30
+ def response_type(env)
31
+ env.response_headers['Content-Type'].to_s.split(';', 2).first
32
+ end
33
+
34
+ def process_response_type?(type)
35
+ type == 'application/xml'
36
+ end
37
+
38
+ def parse_response?(env)
39
+ env.body.respond_to? :to_str
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module DecodeXML
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'decode_xml/middleware'
4
+ require_relative 'decode_xml/version'
5
+
6
+ module Faraday
7
+ # This will be your middleware main module, though the actual middleware implementation will go
8
+ # into Faraday::DecodeXML::Middleware for the correct namespacing.
9
+ module DecodeXML
10
+ # Faraday allows you to register your middleware for easier configuration.
11
+ # This step is totally optional, but it basically allows users to use a
12
+ # custom symbol (in this case, `:decode_xml`), to use your middleware in their connections.
13
+ # After calling this line, the following are both valid ways to set the middleware in a connection:
14
+ # * conn.use Faraday::DecodeXML::Middleware
15
+ # * conn.use :decode_xml
16
+ # Without this line, only the former method is valid.
17
+ Faraday::Response.register_middleware(xml: Faraday::DecodeXML::Middleware)
18
+
19
+ # Alternatively, you can register your middleware under Faraday::Request or Faraday::Response.
20
+ # This will allow to load your middleware using the `request` or `response` methods respectively.
21
+ #
22
+ # Load middleware with conn.request :decode_xml
23
+ # Faraday::Request.register_middleware(decode_xml: Faraday::DecodeXML::Middleware)
24
+ #
25
+ # Load middleware with conn.response :decode_xml
26
+ # Faraday::Response.register_middleware(decode_xml: Faraday::DecodeXML::Middleware)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-decode_xml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Spencer Oberstadt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_xml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.21.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.21.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.25.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.25.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-packaging
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
153
+ description: 'Faraday middleware for decoding XML requests.
154
+
155
+ '
156
+ email:
157
+ - spencer.oberstadt@anedot.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - CHANGELOG.md
163
+ - LICENSE.md
164
+ - README.md
165
+ - lib/faraday/decode_xml.rb
166
+ - lib/faraday/decode_xml/middleware.rb
167
+ - lib/faraday/decode_xml/version.rb
168
+ homepage: https://github.com/soberstadt/faraday-decode_xml
169
+ licenses:
170
+ - MIT
171
+ metadata:
172
+ bug_tracker_uri: https://github.com/soberstadt/faraday-decode_xml/issues
173
+ changelog_uri: https://github.com/soberstadt/faraday-decode_xml/blob/v0.1.0/CHANGELOG.md
174
+ documentation_uri: http://www.rubydoc.info/gems/faraday-decode_xml/0.1.0
175
+ homepage_uri: https://github.com/soberstadt/faraday-decode_xml
176
+ rubygems_mfa_required: 'true'
177
+ source_code_uri: https://github.com/soberstadt/faraday-decode_xml
178
+ wiki_uri: https://github.com/soberstadt/faraday-decode_xml/wiki
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '2.5'
188
+ - - "<"
189
+ - !ruby/object:Gem::Version
190
+ version: '4'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubygems_version: 3.2.30
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Faraday middleware for decoding XML requests
201
+ test_files: []