import json

import requests

from .utils import sign, gen_timestamp


__all__ = ('JDClient',)


class JDClient(object):
    """Jingdong API Client"""

    BASE_URL = 'http://gw.api.360buy.com/routerjson'

    def __init__(self, key, secret):
        self.key = key
        self.secret = secret

    def call(self, method, app_params=None):
        """Call specific method to fetch data returned by API.

        :param method: the method to be called.
        :param app_params: application parameters which are required
                           to call the specific method.
        """
        params = {
            'method': method,
            'app_key': self.key,
            'timestamp': gen_timestamp(),
            'v': '2.0',
            '360buy_param_json': json.dumps(app_params),
        }
        params['sign'] = sign(self.secret, params)
        res = requests.get(self.BASE_URL, params=params)
        res.raise_for_status()
        return json.loads(res.content, strict=False)

@@ -169,24 +169,18 @@
 http
+s
 ://
-gw.
 api.
-360buy
+jd
 .com
@@ -227,16 +227,28 @@
 , secret
+, token=None
 ):%0A     
@@ -293,16 +293,43 @@
 = secret
+%0A        self.token = token
 %0A%0A    de
@@ -831,16 +831,99 @@
       %7D%0A
+        if self.token is not None:%0A            params%5B'access_token'%5D = self.token%0A
         

add token param