Beispiel #1
0
    def __init__(self,
                 api_key,
                 secret=None,
                 session_key=None,
                 input_encoding=None,
                 request_headers=None,
                 no_cache=False,
                 debug=None,
                 logfile=None):
        """
        Create an Api object to access the last.fm webservice API. Use this object as a
        starting point for accessing all the webservice methods.
        
        @param api_key:            last.fm API key
        @type api_key:             L{str}
        @param secret:             last.fm API secret (optional, required only for
                                   authenticated webservice methods)
        @type secret:              L{str}
        @param session_key:        session key for the authenticated session (optional,
                                   required only for authenticated webservice methods)
        @type session_key:         L{str}
        @param input_encoding:     encoding of the input data (optional)
        @type input_encoding:      L{str}
        @param request_headers:    HTTP headers for the requests to last.fm webservices
                                   (optional)
        @type request_headers:     L{dict}
        @param no_cache:           flag to switch off file cache (optional)
        @type no_cache:            L{bool}
        @param debug:              flag to switch on debugging (optional)
        @type debug:               L{bool}
        """
        self._api_key = api_key
        self._secret = secret
        self._session_key = session_key
        self._urllib = urllib2
        self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
        self._initialize_request_headers(request_headers)
        self._initialize_user_agent()
        self._input_encoding = input_encoding
        self._no_cache = no_cache
        self._logfile = logfile
        self._last_fetch_time = datetime.now()
        if self._no_cache:
            self._cache = None
        else:
            self._cache = FileCache()

        if debug is not None:
            if debug in Api.DEBUG_LEVELS:
                self._debug = Api.DEBUG_LEVELS[debug]
            else:
                raise InvalidParametersError(
                    "debug parameter must be one of the keys in Api.DEBUG_LEVELS dict"
                )
        else:
            self._debug = None
        if self._debug is not None:
            Wormhole.enable()
        logging.set_api(self)
Beispiel #2
0
    def __init__(
        self,
        api_key,
        secret=None,
        session_key=None,
        input_encoding=None,
        request_headers=None,
        no_cache=False,
        debug=None,
        logfile=None,
    ):
        """
        Create an Api object to access the last.fm webservice API. Use this object as a
        starting point for accessing all the webservice methods.
        
        @param api_key:            last.fm API key
        @type api_key:             L{str}
        @param secret:             last.fm API secret (optional, required only for
                                   authenticated webservice methods)
        @type secret:              L{str}
        @param session_key:        session key for the authenticated session (optional,
                                   required only for authenticated webservice methods)
        @type session_key:         L{str}
        @param input_encoding:     encoding of the input data (optional)
        @type input_encoding:      L{str}
        @param request_headers:    HTTP headers for the requests to last.fm webservices
                                   (optional)
        @type request_headers:     L{dict}
        @param no_cache:           flag to switch off file cache (optional)
        @type no_cache:            L{bool}
        @param debug:              flag to switch on debugging (optional)
        @type debug:               L{bool}
        """
        self._api_key = api_key
        self._secret = secret
        self._session_key = session_key
        self._urllib = urllib2
        self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
        self._initialize_request_headers(request_headers)
        self._initialize_user_agent()
        self._input_encoding = input_encoding
        self._no_cache = no_cache
        self._logfile = logfile
        self._last_fetch_time = datetime.now()
        if self._no_cache:
            self._cache = None
        else:
            self._cache = FileCache()

        if debug is not None:
            if debug in Api.DEBUG_LEVELS:
                self._debug = Api.DEBUG_LEVELS[debug]
            else:
                raise InvalidParametersError("debug parameter must be one of the keys in Api.DEBUG_LEVELS dict")
        else:
            self._debug = None
        if self._debug is not None:
            Wormhole.enable()
        logging.set_api(self)