Exemplo n.º 1
0
    def _request(self, to, params):
        url = 'http://api.stackexchange.com/' + self.api_version + '/' + to
        params['site'] = params.get('site', self.root_domain)

        new_params = {}
        for k, v in params.items():
            if v is None:
                pass
            elif k in ('fromdate', 'todate'):
                # bit of a HACKish workaround for a reported issue; force to an integer
                new_params[k] = str(int(v))
            else:
                new_params[k] = self._kw_to_str(v)

        if self.app_key != None:
            new_params['key'] = self.app_key

        request_properties = dict([(x, getattr(self, x))
                                   for x in ('impose_throttling',
                                             'throttle_stop')])
        request_properties.update(self.cache_options)
        request_mgr = WebRequestManager(**request_properties)

        json, info = request_mgr.json_request(url, new_params)

        if 'quota_remaining' in json and 'quota_max' in json:
            self.rate_limit = (json['quota_remaining'], json['quota_max'])
            self.requests_used = self.rate_limit[1] - self.rate_limit[0]
            self.requests_left = self.rate_limit[0]

        return json
Exemplo n.º 2
0
    def _request(self, to, params):
        url = 'http://api.stackexchange.com/' + self.api_version + '/' + to
        params['site'] = params.get('site', self.root_domain)

        new_params = {}
        for k, v in params.items():
            if v is None:
                pass
            elif k in ('fromdate', 'todate'):
                # bit of a HACKish workaround for a reported issue; force to an integer
                new_params[k] = str(int(v))
            else:
                new_params[k] = self._kw_to_str(v)

        if self.app_key != None:
            new_params['key'] = self.app_key

        request_properties = dict([(x, getattr(self, x)) for x in ('impose_throttling', 'throttle_stop')])
        request_properties.update(self.cache_options)
        request_mgr = WebRequestManager(**request_properties)

        json, info = request_mgr.json_request(url, new_params)

        if 'quota_remaining' in json and 'quota_max' in json:
            self.rate_limit = (json['quota_remaining'], json['quota_max'])
            self.requests_used = self.rate_limit[1] - self.rate_limit[0]
            self.requests_left = self.rate_limit[0]

        return json
Exemplo n.º 3
0
    def _request(self, to, params):
        url = 'http://' + self.domain + '/' + self.api_version + '/' + to

        new_params = {}
        for k, v in params.iteritems():
            if k in ('fromdate', 'todate'):
                # bit of a HACKish workaround for a reported issue; force to an integer
                new_params[k] = str(int(v))
            else:
                new_params[k] = self._kw_to_str(v)
        if self.app_key != None:
            new_params['key'] = self.app_key

        request_properties = dict([(x, getattr(self, x))
                                   for x in ('impose_throttling',
                                             'throttle_stop')])
        request_properties.update(self.cache_options)
        request_mgr = WebRequestManager(**request_properties)

        json, info = request_mgr.json_request(url, new_params)

        self.rate_limit = (int(info.getheader('X-RateLimit-Current')),
                           int(info.getheader('X-RateLimit-Max')))
        self.requests_used = self.rate_limit[1] - self.rate_limit[0]
        self.requests_left = self.rate_limit[0]

        return json
Exemplo n.º 4
0
	def _request(self, to, params):
		url = 'http://' + self.domain + '/' + self.api_version + '/' + to

		new_params = {}
		for k, v in params.iteritems():
			new_params[k] = self._kw_to_str(v)
		if self.app_key != None:
			new_params['key'] = self.app_key

		request_properties = dict([(x, getattr(self, x)) for x in ('impose_throttling', 'throttle_stop')])
		request_properties.update(self.cache_options)
		request_mgr = WebRequestManager(**request_properties)

		json, info = request_mgr.json_request(url, new_params)

		self.rate_limit = (int(info.getheader('X-RateLimit-Current')), int(info.getheader('X-RateLimit-Max')))
		self.requests_used = self.rate_limit[1] - self.rate_limit[0]
		self.requests_left = self.rate_limit[0]

		return json
Exemplo n.º 5
0
    def build(self, url, typ, collection, kw = {}):
        mgr = WebRequestManager()
        json, info = mgr.json_request(url, kw)

        return JSONMangler.json_to_resultset(self, json, typ, collection, (self, url, typ, collection, kw))
Exemplo n.º 6
0
    def build(self, url, typ, collection, kw={}):
        mgr = WebRequestManager()
        json, info = mgr.json_request(url, kw)

        return JSONMangler.json_to_resultset(self, json, typ, collection,
                                             (self, url, typ, collection, kw))