WooCommerce orders change page in URL with Python OAuth HTTP request -


i fetch orders woocommerce request using oauth client from: python oauth woocommerce.

my code looks this:

import time hashlib import sha1 import hmac import binascii urllib import quote, urlencode import httplib2 collections import ordereddict import json  def key_compare(a, b):     return cmp(a[0], b[0])  class restful_client(object):     """docstring restful_client"""     def __init__(self, endpoint, consumer_key, consumer_secret):         super(restful_client, self).__init__()         self.consumer_key = consumer_key         self.consumer_secret = consumer_secret         self.endpoint = endpoint      def make_request(self, resource, params, method='get' ):         oauth_params = {             'oauth_consumer_key': self.consumer_key,             'oauth_nonce': self.gen_nonce(),             'oauth_timestamp': self.gen_timestamp(),             'oauth_signature_method': 'hmac-sha1',             # 'oauth_version':'1.0'         }         oauth_params['oauth_signature'] = self.gen_signature(             resource,             ordereddict( params.items() + oauth_params.items() ),             method         )         params = ordereddict( params.items() + oauth_params.items() )         clean_params = self.sort_params(self.normalize_params(params))         uri = endpoint + resource         p_string = urlencode(clean_params)         return httplib2.http().request(uri + '?' + p_string)      def gen_signature(self, resource, params, method):         base_request_uri = quote(self.endpoint + resource, safe = "")         clean_params = self.sort_params(             self.normalize_params(                 self.normalize_params(                     params                 )             )         )         query_string = '%26'.join([             key + '%3d' + value\             key, value in clean_params.iteritems()         ])         raw_string = '&'.join([method, base_request_uri, query_string])          hashed = hmac.new(self.consumer_secret, raw_string, sha1)         return binascii.b2a_base64( hashed.digest() )[:-1]      def normalize_string(self, string):         return quote(str(string), safe="")      def normalize_params(self, params):         return ordereddict( [             (self.normalize_string(key), self.normalize_string(value))\             key, value \             in params.iteritems()         ])      def sort_params(self, params):         return ordereddict(sorted(             params.iteritems(),             cmp=key_compare         ))      def gen_timestamp(self):         return int(time.time())      def gen_nonce(self):         return hex(self.gen_timestamp())  if __name__ == "__main__":     store_url = '<store url here>'     api_base = 'wc-api'     api_ver = 'v3'     endpoint = "%s/%s/%s/" % (store_url, api_base, api_ver)      consumer_key = '<ck here>'     consumer_secret = '<cs here>&' # & necessary api ver v3      resource = 'orders'     parameters = {}      rc = restful_client(endpoint, consumer_key, consumer_secret)     r, c = rc.make_request(resource, parameters, 'get')     print json.dumps(r, indent=1)     c = json.loads(c)     print json.dumps(c, indent=1) 

this code results in woocommerce sending 10 latest orders stored in variable c. in variable r, there more details request stored. example output variable r:

{  "status": "200",   ...,  "content-location": "<<store url>/wc-api/v3/orders?oauth_consumer_key=<ck here>&oauth_nonce=0x560bc13c&oauth_signature=ln6ibxcidsnjtfrake1cx%252fprdku%253d&oauth_signature_method=hmac-sha1&oauth_timestamp=1443610940",   "x-cache": "miss",   "x-wc-total": "1180",   ...,   "x-wc-totalpages": "118",   "-content-encoding": "gzip",   "link": "<<store url>/wc-api/v3/orders?oauth_consumer_key=<ck here>&oauth_nonce=0x560bc13c&oauth_signature=ln6ibxcidsnjtfrake1cx%2fprdku%3d&oauth_signature_method=hmac-sha1&oauth_timestamp=1443610940&page=2>; rel=\"next\", <<store url>/wc-api/v3/orders?oauth_consumer_key=<ck here>&oauth_nonce=0x560bc13c&oauth_signature=ln6ibxcidsnjtfrake1cx%2fprdku%3d&oauth_signature_method=hmac-sha1&oauth_timestamp=1443610940&page=118>; rel=\"last\"",   ...,   "content-type": "application/json; charset=utf-8",   "accept-ranges": "bytes" } 

associated key "links", there links there links on request based, , possible see request orders sent in different pages. apparently above code requesting last page.

my questions:

where in code requested page specified?

how can specify page want request , if possible change number of displayed orders per page?

every appreciated!

(my programming experience limited.)


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -