actionpack-xml_parser 1.0.2 → 2.0.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
  SHA1:
3
- metadata.gz: 97a34add867fdd86962702b26a409d5b174d1c11
4
- data.tar.gz: 76ea8609436ceb7b00c7930cfcd0021bfa3be8de
3
+ metadata.gz: c11adb9da2eac23e2464c66595308dfbd73e976f
4
+ data.tar.gz: 08466c378f81fb652bf083c9e228683c7b380937
5
5
  SHA512:
6
- metadata.gz: 5875755a817de09d059f5dcb3dfa8230161393575d803f89a13f994b1fb17a8a45020286b675901c97d02924cb133da8b7c6d48867836a2f0a5378c8ab622145
7
- data.tar.gz: 40ab47784a747175029be1fc3d9f3048cea205b36fa7025067f3bc3e0c8f120303f5f21ecda0dd1608864f26f3c14c594172abb9ac28c1b83d84c153a4ded522
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
- Then, add `ActionDispatch::XmlParamsParser` middleware after `ActionDispatch::ParamsParser`
16
- in `config/application.rb`:
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
- config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::XmlParamsParser
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
- You may need to require the `ActionDispatch::XmlParamsParser` manually. Add the following
23
- in your `config/application.rb`:
81
+ will result in:
24
82
 
25
83
  ```ruby
26
- require 'action_dispatch/xml_params_parser'
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,11 @@
1
+ require 'action_pack/xml_parser'
2
+
3
+ module ActionPack
4
+ class XmlParser
5
+ class Railtie < ::Rails::Railtie
6
+ initializer "actionpack-xml_parser.configure" do
7
+ ActionPack::XmlParser.register
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module ActionPack
2
+ class XmlParser
3
+ VERSION = "2.0.0"
4
+ end
5
+ 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: 1.0.2
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: 2015-04-17 00:00:00.000000000 Z
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: '5'
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: 4.0.0
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: '5'
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/action_dispatch/xml_params_parser.rb
57
- - lib/actionpack/xml_parser.rb
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: 1.9.3
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.4.6
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'