savonrb / gyoku Goto Github PK
View Code? Open in Web Editor NEWTranslates Ruby Hashes to XML
License: MIT License
Translates Ruby Hashes to XML
License: MIT License
Since this gem hasn't been released in a while the only possible way to use the pretty printing is to do this:
Gemfile:
source 'https://rubygems.org'
gem 'gyoku', git: 'https://github.com/savonrb/gyoku'
script.rb:
require 'bundler/setup'
require 'gyoku'
xml = Gyoku.xml({ document: "xy" }, { pretty_print: true })
This fails however since rexml
is used for pretty printing, so the Gemfile must look like this to make the pretty printing work:
source 'https://rubygems.org'
gem 'gyoku', git: 'https://github.com/savonrb/gyoku'
gem 'rexml'
rexml
should be included in the Gemfile of gyoku
. It should not be necessary for the user of the library to include it in his/her Gemfile.
For example:
Gyoku.xml({items: {:content! => [item: "abc"], :@amount => "1"}}, unwrap: true)
# => "<items><item>abc</item></items>"
But I'm expecting:
Gyoku.xml({items: {:content! => [item: "abc"], :@amount => "1"}}, unwrap: true)
# => "<items amount=\"1\"><item>abc</item></items>"
Line /lib/gyoku/array.rb:3 require "gyoku/hash"
establishes a circular require pattern. Commenting that line out seems to resolve the issue. The following is the full exception listing from JRuby-9.1.14.0
/Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247: warning: loading in progress, circular require considered harmful - /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/array.rb:3 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb:3 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku.rb:2 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/akami-1.3.1/lib/akami/wsse.rb:7 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/akami-1.3.1/lib/akami.rb:2 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/header.rb:1 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/builder.rb:1 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/operation.rb:4 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 each at org/jruby/RubyArray.java:1734 block in load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 each at org/jruby/RubyArray.java:1734 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/client.rb:1 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 tap at org/jruby/RubyKernel.java:1741 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon.rb:27 require at org/jruby/RubyKernel.java:955 <main> at /Users/jscott/.rvm/gems/jruby-9.1.14.0@bmiservice/gems/bundler-1.16.0/lib/bundler/runtime.rb:1
Hi, congrats for the nice gem.
I need instead it do
How can I do this? thanks
@teste = Gyoku.xml(
:enviar_instrucao => {
:instrucao_unica =>{
:razao => 'Upgrade de Conta',
:valores => {:valor => '100', :attributes! => { :valor => { :moeda => 'BRL' }}},
:id_propio => 'TesteRails',
:pagador => {
:nome => 'Igor Cesar',
:email => '[email protected]',
:id_pagador =>'01',
:endereco_cobranca => {
:logradouro => 'Rua do Teste',
:numero => '45',
:complemento => 'em frente ao PC',
:bairro => 'Palhaco Ze',
:cidade => 'Rio de Janeiro',
:estado => 'RJ',
:pais => 'Brasil',
:CEP => '20765171',
:telefone_fixo => '(21) 99527-2766'
}
}
}
}, :key_converter => :none)
The xml method does not behave as I would expect as it modifies the hash that is passed into it. Moreover, it modifies elements within the hash as it proceeds. Consider the following code:
nil_content = { :content! => nil, :'@xs1:nil' => 1 }
bar = { request: { "attributes" => { "text" => nil_content, "date" => nil_content } }}
bar_xml = Gyoku.xml(bar)
puts bar_xml
This produces:
Note that the xs1:nil attribute is not set in the XML when it should be. This is because somehow Gyoku is modifying the content of the nil_content variable.
By changing the bar_xml assignment to use the Rails deep_dup() Hash method to:
bar_xml = Gyoku.xml(bar.deep_dup)
puts bar_xml
This produces:
I note that in the implementation it performs a dup on the hash that is called, but that is insufficient. It should perform (the equivalent) a deep_dup instead.
Unfortunately am stuck using 1.8.7
Savon settings:
convert_request_keys_to :camelelcase
element_form_default :qualified
but this is not applying to the :order!
array, so I am getting an argument error:
Missing elements in :order! [:user_name, :email_count]
Upon further exploration the error is coming from
gyoku-1.0.0/lib/gyoku/hash.rb:76:in `order'
hashable = [:email_count, :user_name]
orderable = ['userName', 'emailCount']
Thanks
If attributes! are not given for all elements, Gyoku generates the attribute with blank values.
This breaks web services which require that attribute to be unspecified or non-blank
For example:
hash = { :find_user => { :person => ["Lucy", "Anna", "Beth"], :attributes! => { :person => { :id => [1, 2] } } } }
Gyoku.xml(hash)
generates
<findUser><person id=\"1\">Lucy</person><person id=\"2\">Anna</person><person id=\"\">Beth</person></findUser>
The blank id for the last element is incorrect if web service does not require you to specify ids for new elements.
The generated xml should have been:
<findUser><person id=\"1\">Lucy</person><person id=\"2\">Anna</person><person>Beth</person></findUser>
without the id attribute.
In GitHub Actions output, examples:
Coveralls encountered an exception:
NoMethodError
undefined method `coverage' for #<SimpleCov::SourceFile:0x00007f3142fd0cd0 @filename="/home/runner/work/gyoku/gyoku/lib/gyoku.rb", @coverage_data={"lines"=>[1, 1, nil, 1, nil, nil, 1, 4, nil, nil, nil, 1, 6, nil, nil, nil]}>
properties[:coverage] = file.coverage
^^^^^^^^^
Did you mean? coverage_data
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/coveralls-0.7.2/lib/coveralls/simplecov.rb:50:in `block in format'
/opt/hostedtoolcache/Ruby/3.1.1/x64/lib/ruby/3.1.0/forwardable.rb:238:in `each'
/opt/hostedtoolcache/Ruby/3.1.1/x64/lib/ruby/3.1.0/forwardable.rb:238:in `each'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/coveralls-0.7.2/lib/coveralls/simplecov.rb:40:in `format'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/result.rb:51:in `format!'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/configuration.rb:197:in `block in at_exit'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov.rb:189:in `run_exit_tasks!'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov.rb:179:in `at_exit_behavior'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/defaults.rb:30:in `block in <top (required)>'
Any reason not to accept something call
able or allow one to add a converter?
The problem I've found is that some schemas upcase certain words. For example:
Ruby | :camelcase | Wanted |
:product_id | ProductId | ProductID |
:iso_code | IsoCode | ISOCode |
Sometimes when using gyoku through Savon we get an exception like so:
NoMethodError: undefined method `upcase' for nil:NilClass
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:5:in `__singleton__' org/jruby/RubyString.java:3037:in `gsub' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:5:in `__singleton__' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:11:in `__singleton__' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:24:in `create'
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku.rb:8:in `xml_tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/message.rb:22:in `to_s'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:146:in `tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:146:in `tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:33:in `to_s'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/operation.rb:72:in `build_request'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/operation.rb:48:in `call'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/client.rb:38:in `call'
I'm not exactly sure why this happen, probably the result is not as gyoku expect it but a proper error would be nicer than a NoMethodError.
I'm not sure why exactly this is happening, but Gyoku seems to be running fine out of the box on the [Ruby 1.8] Linux machine I was running on, but when I tried it on a [Ruby 1.9] Windows machine with a similar Gem setup, I'm getting an error with it resolving DateTime in /lib/gyoku/xml_value.rb:
https://gist.github.com/7b2c1ecb970019f66b9b
Which obviously is fixable just adding require 'Date'
. I'm not much of a Rubyist, so I'm not sure that's the right solution (well, manually hacking a gem isn't, regardless). Any thoughts? Versions below:
c:\Test>ruby --version
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
c:\Test>gem list
...
gyoku (0.4.2)
This code:
xml = Gyoku.xml({
'foo' => { '@foo' => 'foo' },
'bar' => [ { '@bar' => 'bar', 'baz' => { } } ],
})
produces this xml:
<foo foo="foo">
</foo>
<bar>
<baz>
</baz>
</bar>
but should produce:
<foo foo="foo">
</foo>
<bar bar="bar">
<baz>
</baz>
</bar>
(the attributes are missing when the hash value is an array of hashes).
I looked at array.rb for how to fix this, but it's not obvious to me.
Strathmeyer mentioned this in #18 (comment), but I thought it was better to enter a separate issue for this rather than hijack an existing one.
It just so happens to be the case that I need to use XML-nodes starting with an @.
>> client.call(:get_member_detail, message: { "relationid" => 3_055_232})
=> Savon::SOAPFault: (s:Client) .Net SqlClient Data Provider : Procedure or Function 'GetMemberDetail' expects parameter '@relationid', which was not supplied.
Is there some sort of workaround for this? I now get an empty string after adding the @ to relationid.
>> Gyoku.xml(:@responseid => 1234)
=> ""
Maybe we can only add the attributes via :@attr when there's a valid node present?
Consider the following ruby script:
require 'gyoku'
puts "Ruby Version: #{RUBY_VERSION}"
puts Gyoku.xml(:special_chars => %q{&"<>'})
When executed on Ruby 1.9.3, it produces this output:
Ruby Version: 1.9.3
<specialChars>&"<>'</specialChars>
When executed on Ruby 2.0.0, it produces this output:
Ruby Version: 2.0.0
<specialChars>&"<>'</specialChars>
The apostrophe character is not encoded at all on Ruby 1.9.3, but on ruby 2.0 it is converted to '
. The reason appears to be because of this line. The behavior of the CGI.escapeHTML
function seems to have changed from Ruby 1.9.3 to Ruby 2.0. Here is an example.
This script:
require 'cgi'
string = %q{<>&"'}
puts "Ruby Version: #{RUBY_VERSION}"
puts "Original: #{string}"
puts "Encoded: #{CGI.escapeHTML(string)}"
produces this output on Ruby 1.9.3:
Ruby Version: 1.9.3
Original: <>&"'
Encoded: <>&"'
but this output on Ruby 2.0:
Ruby Version: 2.1.1
Original: <>&"'
Encoded: <>&"'
It seems like the output should not change depending on the ruby version. In addition, if an apostrophe is going to be encoded, it seems like it would be more correct to encode it as '
instead of '
. In fact, encoding it as '
is directly causing me a problem here. :)
Hi,
Without this gem in the gemspec
/usr/share/gems/gems/bundler-1.3.5/lib/bundler/resolver.rb:296:in `resolve': Could not find gem 'rubinius-coverage (>= 0) ruby' in the gems available on this machine. (Bundler::GemNotFound)
Doc says this:
Using "@" keys and ":content!"
Gyoku.xml(
"foo/" => {
:@bar => "1",
:@biz => "2",
:@baz => "3",
:content! => ""
})
Actual output:
1.9.2-p318 :021 > Gyoku.xml(
1.9.2-p318 :022 > "foo/" => {
1.9.2-p318 :023 > :@bar => "1",
1.9.2-p318 :024 > :@biz => "2",
1.9.2-p318 :025 > :@baz => "3",
1.9.2-p318 :026 > :content! => ""
1.9.2-p318 :027?> })
=> "@BAR1/@bar@biz2/@biz@BAZ3/@baz" โจ
(gyoku (1.0.0, 0.4.6, 0.4.4))
This is rather frustrating as I am generating very large XML documents with a large attributes hash that need self closing tags for blank values. That is very inefficient with the attributes hash and the :content! syntax would be far superior if it worked as expected...
I'm getting the following error whenever I try to run an application I'm building:
/Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36: warning: loading in progress, circular require considered harmful - /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku/hash.rb
from add_card_tests.rb:2:in `<main>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/git/i2c_web_service/i2c_tests/test_helper.rb:4:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/git/i2c_web_service/lib/i2c/web_services/client.rb:1:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/savon-0.9.9/lib/savon.rb:3:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/savon-0.9.9/lib/savon/client.rb:2:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/akami-1.0.0/lib/akami.rb:2:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/akami-1.0.0/lib/akami/wsse.rb:4:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku.rb:2:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku/hash.rb:3:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku/array.rb:3:in `<top (required)>'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
Just to be thorough here are my requires as they appear in the stacktrace:
add_card_tests.rb
:
require 'test_helper.rb'
test_helper.rb
:
require 'i2c/web_services/client'
i2c/web_services/client.rb
:
require 'savon'
I have my own Client class but it's namespaced under I2C::WebServices::Client, so this shouldn't interfere with savon's own class client, and the errors would indicate that the circular dependency is deeper than savon and well into the gyoku gem.
Any help is greatly appreciated.
Checklist to release a new version:
Gyoko.xml "attribute" => [nil, nil, {}]
IMO should output only one empty <attribute/>
element. In my case it outputted 3.
I think all nils should be ignored (f.ex by using compact
internally). Just my take.
Cheers!
I got an Hash
with a nested Array
of hashes:
>> Gyoku.xml(attributes: [ {key: 'foo', value: 'bar' } ])
=> "<attributes><key>foo</key><value>bar</value></attributes>"
The XML contains no indication that this was an array?
Accidently i tried:
>> Gyoku.xml(attributes: [ {key: 'foo', value: 'bar'}, {key: 'more', value: 'foo' } ] )
=> "<attributes><key>foo</key><value>bar</value></attributes><attributes><key>more</key><value>foo</value></attributes>"
I found that even more surprising... but it gave me a hint how to achieve the expected output:
>> Gyoku.xml(attributes: { item: [ {key: 'foo', value: 'bar'}, {key: 'more', value: 'foo' } ] })
=> "<attributes><item><key>foo</key><value>bar</value></item><item><key>more</key><value>foo</value></item></attributes>"
I can work with that but i do wonder - is this the intended behaviour when converting an array of hashes to XML?
The camelcase method defined in Rails allow to create camelcase and lower camelcase and is your definition of the method is conflicting with it when using like this camelcase(:lower) to have a lower camelcase.
Hi there,
When converting a hash containing an array of hashes, like this:
:some => [{ :new => "user" }, { :old => "gorilla" }]
I expected the following output:
<some>
<new>user</new>
<old>gorilla</old>
</some>
But, instead it produces this:
<some>
<new>user</new>
</some>
<some>
<old>gorilla</old>
</some>
It seems like the parent hash should be the root element and should not repeat since there is only one key (:some)
Thoughts?
Thanks,
Matt
It produces:
h = {attrs: [{attr: 1}, {attr: 2}, {attr: 3}]}
=> {:attrs=>[{:attr=>1}, {:attr=>2}, {:attr=>3}]}
Gyoku.xml(h)
=> "<foo><bar>1</bar></foo><foo><bar>2</bar></foo><foo><bar>3</bar></foo>"
I think this behaviour is completely incorrect. I believe it should return: <foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>
.
I haven't got time to look it yet, but It may be related to #40
Hi,
In parsing XML to hash, Gyoku seems to ignore attributes when there's a content inside the tag :
<myTag myAttribute="attributeContent" />
<myTag myAttribute="otherAttributeContent">tagContent</myTag>
is parsed (by 0.4.4) as
{ :my_tag => [ { :@my_attribute=>"attributeContent" }, "tagContent" ] }
Is this really the correct behavior? Is there a way to force attribute parsing?
Thanks,
Gilles
https://github.com/rubiii/gyoku/blob/master/lib/gyoku/hash.rb#L33
Gyoku seems to delete :attributes! and :order! entry from a hash passed as arguments.
I prefer to keep a hash unchanged rather than delete any entry,
because unchanged hash are reusable.
Is there any reason to delete :attributes! and :order! from a hash?
Thanks.
Gyoku seems to swallow custom attributes provided via :attributes!
Hashes for self-closing tags and nil values.
Gyoku.xml(
:root => {
"category/" => "",
:attributes! => { :category => { :id => 1 } }
}
)
# => "<root><category/></root>"
Could you please indicate in the License file the license type? I think it is MIT, but it would be best if you explicitly said so.
One of our partner interfaces loves to use a list of self closing elements with attributes in the requests. In savon 0.7 I was able to generate these using by setting the values to an array of nils with the appropriate attributes hash with array of attribute values. In Gyoku, I can use the / suffix notation to generate a single element, but when I try to generate an array (using empty hashes instead of nils to avoid the xsi nil), the generated elements are not self closing.
I am working around this by generating the XML fragments by hand and using the ! Suffix to avoid escaping the output.
When I have need to use nested arrays in savon SOAP client, but this is case caused bug in my opinion.
irb(main):001:0> Gyoku::Array.to_xml([[{ value: "1" }]], "Map")
=> "<Map>[{:value=>\"1\"}]</Map>"
Nested array is treated with to_s
method. IMO it could be treated as normal Array. I done some workaround in https://github.com/seban/gyoku/commit/e7706cfaea69bba655d30c49c1eabe6893bddc3d. After my fix it looks like:
2.0.0p247 :001 > Gyoku::Array.to_xml([[{ value: "1" }]], "Map")
=> "<Map><element><value>1</value></element></Map>"
If it is ok for you I can submit pull request.
Hi there.
I wanted to generate some XML, and I wanted it to look nice. Having to concatenate some identical tags I set unwrap: true
(which works fine), but the result wasn't prettified.
pry(main)> Gyoku.xml({ a: :b, c: [{ d: :e }, { f: :g }] }, { unwrap: true })
=> "<a>b</a><c><d>e</d><f>g</f></c>"
pry(main)> Gyoku.xml({ a: :b, c: [{ d: :e }, { f: :g }] }, { unwrap: true, pretty_print: true })
=> "<a>b</a><c><d>e</d><f>g</f></c>"
pry(main)> Gyoku.xml({ a: :b, c: [{ d: :e }, { f: :g }] }, { unwrap: true, pretty_print: true, compact: false })
=> "<a>b</a><c><d>e</d><f>g</f></c>"
I would have expected both of the last results to be something like this:
<a>b</a>
<c>
<d>e</d>
<f>g</f>
</c>
I'm currently running Gyoku v. 1.3.1
Thanks in advance
How do i get ditinct attributes for Array elements
Gyoku.xml(:person => "Eve", :attributes! => { :person => { :id => 1 } })
results in:
<person id="1">Eve</person>
If i make person an Array, it gives the same attribute for each element
Gyoku.xml(:person => ["Adam","Eve"], :attributes! => { :person => { :id => 1 } })
results in:
<person id="1">Adam</person><person id="1">Eve</person>
How do i get distinct attrbiutes for Array elements like this:
<person id="1">Adam</person><person id="2">Eve</person>
Declaring attributes! as Array doesn't help either:
Gyoku.xml(:person => ["Adam","Eve"], :attributes! => { :person => [{ :id => 1 }, {:id => 2}] })
results in invalid xml like this:
<person {:id=>1}=\"\" {:id=>2}=\"\">Adam</person><person {:id=>1}=\"\" {:id=>2}=\"\">Eve</person>
When I try to generate custom XML which should be used like this:
resp = client.request 'save_waybill', :body => { :waybill! => '<a>Some XML</a>' }
it results in the following request:
<ins0:save_waybill><ins0:waybill><a>Some tag</a></ins0:waybill></ins0:save_waybill>
when i use something different from waybill
everything seems to work fine:
resp = client.request 'save_waybill', :body => { :waybil! => '<a>Some XML</a>' }
<ins0:save_waybill><wsdl:waybil><a>Some XML</a></wsdl:waybil></ins0:save_waybill>
The same applies, when i change the name of the method save_waybill
to something not ending with waybill
.
If I write the following code:
Gyoku.xml(tag!: '<p>text<p>', attributes!: {tag: { prop: 1}})
the output is "<tag><p>text<p></tag>"
, note the property may be missing in the tag
But it works with:
Gyoku.xml(tag!: '<p>text<p>', attributes!: {tag!: { prop: 1}})
output: '<tag prop="1"><p>text<p></tag>'
I would like to ask if this is the intended behaviour before submitting a PR
Date objects are mapped like DateTime, e.g. results in strings like 2009-08-17T00:00:00+00:00
Shouldn't they be mapped to something like 2009-08-17 (without the time)? This breaks my app and ist not valid xsd:date as well.
This is in the context of Savon, of course.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.