Пример #1
0
    def request_username(password):
        """This function is responsable for requesting the username from the ah website.
        The other data that is given is not used (like address)"""

        response = requests.post(AHConnector.HOST + "/rest/ah/v1/members",
                                 json.dumps({"password": password}),
                                 headers={'Content-Type': 'application/json'})
        if succes(response.status_code):
            return str(response.json()['memberId'])
Пример #2
0
    def request(self, method, host, url, parameters=None, body=None):
        headers = {"x-jumbo-token": self.token}

        response = requests.request(method,
                                    host + url,
                                    params=parameters,
                                    data=body,
                                    headers=headers)
        if succes(response.status_code):
            self.token = response.headers["x-jumbo-token"]
            return response.json()
Пример #3
0
    def response(method, host, url, parameters, body, username, password):
        """This function is responsable for executing the requested method on the given host with the url as path.
        Parameters and body are optional and can be None. WARNING! body is always used when given!
        The username and password are requested when creating the AHConnector."""

        headers = {
            # "Accept": "application/vnd.ah.taxonomy.category.product.withfilters+json", # header not needed
            "Content-Type":
            "application/json",  # header needed
            "Deliver-Errors-In-Json":
            "true",  # header optional
            "X-ClientName":
            "android",  # header needed
            "X-ClientVersion":
            "5.2.1",  # header needed
            "X-Digest":
            AHConnector.calculate_xdigest(parameterize_url(url, parameters),
                                          body, username),  # header needed
            "User-Agent":
            "android/5.2.1 Model/phone Android/6.0.1-API23 Member/" +
            username,  # header needed
            "Authorization":
            "Basic " +
            base64.b64encode(bytes("{}:{}".format(username, password),
                                   "utf-8")).decode("UTF-8"),  # header needed
            "Host":
            "ms.ah.nl",  # header needed
            # "Connection": "Keep-Alive", # header not needed
            # "Accept-Encoding": "gzip"   # header not needed
        }
        try:
            result = requests.request(method,
                                      host + url,
                                      params=parameters,
                                      headers=headers)

            if succes(result.status_code):  # check if not failed!
                return result.json()
        except Exception as e:
            print(e)
Пример #4
0
 def get_stores():
     result = requests.get(JumboConnector.HOST + JumboConnector.STORES)
     if succes(result.status_code):
         return result.json()["stores"]["data"]
Пример #5
0
 def get_token():
     result = requests.get(JumboConnector.HOST + "/v2/configuration")
     if succes(result.status_code):
         return result.headers["x-jumbo-token"]
Пример #6
0
    def request_password():
        """It requests a password from the ah server.."""

        response = requests.get(AHConnector.HOST + AHConnector.GEN_PASSWORD)
        if succes(response.status_code):
            return str(response.json()['password'])