""" https://gsxwsut.apple.com/apidocs/ut/html/WSAPIChangeLog.html?user=asp """ import urllib from lookups import Lookup from diagnostics import Diagnostics from core import GsxObject, GsxError def models(): """ >>> models() # doctest: +ELLIPSIS {'iphone_acc': {'models': 'Bluetooth Headset',... """ import os import yaml filepath = os.path.join(os.path.dirname(__file__), "products.yaml") return yaml.load(open(filepath, 'r')) class Product(GsxObject): "Something serviceable made by Apple" _namespace = "glob:" def model(self): """ Returns the model description of this Product >>> Product('DGKFL06JDHJP').model().configDescription u'iMac (27-inch, Mid 2011)' """ result = self._submit("productModelRequest", "FetchProductModel") self.configDescription = result.configDescription self.productLine = result.productLine self.configCode = result.configCode return result def warranty(self): """ The Warranty Status API retrieves the same warranty details displayed on the GSX Coverage screen. If part information is provided, the part warranty information is returned. If you do not provide the optional part information in the warranty status request, the unit level warranty information is returned. >>> Product('DGKFL06JDHJP').warranty().warrantyStatus u'Out Of Warranty (No Coverage)' >>> Product('DGKFL06JDHJP').warranty().estimatedPurchaseDate '2011-06-02' """ self._submit("unitDetail", "WarrantyStatus", "warrantyDetailInfo") self.warrantyDetails = self._req.objects[0] return self.warrantyDetails def parts(self): """ >>> Product('DGKFL06JDHJP').parts() # doctest: +ELLIPSIS [>> Product(productName='MacBook Pro (17-inch, Mid 2009)').parts() # doctest: +ELLIPSIS [>> Product(serialNumber='DGKFL06JDHJP').repairs() # doctest: +ELLIPSIS >> Product('DGKFL06JDHJP').diagnostics() """ diags = Diagnostics(serialNumber=self.serialNumber) return diags.fetch() def fetch_image(self): """ >>> Product('DGKFL06JDHJP').warranty().fetch_image() """ if not hasattr(self, "imageURL"): raise GsxError("No URL to fetch product image") try: result = urllib.urlretrieve(self.imageURL) return result[0] except Exception, e: raise GsxError("Failed to fetch product image: %s" % e) def activation(self): """ The Fetch iOS Activation Details API is used to fetch activation details of iOS Devices. >>> Product('013348005376007').activation().unlocked True >>> Product('W874939YX92').activation().unlocked # doctest: +ELLIPSIS Traceback (most recent call last): ... GsxError: Provided serial number does not belong to an iOS Device... """ self._namespace = "glob:" act = self._submit("FetchIOSActivationDetailsRequest", "FetchIOSActivationDetails", "activationDetailsInfo") return act if __name__ == '__main__': import sys import doctest import logging from core import connect logging.basicConfig(level=logging.DEBUG) connect(*sys.argv[1:]) doctest.testmod()