<filename>system/apis/googlebooksapi/volume.py
class Volume:

    def __init__(self, json):
        if "id" in json.keys():
            self.id = json["id"]
        else:
            self.id = None

        if "title" in json["volumeInfo"].keys():
            self.title = json["volumeInfo"]["title"]
        else:
            self.title = None

        if "subtitle" in json["volumeInfo"].keys():
            self.subtitle = json["volumeInfo"]["subtitle"]
        else:
            self.subtitle = None

        if "authors" in json["volumeInfo"].keys():
            self.authors = json["volumeInfo"]["authors"]
        else:
            self.authors = None

        if "description.txt" in json["volumeInfo"].keys():
            self.description = json["volumeInfo"]["description.txt"]
        else:
            self.description = None

        if "publisher" in json["volumeInfo"].keys():
            self.publisher = json["volumeInfo"]["publisher"]
        else:
            self.publisher = None

        if "publishedDate" in json["volumeInfo"].keys():
            self.publishedDate = json["volumeInfo"]["publishedDate"]
        else:
            self.publisher = None

        if "pageCount" in json["volumeInfo"].keys():
            self.pageCount = json["volumeInfo"]["pageCount"]
        else:
            self.pageCount = None

        if "categories" in json["volumeInfo"].keys():
            self.categories = json["volumeInfo"]["categories"]
        else:
            self.categories = None

        if "averageRating" in json["volumeInfo"].keys():
            self.averageRating = json["volumeInfo"]["averageRating"]
        else:
            self.averageRating = None

        if "ratingsCount" in json["volumeInfo"].keys():
            self.ratingsCount = json["volumeInfo"]["ratingsCount"]
        else:
            self.ratingsCount = None

        if "imageLinks" in json["volumeInfo"].keys():
            self.images = json["volumeInfo"]["imageLinks"]
        else:
            self.images = None

        if "saleability" in json["saleInfo"].keys():
            self.free = (json["saleInfo"]["saleability"] == "FREE")
        else:
            self.free = None

        self.ePubAccess = ("accessInfo" in json.keys()) \
                      and ("viewability" in json["accessInfo"].keys()) \
                      and ("epub" in json["accessInfo"].keys()) \
                      and ("downloadLink" in json["accessInfo"]["epub"].keys()) \
                      and not json["accessInfo"]["viewability"] in ["PARTIAL", "NO_PAGES", "UNKNOWN"]

        self.pdfAccess = ("accessInfo" in json.keys()) \
                          and ("viewability" in json["accessInfo"].keys()) \
                          and ("pdf" in json["accessInfo"].keys()) \
                          and ("downloadLink" in json["accessInfo"]["pdf"].keys()) \
                          and not json["accessInfo"]["viewability"] in ["PARTIAL", "NO_PAGES", "UNKNOWN"]

        if self.ePubAccess:
            self.ePubDownload = json["accessInfo"]["epub"]["downloadLink"]
        else:
            self.ePubDownload = None

        if self.pdfAccess:
            self.pdfDownload = json["accessInfo"]["pdf"]["downloadLink"]
        else:
            self.pdfDownload = None

<filename>system/apis/googlebooksapi/volume.py
class Volume:

    def __init__(self, json):
        if "id" in json.keys():
            self.id = json["id"]
        else:
            self.id = None

        if "title" in json["volumeInfo"].keys():
            self.title = json["volumeInfo"]["title"]
        else:
            self.title = None

        if "subtitle" in json["volumeInfo"].keys():
            self.subtitle = json["volumeInfo"]["subtitle"]
        else:
            self.subtitle = None

        if "authors" in json["volumeInfo"].keys():
            self.authors = json["volumeInfo"]["authors"]
        else:
            self.authors = None

        if "description.txt" in json["volumeInfo"].keys():
            self.description = json["volumeInfo"]["description.txt"]
        else:
            self.description = None

        if "publisher" in json["volumeInfo"].keys():
            self.publisher = json["volumeInfo"]["publisher"]
        else:
            self.publisher = None

        if "publishedDate" in json["volumeInfo"].keys():
            self.publishedDate = json["volumeInfo"]["publishedDate"]
        else:
            self.publisher = None

        if "pageCount" in json["volumeInfo"].keys():
            self.pageCount = json["volumeInfo"]["pageCount"]
        else:
            self.pageCount = None

        if "categories" in json["volumeInfo"].keys():
            self.categories = json["volumeInfo"]["categories"]
        else:
            self.categories = None

        if "averageRating" in json["volumeInfo"].keys():
            self.averageRating = json["volumeInfo"]["averageRating"]
        else:
            self.averageRating = None

        if "ratingsCount" in json["volumeInfo"].keys():
            self.ratingsCount = json["volumeInfo"]["ratingsCount"]
        else:
            self.ratingsCount = None

        if "imageLinks" in json["volumeInfo"].keys():
            self.images = json["volumeInfo"]["imageLinks"]
        else:
            self.images = None

        if "saleability" in json["saleInfo"].keys():
            self.free = (json["saleInfo"]["saleability"] == "FREE")
        else:
            self.free = None

        self.ePubAccess = ("accessInfo" in json.keys()) \
                      and ("viewability" in json["accessInfo"].keys()) \
                      and ("epub" in json["accessInfo"].keys()) \
                      and ("downloadLink" in json["accessInfo"]["epub"].keys()) \
                      and not json["accessInfo"]["viewability"] in ["PARTIAL", "NO_PAGES", "UNKNOWN"]

        self.pdfAccess = ("accessInfo" in json.keys()) \
                          and ("viewability" in json["accessInfo"].keys()) \
                          and ("pdf" in json["accessInfo"].keys()) \
                          and ("downloadLink" in json["accessInfo"]["pdf"].keys()) \
                          and not json["accessInfo"]["viewability"] in ["PARTIAL", "NO_PAGES", "UNKNOWN"]

        if self.ePubAccess:
            self.ePubDownload = json["accessInfo"]["epub"]["downloadLink"]
        else:
            self.ePubDownload = None

        if self.pdfAccess:
            self.pdfDownload = json["accessInfo"]["pdf"]["downloadLink"]
        else:
            self.pdfDownload = None
