bjjb / ebayr

A small library to help using the eBay Trading API with Ruby
MIT License
60 stars 49 forks source link

Make Array handling in payload values more compact to reflect subsequent equal tags #21

Open meismann opened 8 years ago

meismann commented 8 years ago

Old behaviour:

# Adds: "<a>1</a><a><b>1</b><b>2</b></a>" to the ebay request body
args = [{ :a => 1 }, { :a => [{:b => 1 }, { :b => 2 }] }]
Ebayr::Request.new(:Blah, :input => args)

New behaviour:

If a value in this Hash is an Array, then each of the Array's elements is wrapped in the same tag (which is the value's key), like here (1 and 2 are both wrapped in the tag b):

# Adds: "<a>1</a><a><b>1</b><b>2</b></a>" to the ebay request body
args = {a: [ 1, { b: [1, 2] } ]}
Ebayr::Request.new(:Blah, :input => args)

If you have to, you can switch the legacy syntax on with this setting:

Ebayr.use_old_hash_to_xml_conversion = true

Also: These methods cannot be used from outside of Ebayr::Request any more: .xml, .serialize_input, .camelize, #input_xml

meismann commented 8 years ago

@bjjb Took up your suggestion to make it backward compatible. Here is the result.

SpeerJ commented 8 years ago

Please remember to use the "=>" over ":" for hashes, since this project targets ruby 1.8.7 as well. the tests return this error " /home/travis/build/bjjb/ebayr/test/ebayr/request_test.rb:24: syntax error, unexpected ':', expecting ')'

  xml_of(a: [ 1, { b: [1, 2] } ])."

it can be fixed with "xml_of(:a=> [ 1, { :b=> [1, 2] } ])"

meismann commented 8 years ago

Ok, will change it in a minute.

meismann commented 8 years ago

Any progress here?

meismann commented 6 years ago

Any chance that theses changes will make it into master? If not, let us close it.

bjjb commented 6 years ago

Hi @meismann The changes currently conflict with other changes in master. Is it still an issue for you? If not, then I guess we can just close it. If so, then I can make some suggestions for prepping the MR.