actionpack-xml_parser 1.0.2 → 2.0.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/README.md +64 -6
- data/lib/action_pack/xml_parser.rb +18 -0
- data/lib/action_pack/xml_parser/railtie.rb +11 -0
- data/lib/action_pack/xml_parser/version.rb +5 -0
- data/lib/actionpack-xml_parser.rb +1 -0
- metadata +25 -15
- data/lib/action_dispatch/xml_params_parser.rb +0 -54
- data/lib/actionpack/xml_parser.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c11adb9da2eac23e2464c66595308dfbd73e976f
|
4
|
+
data.tar.gz: 08466c378f81fb652bf083c9e228683c7b380937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff7071bfa1b3b5a0d9050a22962ce6b5f0f4b058f43d051a2bea1cc52b567968053e9af56810bf7e8e6bcda4d62cd9f4ee49332d9c1255f65ed191c36b7a6188
|
7
|
+
data.tar.gz: b559483eb7e3cda5299915017e58beb9de522a2cdee9500ea1fe0ab7ccb5b5be4c97f9369830f963b03fd15d4a9850fc48b3739cd9ea4ab8b55c447f3f7f4205
|
data/README.md
CHANGED
@@ -12,16 +12,74 @@ Include this gem into your Gemfile:
|
|
12
12
|
gem 'actionpack-xml_parser'
|
13
13
|
```
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
Parameters parsing rules
|
16
|
+
------------------------
|
17
|
+
|
18
|
+
The parameters parsing is handled by `ActiveSupport::XMLConverter` so there may
|
19
|
+
be specific features and subtle differences depending on the chosen XML backend.
|
20
|
+
|
21
|
+
### Hashes
|
22
|
+
|
23
|
+
Basically, each node represents a key. With the following XML:
|
24
|
+
|
25
|
+
```xml
|
26
|
+
<person><name>David</name></person>
|
27
|
+
```
|
28
|
+
|
29
|
+
The resulting parameters will be:
|
17
30
|
|
18
31
|
```ruby
|
19
|
-
|
32
|
+
{"person" => {"name" => "David"}}
|
33
|
+
```
|
34
|
+
|
35
|
+
### File attachment
|
36
|
+
|
37
|
+
You can specify the `type` attribute of a node to attach files:
|
38
|
+
|
39
|
+
```xml
|
40
|
+
<person>
|
41
|
+
<avatar type="file" name="me.jpg" content_type="image/jpg"><!-- File content --></avatar>
|
42
|
+
</person>
|
43
|
+
```
|
44
|
+
|
45
|
+
The resulting parameters will include a `StringIO` object with the given content,
|
46
|
+
name and content type set accordingly:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
{"person" => {"avatar" => #<StringIO:...>}}
|
50
|
+
```
|
51
|
+
|
52
|
+
### Arrays
|
53
|
+
|
54
|
+
There are several ways to pass an array. You can either specify multiple nodes
|
55
|
+
with the same name:
|
56
|
+
|
57
|
+
```xml
|
58
|
+
<person>
|
59
|
+
<address city="Chicago"/>
|
60
|
+
<address city="Ottawa"/>
|
61
|
+
</person>
|
62
|
+
```
|
63
|
+
|
64
|
+
The resulting parameters will be:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
{"person" => {"address" => [{"city" => "Chicago"}, {"city" => "Ottawa"}]}}
|
68
|
+
```
|
69
|
+
|
70
|
+
You can also specify the `type` attribute of a node and nest child nodes inside:
|
71
|
+
|
72
|
+
```xml
|
73
|
+
<person>
|
74
|
+
<addresses type="array">
|
75
|
+
<address city="Melbourne"/>
|
76
|
+
<address city="Paris"/>
|
77
|
+
</addresses>
|
78
|
+
</person>
|
20
79
|
```
|
21
80
|
|
22
|
-
|
23
|
-
in your `config/application.rb`:
|
81
|
+
will result in:
|
24
82
|
|
25
83
|
```ruby
|
26
|
-
|
84
|
+
{"person" => {"addresses" => [{"city" => "Melbourne"}, {"city" => "Paris"}]}}
|
27
85
|
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/hash/conversions'
|
3
|
+
require 'action_dispatch'
|
4
|
+
require 'action_dispatch/http/request'
|
5
|
+
require 'action_pack/xml_parser/version'
|
6
|
+
|
7
|
+
module ActionPack
|
8
|
+
class XmlParser
|
9
|
+
def self.register
|
10
|
+
original_parsers = ActionDispatch::Request.parameter_parsers
|
11
|
+
ActionDispatch::Request.parameter_parsers = original_parsers.merge(Mime[:xml].symbol => self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.call(raw_post)
|
15
|
+
Hash.from_xml(raw_post) || {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'action_pack/xml_parser/railtie' if defined?(Rails::Railtie)
|
metadata
CHANGED
@@ -1,35 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionpack-xml_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prem Sichanugrist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.0.0
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 5.x
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
|
26
|
+
version: 5.x
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.x
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
31
39
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
40
|
+
version: 5.x
|
33
41
|
- !ruby/object:Gem::Dependency
|
34
42
|
name: rake
|
35
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,8 +61,10 @@ extra_rdoc_files:
|
|
53
61
|
files:
|
54
62
|
- LICENSE
|
55
63
|
- README.md
|
56
|
-
- lib/
|
57
|
-
- lib/
|
64
|
+
- lib/action_pack/xml_parser.rb
|
65
|
+
- lib/action_pack/xml_parser/railtie.rb
|
66
|
+
- lib/action_pack/xml_parser/version.rb
|
67
|
+
- lib/actionpack-xml_parser.rb
|
58
68
|
homepage: http://www.rubyonrails.org
|
59
69
|
licenses:
|
60
70
|
- MIT
|
@@ -69,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
79
|
requirements:
|
70
80
|
- - ">="
|
71
81
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
82
|
+
version: 2.2.2
|
73
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
84
|
requirements:
|
75
85
|
- - ">="
|
@@ -77,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
87
|
version: '0'
|
78
88
|
requirements: []
|
79
89
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.6
|
81
91
|
signing_key:
|
82
92
|
specification_version: 4
|
83
93
|
summary: XML parameters parser for Action Pack (removed from core in Rails 4.0)
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/conversions'
|
2
|
-
require 'action_dispatch/http/request'
|
3
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
-
|
5
|
-
module ActionDispatch
|
6
|
-
class XmlParamsParser
|
7
|
-
def initialize(app)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
if params = parse_formatted_parameters(env)
|
13
|
-
env["action_dispatch.request.request_parameters"] = params
|
14
|
-
end
|
15
|
-
|
16
|
-
@app.call(env)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def parse_formatted_parameters(env)
|
21
|
-
request = Request.new(env)
|
22
|
-
|
23
|
-
return false if request.content_length.zero?
|
24
|
-
|
25
|
-
mime_type = content_type_from_legacy_post_data_format_header(env) ||
|
26
|
-
request.content_mime_type
|
27
|
-
|
28
|
-
if mime_type == Mime::XML
|
29
|
-
# Rails 4.1 moved #deep_munge out of the request and into ActionDispatch::Request::Utils
|
30
|
-
munger = defined?(Request::Utils) ? Request::Utils : request
|
31
|
-
|
32
|
-
data = munger.deep_munge(Hash.from_xml(request.body.read) || {})
|
33
|
-
request.body.rewind if request.body.respond_to?(:rewind)
|
34
|
-
data.with_indifferent_access
|
35
|
-
else
|
36
|
-
false
|
37
|
-
end
|
38
|
-
rescue Exception => e # XML code block errors
|
39
|
-
logger(env).debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
|
40
|
-
|
41
|
-
raise ActionDispatch::ParamsParser::ParseError.new(e.message, e)
|
42
|
-
end
|
43
|
-
|
44
|
-
def content_type_from_legacy_post_data_format_header(env)
|
45
|
-
if env['HTTP_X_POST_DATA_FORMAT'].to_s.downcase == 'xml'
|
46
|
-
Mime::XML
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def logger(env)
|
51
|
-
env['action_dispatch.logger'] || ActiveSupport::Logger.new($stderr)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'action_dispatch/xml_params_parser'
|