(self, name, url, **kwargs)
return self._get(url, params=params)
Generic API method.
Generic API method.
Generic API method .
def api(self, name, url, **kwargs):
        """Generic API method."""
        if name not in self._apis:
            raise ValueError(
                "API name must be one of {0}, not {1!r}.".format(
                    tuple(self._apis), name
                )
            )
        fields = kwargs.pop("fields", None)
        timeout = kwargs.pop("timeout", None)
        text = kwargs.pop("text", None)
        html = kwargs.pop("html", None)
        if text and html:
            raise ValueError("Both `text` and `html` arguments provided!")
        params = {**kwargs, "url": url, "token": self._token}
        if timeout:
            params["timeout"] = timeout
        if fields:
            if not isinstance(fields, str):
                fields = ",".join(sorted(fields))
            params["fields"] = fields
        url = self.endpoint(name)
        if text or html:
            content_type = html and "text/html" or "text/plain"
            return self._post(url, text or html, content_type, params=params)
        # pprint.pprint(params)
        return self._get(url, params=params)
def api ( self , name , url , * * kwargs ) : if name not in self . _apis : raise ValueError ( "API name must be one of {0}, not {1!r}." . format ( tuple ( self . _apis ) , name ) ) fields = kwargs . pop ( "fields" , None ) timeout = kwargs . pop ( "timeout" , None ) text = kwargs . pop ( "text" , None ) html = kwargs . pop ( "html" , None ) if text and html : raise ValueError ( "Both `text` and `html` arguments provided!" ) params = { * * kwargs , "url" : url , "token" : self . _token } if timeout : params [ "timeout" ] = timeout if fields : if not isinstance ( fields , str ) : fields = "," . join ( sorted ( fields ) ) params [ "fields" ] = fields url = self . endpoint ( name ) if text or html : content_type = html and "text/html" or "text/plain" return self . _post ( url , text or html , content_type , params = params ) # pprint.pprint(params) return self . _get ( url , params = params )