Beispiel #1
0
 def _make_signed_request(self,
                          method_name,
                          relative_url,
                          params=None,
                          data=None):
     params = params or {}
     data = data or {}
     serialized = None
     headers = self.get_default_header()
     headers['X-Api-Key'] = self.api_key
     date_header = datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
     headers['Date'] = date_header
     default_params = self.get_default_params()
     default_params.update(params)
     url = self.get_full_url('api', relative_url)
     serialized = serializer.dumps(data)
     method = getattr(self.session, method_name)
     if method_name in ['post', 'put']:
         serialized = serializer.dumps(data)
     response = method(url,
                       auth=self.auth,
                       data=serialized,
                       headers=headers,
                       params=default_params,
                       timeout=self.timeout)
     logger.debug('stream api call %s, headers %s data %s', response.url,
                  headers, data)
     return self._parse_response(response)
Beispiel #2
0
 def _make_request(self,
                   method,
                   relative_url,
                   signature,
                   params=None,
                   data=None):
     params = params or {}
     data = data or {}
     default_params = self.get_default_params()
     default_params.update(params)
     headers = {'Authorization': signature}
     headers['Content-type'] = 'application/json'
     headers['User-Agent'] = self.get_user_agent()
     url = self.get_full_url(relative_url)
     serialized = serializer.dumps(data)
     response = method(url,
                       data=serialized,
                       headers=headers,
                       params=default_params,
                       timeout=self.timeout)
     logger.debug('stream api call %s, headers %s data %s', response.url,
                  headers, data)
     try:
         parsed_result = serializer.loads(response.text)
     except ValueError:
         parsed_result = None
     if parsed_result.get('exception') or response.status_code >= 500:
         self.raise_exception(parsed_result,
                              status_code=response.status_code)
     return parsed_result
Beispiel #3
0
    def _make_request(self,
                      method,
                      relative_url,
                      signature,
                      service_name='api',
                      params=None,
                      data=None):
        params = params or {}
        data = data or {}
        serialized = None
        default_params = self.get_default_params()
        default_params.update(params)
        headers = self.get_default_header()
        headers['Authorization'] = signature
        headers['stream-auth-type'] = 'jwt'

        if not relative_url.endswith('/'):
            relative_url += '/'

        url = self.get_full_url(service_name, relative_url)

        if method.__name__ in ['post', 'put', 'delete']:
            serialized = serializer.dumps(data)
        response = method(url,
                          data=serialized,
                          headers=headers,
                          params=default_params,
                          timeout=self.timeout)
        logger.debug('stream api call %s, headers %s data %s', response.url,
                     headers, data)
        return self._parse_response(response)
Beispiel #4
0
    def _make_request(
        self,
        method,
        relative_url,
        signature,
        service_name="api",
        params=None,
        data=None,
    ):
        params = params or {}
        data = data or {}
        serialized = None
        default_params = self.get_default_params()
        default_params.update(params)
        headers = self.get_default_header()
        headers["Authorization"] = signature
        headers["stream-auth-type"] = "jwt"

        if not relative_url.endswith("/"):
            relative_url += "/"

        url = self.get_full_url(service_name, relative_url)

        if method.__name__ in ["post", "put", "delete"]:
            serialized = serializer.dumps(data)
        response = method(
            url,
            data=serialized,
            headers=headers,
            params=default_params,
            timeout=self.timeout,
        )
        logger.debug("stream api call %s, headers %s data %s", response.url,
                     headers, data)
        return self._parse_response(response)
Beispiel #5
0
 def test_serialization(self):
     today = datetime.date.today()
     now = datetime.datetime.now()
     data = dict(
         string='string', float=0.1, int=1, date=today, datetime=now)
     serialized = serializer.dumps(data)
     loaded = serializer.loads(serialized)
     self.assertEqual(data, loaded)
Beispiel #6
0
 def test_serialization(self):
     today = datetime.date.today()
     now = datetime.datetime.now()
     data = dict(
         string='string', float=0.1, int=1, date=today, datetime=now)
     serialized = serializer.dumps(data)
     loaded = serializer.loads(serialized)
     self.assertEqual(data, loaded)
Beispiel #7
0
 def test_serialization(self):
     today = datetime.date.today()
     then = datetime.datetime.now().replace(microsecond=0)
     now = datetime.datetime.now()
     data = dict(string="string", float=0.1, int=1, date=today, datetime=now, datetimenomicro=then)
     serialized = serializer.dumps(data)
     loaded = serializer.loads(serialized)
     self.assertEqual(data, loaded)
