Exemplo n.º 1
0
    def post_image(self, spot_id, image):
        url = "api/v1/spot/%s/image" % spot_id
        implementation = Spotseeker_DAO().get_implementation()

        if implementation.is_mock():
            response = Spotseeker_DAO().putURL(url, {})
            content = response.data
            return content
        else:
            try:
                headers = {"X-OAuth-User": settings.OAUTH_USER}
                auth = OAuth1(settings.SPOTSEEKER_OAUTH_KEY,
                              settings.SPOTSEEKER_OAUTH_SECRET)
                full_url = settings.RESTCLIENTS_SPOTSEEKER_HOST + "/" + url
                files = {'image': ('image.jpg', image)}

                response = requests.post(full_url,
                                         files=files,
                                         auth=auth,
                                         headers=headers)
                if response.status_code != 201:
                    raise DataFailureException(url, response.status_code,
                                               response.content)
            except AttributeError:
                raise NotConfigured("must set OAUTH_ keys in settings")
Exemplo n.º 2
0
    def _get_image(self, image_app_type, parent_id, image_id, width=None):
        if width is not None:
            url = "/api/v1/%s/%s/image/%s/thumb/constrain/width:%s" % (
                image_app_type, parent_id, image_id, width)
        else:
            url = "/api/v1/%s/%s/image/%s" % (image_app_type, parent_id,
                                              image_id)
        implementation = Spotseeker_DAO().get_implementation()
        if implementation.is_mock():
            response = Spotseeker_DAO().getURL(url)
            content = response.data
        else:
            response = Spotseeker_DAO().getURL(url)
            content = response.data

        return response, content
Exemplo n.º 3
0
    def delete_item_image(self, item_id, image_id, etag):
        url = "/api/v1/item/%s/image/%s" % (item_id, image_id)
        implementation = Spotseeker_DAO().get_implementation()

        if implementation.is_mock():
            response = mock.Mock()
            response.status = 200
        else:
            try:
                headers = {
                    "X-OAuth-User": settings.OAUTH_USER,
                    "If-Match": etag
                }
                response = Spotseeker_DAO().deleteURL(url, headers)
                content = response.data
            except AttributeError:
                raise NotConfigured("Must set OAUTH_USER in settings")
        if response.status != 200:
            raise DataFailureException(url, response.status, content)
Exemplo n.º 4
0
    def post_spot(self, spot_json):
        url = "/api/v1/spot"
        implementation = Spotseeker_DAO().get_implementation()

        if implementation.is_mock():
            response = Spotseeker_DAO().postURL(url)
            content = response.data
        else:
            try:
                headers = {
                    "X-OAuth-User": settings.OAUTH_USER,
                    "Content-Type": "application/json"
                }
                response = Spotseeker_DAO().postURL(url, headers, spot_json)
                content = response.data
            except AttributeError:
                raise NotConfigured("Must set OAUTH_USER in settings")

        if response.status != 201:
            raise DataFailureException(url, response.status, content)
        return response
Exemplo n.º 5
0
    def put_spot(self, spot_id, spot_json, etag):
        url = "/api/v1/spot/%s" % spot_id
        implementation = Spotseeker_DAO().get_implementation()

        if implementation.is_mock():
            response = Spotseeker_DAO().putURL(url, {})
            content = response.data
        else:
            try:
                headers = {
                    "X-OAuth-User": settings.OAUTH_USER,
                    "If-Match": etag
                }
                response = Spotseeker_DAO().putURL(url, headers, spot_json)
                content = response.data
            except AttributeError:
                raise NotConfigured("Must set OAUTH_USER in settings")

        if response.status != 200:
            raise DataFailureException(url, response.status, content)
        return response, content