lib/rivendell/api/xport.rb in rivendell-api-0.0.5 vs lib/rivendell/api/xport.rb in rivendell-api-0.6

- old
+ new

@@ -100,29 +100,33 @@ # FIXME accents in carts create invalid UTF-8 response def list_carts(options = {}) options[:group_name] ||= options.delete(:group) response = post COMMAND_LISTCARTS, options - response["cartList"]["cart"].collect do |cart_xml| + elements(response["cartList"]["cart"]).collect do |cart_xml| Rivendell::API::Cart.new(cart_xml) end end + def elements(response) + case response + when Array + response + when nil + [] + else + [ response ] + end + end + def remove_cart(cart_number) post COMMAND_REMOVECART, :cart_number => cart_number end def list_cuts(cart_number) response = post COMMAND_LISTCUTS, :cart_number => cart_number - case cuts_xml = response["cutList"]["cut"] - when Array - cuts_xml.collect do |cut_xml| - Rivendell::API::Cut.new(cut_xml) - end - when nil - [] - else - [ Rivendell::API::Cut.new(cuts_xml) ] + elements(response["cutList"]["cut"]).collect do |cut_xml| + Rivendell::API::Cut.new cut_xml end end def remove_cut(cart_number, cut_number) post COMMAND_REMOVECUT, :cart_number => cart_number, :cut_number => cut_number