Example #1
0
    def request(self,
                method,
                version,
                path,
                data=None,
                params=None,
                json=True):

        oauth = OAuth1(six.text_type(settings.BITBUCKET_CONSUMER_KEY),
                       six.text_type(settings.BITBUCKET_CONSUMER_SECRET),
                       self.auth.tokens['oauth_token'],
                       self.auth.tokens['oauth_token_secret'],
                       signature_type='auth_header')

        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='%s%s%s' % (self.API_URL, version, path),
                auth=oauth,
                data=(data if version == '1.0' else None),
                json=(data if version == '2.0' else None),
                params=params,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)

        if resp.status_code == 204:
            return {}

        if json:
            return resp.json()
        else:
            return resp.text
Example #2
0
    def request(self, method, path, data):
        payload = {
            'k': self.privatekey,
        }
        payload.update(data)

        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='{}{}'.format(self.base_url, path),
                data=payload,
                allow_redirects=True,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #3
0
    def request(self, data):
        endpoint = 'https://alert.victorops.com/integrations/generic/20131114/alert/{}/{}'.format(
            self.api_key,
            self.routing_key,
        )

        session = build_session()
        try:
            resp = session.post(
                url=endpoint,
                json=data,
                allow_redirects=False,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #4
0
 def request(self, method, path, data=None, params=None):
     headers = {
         'Private-Token': self.token,
     }
     session = build_session()
     try:
         resp = getattr(session, method.lower())(
             url='{}/api/v4/{}'.format(self.url, path.lstrip('/')),
             headers=headers,
             json=data,
             params=params,
             allow_redirects=False,
         )
         resp.raise_for_status()
     except HTTPError as e:
         raise ApiError.from_response(e.response)
     return resp.json()
Example #5
0
    def request(self, data):
        payload = {
            'service_key': self.service_key,
        }
        payload.update(data)

        session = build_session()
        try:
            resp = session.post(
                url=INTEGRATION_API_URL,
                json=payload,
                allow_redirects=False,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #6
0
    def request(self, data):
        endpoint = 'https://alert.victorops.com/integrations/generic/20131114/alert/{}/{}'.format(
            self.api_key,
            self.routing_key,
        )

        session = build_session()
        try:
            resp = session.post(
                url=endpoint,
                json=data,
                allow_redirects=False,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #7
0
    def request(self, data):
        payload = {
            'service_key': self.service_key,
        }
        payload.update(data)

        session = build_session()
        try:
            resp = session.post(
                url=INTEGRATION_API_URL,
                json=payload,
                allow_redirects=False,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #8
0
 def request(self, method, path, data=None, params=None):
     headers = {
         'Private-Token': self.token,
     }
     session = build_session()
     try:
         resp = getattr(session, method.lower())(
             url='{}/api/v4/{}'.format(self.url, path.lstrip('/')),
             headers=headers,
             json=data,
             params=params,
             allow_redirects=False,
         )
         resp.raise_for_status()
     except HTTPError as e:
         raise ApiError.from_response(e.response)
     return resp.json()
Example #9
0
    def _request(self, method, path, headers=None, data=None, params=None):
        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='{}{}'.format(self.url, path),
                headers=headers,
                json=data,
                params=params,
                allow_redirects=True,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)

        if resp.status_code == 204:
            return {}

        return resp.json()
Example #10
0
    def request(self, method, path, data=None, params=None):
        headers = {
            'Authorization': 'token %s' % self.token,
        }

        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='{}{}'.format(self.url, path),
                headers=headers,
                json=data,
                params=params,
                allow_redirects=True,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #11
0
    def _request(self, token, method, path, data=None, params=None):
        headers = {
            'Authorization': 'Bearer %s' % token,
        }

        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='%s%s' % (self.API_URL, path),
                headers=headers,
                json=data,
                params=params,
                allow_redirects=False,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #12
0
    def request(self, method, path, data=None, params=None):
        oauth = OAuth1(unicode(settings.BITBUCKET_CONSUMER_KEY),
                       unicode(settings.BITBUCKET_CONSUMER_SECRET),
                       self.auth.tokens['oauth_token'],
                       self.auth.tokens['oauth_token_secret'],
                       signature_type='auth_header')

        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='%s%s' % (self.API_URL, path),
                auth=oauth,
                data=data,
                params=params,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #13
0
    def request(self, method, path, data):
        # see https://pushover.net/api
        # We can no longer send JSON because pushover disabled incoming
        # JSON data: http://updates.pushover.net/post/39822700181/
        payload = {
            'user': self.userkey,
            'token': self.apikey,
        }
        payload.update(data)

        session = build_session()
        try:
            resp = getattr(session, method.lower())(
                url='{}{}'.format(self.base_url, path),
                data=payload,
                allow_redirects=False,
            )
            resp.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return resp.json()
Example #14
0
    def make_request(self, method, url, payload=None):
        if url[:4] != "http":
            url = self.zendesk_url + url
        auth = self.username.encode('utf8'), self.password.encode('utf8')
        session = build_session()
        if method == 'get':
            response = session.get(url,
                                   params=payload,
                                   auth=auth,
                                   verify=False,
                                   timeout=self.HTTP_TIMEOUT)
        else:
            response = session.post(url,
                                    json=payload,
                                    auth=auth,
                                    verify=False,
                                    timeout=self.HTTP_TIMEOUT)

        try:
            response.raise_for_status()
        except HTTPError as e:
            raise ApiError.from_response(e.response)
        return response