Beispiel #8
0
 def _make_signed_request(self, method_name, relative_url, params=None, data=None):
     params = params or {}
     data = data or {}
     serialized = None
     headers = self.get_default_header()
     headers['X-Api-Key'] = self.api_key
     date_header = datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
     headers['Date'] = date_header
     default_params = self.get_default_params()
     default_params.update(params)
     url = self.get_full_url(relative_url)
     serialized = serializer.dumps(data)
     method = getattr(self.session, method_name)
     if method_name in ['post', 'put']:
         serialized = serializer.dumps(data)
     response = method(url, auth=self.auth, data=serialized, headers=headers,
                       params=default_params, timeout=self.timeout)
     logger.debug('stream api call %s, headers %s data %s',
                  response.url, headers, data)
     return self._parse_response(response)
Beispiel #9
0
 def _make_request(self, method, relative_url, signature, params=None, data=None):
     params = params or {}
     data = data or {}
     default_params = self.get_default_params()
     default_params.update(params)
     headers = self.get_default_header()
     headers['Authorization'] = signature
     url = self.get_full_url(relative_url)
     serialized = serializer.dumps(data)
     response = method(url, data=serialized, headers=headers,
                       params=default_params, timeout=self.timeout)
     logger.debug('stream api call %s, headers %s data %s',
                  response.url, headers, data)
     return self._parse_response(response)
Beispiel #10
0
 def _make_request(self, method, relative_url, signature, params=None, data=None):
     params = params or {}
     data = data or {}
     serialized = None
     default_params = self.get_default_params()
     default_params.update(params)
     headers = self.get_default_header()
     headers['Authorization'] = signature
     headers['stream-auth-type'] = 'jwt'
     url = self.get_full_url(relative_url)
     if method.__name__ in ['post', 'put']:
         serialized = serializer.dumps(data)
     response = method(url, data=serialized, headers=headers,
                       params=default_params, timeout=self.timeout)
     logger.debug('stream api call %s, headers %s data %s',
                  response.url, headers, data)
     return self._parse_response(response)
Beispiel #11
0
    def _make_request(self, method, relative_url, signature, params=None, data=None):
        params = params or {}
        data = data or {}
        serialized = None
        default_params = self.get_default_params()
        default_params.update(params)
        headers = self.get_default_header()
        headers["Authorization"] = signature
        headers["stream-auth-type"] = "jwt"
        url = self.get_full_url(relative_url)
        print ("URL at line 168", url)

        if method.__name__ in ["post", "put"]:
            serialized = serializer.dumps(data)
        response = method(url, data=serialized, headers=headers, params=default_params, timeout=self.timeout)
        logger.debug("stream api call %s, headers %s data %s", response.url, headers, data)
        return self._parse_response(response)
Beispiel #12
0
    def _make_request(self, method, relative_url, authorization, params=None, data=None):
        params = params or {}
        data = data or {}

        default_params = self.get_default_params()
        default_params.update(params)

        headers = {'Authorization': authorization}
        headers['Content-type'] = 'application/json'

        url = self.base_url + relative_url

        serialized = serializer.dumps(data)
        response = method(url, data=serialized, headers=headers,
                          params=default_params)
        logger.debug('stream api call %s, headers %s data %s',
                     response.url, headers, data)
        result = serializer.loads(response.content)
        if result.get('exception'):
            self.raise_exception(result, status_code=response.status_code)
        return result
Beispiel #13
0
 def _make_request(self, method, relative_url, signature, params=None, data=None):
     params = params or {}
     data = data or {}
     default_params = self.get_default_params()
     default_params.update(params)
     headers = {'Authorization': signature}
     headers['Content-type'] = 'application/json'
     headers['User-Agent'] = self.get_user_agent()
     url = self.get_full_url(relative_url)
     serialized = serializer.dumps(data)
     response = method(url, data=serialized, headers=headers,
                       params=default_params, timeout=self.timeout)
     logger.debug('stream api call %s, headers %s data %s',
                  response.url, headers, data)
     try:
         parsed_result = serializer.loads(response.text)
     except ValueError:
         parsed_result = None
     if parsed_result.get('exception') or response.status_code >= 500:
         self.raise_exception(parsed_result, status_code=response.status_code)
     return parsed_result
Beispiel #14
0
    def _make_request(
        self,
        method,
        relative_url,
        signature,
        service_name="api",
        params=None,
        data=None,
    ):
        params = params or {}
        data = data or {}
        serialized = None
        default_params = self.get_default_params()
        default_params.update(params)
        headers = self.get_default_header()
        headers["Authorization"] = signature
        headers["stream-auth-type"] = "jwt"

        if not relative_url.endswith("/"):
            relative_url += "/"

        url = self.get_full_url(service_name, relative_url)

        if method.__name__ in ["post", "put", "delete"]:
            serialized = serializer.dumps(data)
        response = method(
            url,
            data=serialized,
            headers=headers,
            params=default_params,
            timeout=self.timeout,
        )
        logger.debug(
            "stream api call %s, headers %s data %s", response.url, headers, data
        )
        return self._parse_response(response)