# HG changeset patch # User Gustavo Andres Morero # Date 1380116751 10800 # Wed Sep 25 10:45:51 2013 -0300 # Node ID 31507860ec40c0e4f57e6a035e7aa828bf77e2c1 # Parent e1ba04b44a8b4a347c33a315e76fede794d63e89 changed ShippingOptions get_options to return a ShippingOption list diff --git a/README.rst b/README.rst --- a/README.rst +++ b/README.rst @@ -56,9 +56,9 @@ # Retrieve options list options = shipping_opts.get_options() for opt in options: - print 'Description:', opt[0] - print 'Delivery Time:', opt[1] - print 'Price:', opt[2] + print 'Description:', opt.description + print 'Delivery Time:', opt.delivery_time + print 'Price:', opt.price else: print 'Error:', shipping_opts.error_msg diff --git a/kunaki/kunaki.py b/kunaki/kunaki.py --- a/kunaki/kunaki.py +++ b/kunaki/kunaki.py @@ -18,6 +18,24 @@ return product +class ShippingOption(KunakiElement): + """ Kunaki Shipping Option. Used for Shipping Options response. + """ + def __init__(self, description, delivery_time, price): + self.description = description + self.delivery_time = delivery_time + self.price = price + + def get_tree(self): + """ Builds tree structure for the Shipping Option. + """ + opt = ET.Element('Option') + ET.SubElement(opt, 'Description').text = unicode(self.description) + ET.SubElement(opt, 'DeliveryTime').text = unicode(self.delivery_time) + ET.SubElement(opt, 'Price').text = unicode(self.price) + return opt + + class ShippingOptions(KunakiRequest): """ Kunaki Shipping Options request. """ @@ -40,13 +58,17 @@ return options def get_options(self): - """ Returns options retrieved from Kunaki as a list of tuples - (, , ) + """ Returns ShippingOption list retrieved from Kunaki """ assert self.response is not None options = [] for opt in self.response.findall('Option'): - options.append(tuple(x.text for x in opt.getchildren())) + shipping_opt = ShippingOption( + description=opt.find('Description').text, + delivery_time=opt.find('DeliveryTime').text, + price=opt.find('Price').text, + ) + options.append(shipping_opt) return options def add_product(self, product):