def next(self): if int(self.last_response.status_code) not in [200]: raise UserWarning("request failed with %s: %s -> %s" % (self.last_response.status_code, repr(self.last_response.request.url), repr(self.last_response.content))) last_response_json = self.last_response.json() last_response_headers = self.last_response.headers # print "headers", last_response_headers links_str = last_response_headers.get('link', '') for link in SanitationUtils.findall_wc_links(links_str): if link.get('rel') == 'next' and link.get('url'): self.last_response = self.api.get(link['url']) return last_response_json raise StopIteration()
def test_findall_wc_links(self): results = SanitationUtils.findall_wc_links( '<http://www.annachandler.com/wc-api/v3/products?filter[meta]=true' + '&oauth_consumer_key=ck_ed0a5ae4658a895dbdf6e4009d81a850e1ec3347' + '&oauth_timestamp=1464927585&oauth_nonce=f8bbaf5c3795d1e7dd76112f5290465301e2a7d6' + '&oauth_signature_method=HMAC-SHA256' + '&oauth_signature=WsQCgHfubKIHHRkKS3879NwzQEImMPcHEtxh8aiBg7A=&page=2>; rel="next", ' '<http://www.annachandler.com/wc-api/v3/products?filter[meta]=true' + '&oauth_consumer_key=ck_ed0a5ae4658a895dbdf6e4009d81a850e1ec3347' + '&oauth_timestamp=1464927585&oauth_nonce=f8bbaf5c3795d1e7dd76112f5290465301e2a7d6' + '&oauth_signature_method=HMAC-SHA256&' + 'oauth_signature=WsQCgHfubKIHHRkKS3879NwzQEImMPcHEtxh8aiBg7A=&page=31>; rel="last"' ) print results
def next(self): assert self.last_response.status_code not in [404] last_response_json = self.last_response.json() print "last_response:", self.last_response, self.last_response.text if int(self.last_response.status_code) not in [200]: raise UserWarning( "request failed with %s: %s" % (self.last_response.status_code, self.last_response.text)) last_response_headers = self.last_response.headers links_str = last_response_headers.get('link', '') for link in SanitationUtils.findall_wc_links(links_str): if link.get('rel') == 'next' and link.get('url'): self.last_response = self.api.get( self.api.__get_endpoint(link['url'])) return last_response_json raise StopIteration()