faraday-encode_xml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.md +21 -0
- data/README.md +51 -0
- data/lib/faraday/encode_xml/version.rb +7 -0
- data/lib/faraday/encode_xml.rb +28 -0
- data/lib/faraday/middleware/encode_xml.rb +61 -0
- metadata +242 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7250a2322ac3dac1774e8514f5acad9db83fe76eedb4f84609cc6e883d79d215
|
4
|
+
data.tar.gz: b3c9dcaf39c8bff4a967a03367f62c740c682af8dd423821641dce66103df19a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd9e89c7aa7c30c4c4dd5dbae1930f8c2c7fe5581960a79b0c9cd574e9c8f27321b8c559095b3dc8029aadedb5444a2ecbb3956fec437dd45c064f3531280e7e
|
7
|
+
data.tar.gz: e29bc25dc3425ef4db407ba3529fe1c353fb74a7d1a2c60c6099c1920fb907acb98e54c7dd5ca6b23de458179cc67990ca8f5d6c998b72709d87e157ea5685ea
|
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Alexander Popov
|
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,51 @@
|
|
1
|
+
# Faraday Encode XML
|
2
|
+
|
3
|
+
This repo is a [Faraday][https://github.com/lostisland/faraday] middleware for encoding requests as XML.
|
4
|
+
Faraday is an HTTP client library that provides a common interface for making requests.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'faraday-encode_xml'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```shell
|
17
|
+
bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```shell
|
23
|
+
gem install faraday-encode_xml
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'faraday/encode_xml'
|
30
|
+
|
31
|
+
# TODO
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bundle install` to install dependencies.
|
37
|
+
|
38
|
+
Then, run `bundle exec rspec` to run the tests.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `toys gem install`.
|
41
|
+
|
42
|
+
To release a new version, run `toys gem release %version%`.
|
43
|
+
See how it works [here](https://github.com/AlexWayfer/gem_toys#release).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/faraday-encode_xml).
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday/middleware/encode_xml'
|
4
|
+
require 'faraday/encode_xml/version'
|
5
|
+
|
6
|
+
module Faraday
|
7
|
+
# This will be your middleware main module, though the actual middleware implementation will go
|
8
|
+
# into Faraday::Middleware::MyMiddleware for the correct namespacing.
|
9
|
+
module EncodeXML
|
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, `:my_middleware`), 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::Middleware::MyMiddleware
|
15
|
+
# * conn.use :my_middleware
|
16
|
+
# Without this line, only the former method is valid.
|
17
|
+
# Faraday::Middleware.register_middleware(encode_xml: Faraday::Middleware::EncodeXML)
|
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 :my_middleware
|
23
|
+
Faraday::Request.register_middleware(xml: Faraday::Middleware::EncodeXML)
|
24
|
+
|
25
|
+
# Load middleware with conn.response :my_middleware
|
26
|
+
# Faraday::Response.register_middleware(my_adapter: Faraday::Middleware::MyMiddleware)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Middleware
|
5
|
+
# Request middleware that encodes the body as XML.
|
6
|
+
#
|
7
|
+
# Processes only requests with matching Content-type or those without a type.
|
8
|
+
# If a request doesn't have a type but has a body, it sets the Content-type
|
9
|
+
# to XML MIME-type.
|
10
|
+
#
|
11
|
+
# Doesn't try to encode bodies that already are in string form.
|
12
|
+
class EncodeXML < Faraday::Middleware
|
13
|
+
CONTENT_TYPE = 'Content-Type'
|
14
|
+
MIME_TYPE = 'application/xml'
|
15
|
+
|
16
|
+
dependency do
|
17
|
+
require 'gyoku' unless defined?(::Gyoku)
|
18
|
+
end
|
19
|
+
|
20
|
+
# This method will be called when the request is being prepared.
|
21
|
+
# You can alter it as you like, accessing things like request_body, request_headers, and more.
|
22
|
+
# Refer to Faraday::Env for a list of accessible fields:
|
23
|
+
# https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
|
24
|
+
#
|
25
|
+
# @param env [Faraday::Env] the environment of the request being processed
|
26
|
+
def on_request(env)
|
27
|
+
match_content_type(env) do |data|
|
28
|
+
env[:body] = encode data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def encode(data)
|
35
|
+
::Gyoku.xml(data, key_converter: :none)
|
36
|
+
end
|
37
|
+
|
38
|
+
def match_content_type(env)
|
39
|
+
return unless process_request?(env)
|
40
|
+
|
41
|
+
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
42
|
+
yield env[:body] unless env[:body].respond_to?(:to_str)
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_request?(env)
|
46
|
+
type = request_type(env)
|
47
|
+
has_body?(env) && (type.empty? or type == MIME_TYPE)
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_body?(env)
|
51
|
+
(body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?)
|
52
|
+
end
|
53
|
+
|
54
|
+
def request_type(env)
|
55
|
+
type = env[:request_headers][CONTENT_TYPE].to_s
|
56
|
+
type = type.split(';', 2).first if type.index(';')
|
57
|
+
type
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-encode_xml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Popov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-20 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: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gyoku
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
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: bundler-audit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.21.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.21.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: gem_toys
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.10.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.10.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: toys
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.12.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.12.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.22.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.22.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-packaging
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.5'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.5'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-performance
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '1.0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '1.0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop-rspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '2.0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '2.0'
|
195
|
+
description: 'Faraday middleware for encoding requests as XML.
|
196
|
+
|
197
|
+
'
|
198
|
+
email:
|
199
|
+
- alex.wayfer@gmail.com
|
200
|
+
executables: []
|
201
|
+
extensions: []
|
202
|
+
extra_rdoc_files: []
|
203
|
+
files:
|
204
|
+
- CHANGELOG.md
|
205
|
+
- LICENSE.md
|
206
|
+
- README.md
|
207
|
+
- lib/faraday/encode_xml.rb
|
208
|
+
- lib/faraday/encode_xml/version.rb
|
209
|
+
- lib/faraday/middleware/encode_xml.rb
|
210
|
+
homepage: https://github.com/AlexWayfer/faraday-encode_xml
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
metadata:
|
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
|
217
|
+
homepage_uri: https://github.com/AlexWayfer/faraday-encode_xml
|
218
|
+
source_code_uri: https://github.com/AlexWayfer/faraday-encode_xml
|
219
|
+
wiki_uri: https://github.com/AlexWayfer/faraday-encode_xml/wiki
|
220
|
+
post_install_message:
|
221
|
+
rdoc_options: []
|
222
|
+
require_paths:
|
223
|
+
- lib
|
224
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '2.5'
|
229
|
+
- - "<"
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '4'
|
232
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
requirements: []
|
238
|
+
rubygems_version: 3.2.22
|
239
|
+
signing_key:
|
240
|
+
specification_version: 4
|
241
|
+
summary: Faraday middleware for encoding requests as XML
|
242
|
+
test_files: []
|