aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws/lookups.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-05-12 22:34:53 +0300
committerFilipp Lepalaan <f@230.to>2013-05-12 22:34:53 +0300
commitaaacaebb861beaf2ef39b6bc54db2d12262e9b0d (patch)
tree2d373fc7d04ab03f87bfe5e4d13f36d6d7bc81a5 /gsxws/lookups.py
parent452005bbb83059913d4c8b7648d9e368936e53da (diff)
downloadpy-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.tar.gz
py-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.tar.bz2
py-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.zip
More speed, more power, less suds, WIP
Diffstat (limited to 'gsxws/lookups.py')
-rw-r--r--gsxws/lookups.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/gsxws/lookups.py b/gsxws/lookups.py
new file mode 100644
index 0000000..0965328
--- /dev/null
+++ b/gsxws/lookups.py
@@ -0,0 +1,64 @@
+import sys
+import base64
+import logging
+import tempfile
+from datetime import date
+
+from core import GsxObject
+
+class Lookup(GsxObject):
+ def __init__(self, *args, **kwargs):
+ super(Lookup, self).__init__(*args, **kwargs)
+ self._namespace = "asp:"
+
+ def lookup(self, method, response="lookupResponseData"):
+ return self._submit("lookupRequestData", method, response)
+
+ def parts(self):
+ """
+ The Parts Lookup API allows users to access part and part pricing data prior to
+ creating a repair or order. Parts lookup is also a good way to search for
+ part numbers by various attributes of a part
+ (config code, EEE code, serial number, etc.).
+ """
+ self._namespace = "core:"
+ return self.lookup("PartsLookup", "parts")
+
+ def repairs(self):
+ """
+ The Repair Lookup API mimics the front-end repair search functionality.
+ It fetches up to 2500 repairs in a given criteria.
+ Subsequently, the extended Repair Status API can be used
+ to retrieve more details of the repair.
+ """
+ return self.lookup("RepairLookup")
+
+ def invoices(self):
+ """
+ The Invoice ID Lookup API allows AASP users
+ to fetch the invoice generated for last 24 hrs
+
+ >>> Lookup(shipTo=677592, invoiceDate=date(2012,2,6)).invoices().invoiceID
+ '9670348809'
+ """
+ return self.lookup("InvoiceIDLookup")
+
+ def invoice_details(self):
+ """
+ The Invoice Details Lookup API allows AASP users to
+ download invoice for a given invoice id.
+ >>> Lookup(invoiceID=9670348809).invoice_details()
+ """
+ result = self.lookup("InvoiceDetailsLookup")
+ pdf = base64.b64decode(result.invoiceData)
+ outfile = tempfile.NamedTemporaryFile(suffix='.pdf', delete=False)
+ outfile.write(pdf)
+ result.invoiceData = outfile.name
+ return result
+
+if __name__ == '__main__':
+ import sys
+ import doctest
+ logging.basicConfig(level=logging.DEBUG)
+ connect(*sys.argv[1:4])
+ doctest.testmod()