Exemple #1
0
    def delete(cls, url, params=None, retries=None, headers=None, proxies=None, verify=None):
        """
        Send a DELETE request.

        :param url: The URL to send the DELETE request to.
        :type url: str
        :param params: The DELETE parameters to send in the request.
        :type params: dict
        :param retries: Number of retries before stopping.
        :type retries: int
        :param headers: header info for requests.
        :type headers: dict
        :param proxies: proxy info for requests.
        :type proxies: dict
        :param verify: verify info for requests.
        :type verify: bool, str
        :returns: dict (using json.loads())
        """

        if not params:
            params = dict()
        if headers is None:
            headers = get_headers()
        if proxies is None:
            proxies = get_proxies()
        if verify is None:
            verify = get_verify()

        params[t.ACCESS_TOKEN] = get_access_token()
        session = cls.build_session(retries)
        resp = session.delete(url, params=params, headers=headers, proxies=proxies, verify=verify)
        return cls.handle_results(resp)
Exemple #2
0
    def delete(cls,
               url,
               params=None,
               retries=None,
               headers=None,
               proxies=None,
               verify=None):
        """
        Send a DELETE request.

        :param url: The URL to send the DELETE request to.
        :type url: str
        :param params: The DELETE parameters to send in the request.
        :type params: dict
        :param retries: Number of retries before stopping.
        :type retries: int
        :param headers: header info for requests.
        :type headers: dict
        :param proxies: proxy info for requests.
        :type proxies: dict
        :param verify: verify info for requests.
        :type verify: bool, str
        :returns: dict (using json.loads())
        """

        if not params:
            params = dict()
        if headers is None:
            headers = get_headers()
        if proxies is None:
            proxies = get_proxies()
        if verify is None:
            verify = get_verify()

        params[t.ACCESS_TOKEN] = get_access_token()
        session = cls.build_session(retries)
        resp = session.delete(url,
                              params=params,
                              headers=headers,
                              proxies=proxies,
                              verify=verify)
        return cls.handle_results(resp)
Exemple #3
0
    def get_generator(cls,
                      klass,
                      url,
                      to_dict=False,
                      params=None,
                      retries=None,
                      headers=None,
                      proxies=None,
                      verify=None):
        """
        Generator for managing GET requests. For each GET request it will yield
        the next object in the results until there are no more objects. If the
        GET response contains a 'next' value in the 'paging' section, the
        generator will automatically fetch the next set of results and continue
        the process until the total limit has been reached or there is no longer
        a 'next' value.

        :param klass: The class to use for the generator.
        :type klass: class
        :param url: The URL to send the GET request to.
        :type url: str
        :param to_dict: Return a dictionary instead of an instantiated class.
        :type to_dict: bool
        :param params: The GET parameters to send in the request.
        :type params: dict
        :param retries: Number of retries before stopping.
        :type retries: int
        :param headers: header info for requests.
        :type headers: dict
        :param proxies: proxy info for requests.
        :type proxies: dict
        :param verify: verify info for requests.
        :type verify: bool, str
        :returns: Generator
        """

        if not klass:
            raise pytxValueError('Must provide a valid object to query.')
        if not params:
            params = dict()
        if headers is None:
            headers = get_headers()
        if proxies is None:
            proxies = get_proxies()
        if verify is None:
            verify = get_verify()
        next_ = True
        while next_:
            results = cls.get(url,
                              params=params,
                              retries=retries,
                              headers=headers,
                              proxies=proxies,
                              verify=verify)
            if do_log():
                try:
                    has_paging = results.get(t.PAGING, None)
                    before = ''
                    after = ''
                    if has_paging != None:
                        before = results[t.PAGING][p.CURSORS].get(pc.BEFORE,
                                                                  'None'
                                                                  )
                        after = results[t.PAGING][p.CURSORS].get(pc.AFTER,
                                                                 'None'
                                                                 )
                    count = len(results[t.DATA])
                    log_message(
                        'Cursor: BEFORE: %s, AFTER: %s, LEN: %d' % (before,
                                                                    after,
                                                                    count
                                                                    )
                    )
                except Exception, e:
                    log_message('Missing key in response: %s' % e)
            for data in results[t.DATA]:
                if to_dict:
                    yield data
                else:
                    yield cls.get_new(klass, data)
            try:
                next_ = results[t.PAGING][t.NEXT]
            except:
                log_message('No next in Pager to follow.')
                next_ = False
            if next_:
                url = next_
                params = {}
Exemple #4
0
    def get_generator(cls,
                      klass,
                      url,
                      to_dict=False,
                      params=None,
                      retries=None,
                      headers=None,
                      proxies=None,
                      verify=None):
        """
        Generator for managing GET requests. For each GET request it will yield
        the next object in the results until there are no more objects. If the
        GET response contains a 'next' value in the 'paging' section, the
        generator will automatically fetch the next set of results and continue
        the process until the total limit has been reached or there is no longer
        a 'next' value.

        :param klass: The class to use for the generator.
        :type klass: class
        :param url: The URL to send the GET request to.
        :type url: str
        :param to_dict: Return a dictionary instead of an instantiated class.
        :type to_dict: bool
        :param params: The GET parameters to send in the request.
        :type params: dict
        :param retries: Number of retries before stopping.
        :type retries: int
        :param headers: header info for requests.
        :type headers: dict
        :param proxies: proxy info for requests.
        :type proxies: dict
        :param verify: verify info for requests.
        :type verify: bool, str
        :returns: Generator
        """

        if not klass:
            raise pytxValueError('Must provide a valid object to query.')
        if not params:
            params = dict()
        if headers is None:
            headers = get_headers()
        if proxies is None:
            proxies = get_proxies()
        if verify is None:
            verify = get_verify()
        next_ = True
        while next_:
            results = cls.get(url,
                              params=params,
                              retries=retries,
                              headers=headers,
                              proxies=proxies,
                              verify=verify)
            if do_log():
                try:
                    has_paging = results.get(t.PAGING, None)
                    before = ''
                    after = ''
                    if has_paging != None:
                        before = results[t.PAGING][p.CURSORS].get(pc.BEFORE,
                                                                  'None'
                                                                  )
                        after = results[t.PAGING][p.CURSORS].get(pc.AFTER,
                                                                 'None'
                                                                 )
                    count = len(results[t.DATA])
                    log_message(
                        'Cursor: BEFORE: %s, AFTER: %s, LEN: %d' % (before,
                                                                    after,
                                                                    count
                                                                    )
                    )
                except Exception, e:
                    log_message('Missing key in response: %s' % e)
            for data in results[t.DATA]:
                if to_dict:
                    yield data
                else:
                    yield cls.get_new(klass, data)
            try:
                next_ = results[t.PAGING][t.NEXT]
            except:
                log_message('No next in Pager to follow.')
                next_ = False
            if next_:
                url = next_
                params = {}