Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop camelcase #55

Open
Igorpollo opened this issue Apr 17, 2015 · 1 comment
Open

Stop camelcase #55

Igorpollo opened this issue Apr 17, 2015 · 1 comment

Comments

@Igorpollo
Copy link

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)
@dtrabandt
Copy link

Even you might already found a solution I would like to point that the issues lies within your code.

The signature of the xml functions looks like:

  # Translates a given +hash+ with +options+ to XML.
  def self.xml(hash, options = {})
    Hash.to_xml hash.dup, options
  end

But what you are trying is to put two separate keys into the xml functions. Just put your data and option key in a separate hash and the function will work as expected.

@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 } )

Result:

<?xml version="1.0"?>
<enviar_instrucao>
  <instrucao_unica>
    <razao>Upgrade de Conta</razao>
    <valores>
      <valor moeda="BRL">100</valor>
    </valores>
    <id_propio>TesteRails</id_propio>
    <pagador>
      <nome>Igor Cesar</nome>
      <email>[email protected]</email>
      <id_pagador>01</id_pagador>
      <endereco_cobranca>
        <logradouro>Rua do Teste</logradouro>
        <numero>45</numero>
        <complemento>em frente ao PC</complemento>
        <bairro>Palhaco Ze</bairro>
        <cidade>Rio de Janeiro</cidade>
        <estado>RJ</estado>
        <pais>Brasil</pais>
        <CEP>20765171</CEP>
        <telefone_fixo>(21) 99527-2766</telefone_fixo>
      </endereco_cobranca>
    </pagador>
  </instrucao_unica>
</enviar_instrucao>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants