Example #1
0
    def post_request(self, data):
        """Make an HTTP request.

        Defined solely so it can be overridden in the mock.
        """
        return HTTP.post_with_timeout(
            self.base_url,
            data,
            headers={"Content-Type": "application/xml"},
            allowed_response_codes=['2xx'],
        )
    def refresh_credential(self, credential):
        url = self.API_ENDPOINT + 'token'
        headers = {'Content-Type': self.TOKEN_CONTENT_TYPE}
        client_details = dict(client_id=self.client_id, client_secret=self.client_secret)

        response = HTTP.post_with_timeout(url, client_details, headers=headers)
        data = response.json()

        credential.credential = data.get('access_token')
        expires_in = data.get('expires_in')
        credential.expires = datetime.utcnow() + timedelta(0, expires_in * 0.9)
        self._credential = credential
    def create_content_item(self, content_item):
        content_item = self.set_timestamp(content_item, create=True)
        content_item = json.dumps(content_item)
        response = HTTP.post_with_timeout(
            self.CONTENT_ITEMS_ENDPOINT, content_item,
            headers=self.default_headers,
            allowed_response_codes=[201]
        )

        content_item = response.json()

        name = content_item.get('name')
        content_item_id = content_item.get('contentItemId')
        self.log.info(
            "New content item created for '%s': '%s'", name, content_item_id)

        return content_item
    def create_catalogue(self, name, description=None):
        catalogue = dict(name=name)
        if description:
            catalogue['description'] = description

        catalogue = json.dumps(catalogue)
        response = HTTP.post_with_timeout(
            self.CATALOGUES_ENDPOINT, catalogue,
            headers=self.default_headers,
            allowed_response_codes=[201]
        )

        catalogue = response.json()

        name = catalogue.get('name')
        catalogue_id = catalogue.get('catalogueId')
        self.log.info(
            "New catalogue '%s' created with ID: %s", name, catalogue_id)

        return catalogue
Example #5
0
 def _get_token(self, payload, headers):
     response = HTTP.post_with_timeout(self.CLEVER_TOKEN_URL,
                                       json.dumps(payload),
                                       headers=headers)
     return response.json()
Example #6
0
    def _do_post(url, payload, headers, **kwargs):
        # More time please
        if 'timeout' not in kwargs:
            kwargs['timeout'] = 60

        return HTTP.post_with_timeout(url, payload, headers=headers, **kwargs)
 def post(self, url, params):
     response = HTTP.post_with_timeout(url, params)
 def post(self, url, params):
     response = HTTP.post_with_timeout(url, params)
Example #9
0
 def _get_token(self, payload, headers):
     response = HTTP.post_with_timeout(
         self.CLEVER_TOKEN_URL, json.dumps(payload), headers=headers
     )
     return response.json()