def post_item_image(self, item_id, image):
        url = "api/v1/item/%s/image" % item_id
        dao = SPOTSEEKER_DAO()
        if isinstance(dao._getDAO(), File):
            resp = dao.putURL(url, {})
            content = resp.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.SPOTSEEKER_HOST + "/" + url
                files = {'image': ('image.jpg', StringIO.StringIO(image))}

                # Using requests lib here as urllib does not have good support
                # for multipart form uploads.
                r = requests.post(full_url,
                                  files=files,
                                  auth=auth,
                                  headers=headers)
                if r.status_code != 201:
                    raise DataFailureException(url, r.status_code, r.content)
            except AttributeError as ex:
                raise ImproperlyConfigured("Must set OAUTH_ keys in settings")
Exemple #2
0
    def post_item_image(self, item_id, image):
        url = "api/v1/item/%s/image" % item_id
        dao = SPOTSEEKER_DAO()
        if isinstance(dao._getDAO(), File):
            resp = dao.putURL(url, {})
            content = resp.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.SPOTSEEKER_HOST + "/" + url
                files = {'image': ('image.jpg', StringIO.StringIO(image))}

                # Using requests lib here as urllib does not have good support
                # for multipart form uploads.
                r = requests.post(full_url,
                                  files=files,
                                  auth=auth,
                                  headers=headers)
                if r.status_code != 201:
                    raise DataFailureException(url, r.status_code, r.content)
            except AttributeError as ex:
                raise ImproperlyConfigured("Must set OAUTH_ keys in settings")
    def put_spot(self, spot_id, spot_json, etag):
        url = "/api/v1/spot/%s" % spot_id
        dao = SPOTSEEKER_DAO()

        if isinstance(dao._getDAO(), File):
            resp = dao.putURL(url, {})
            content = resp.data
        else:
            try:
                headers = {"X-OAuth-User": settings.OAUTH_USER,
                           "If-Match": etag}
                resp, content = dao.putURL(url,
                                           headers,
                                           spot_json)
            except AttributeError:
                raise ImproperlyConfigured("Must set OAUTH_USER in settings")

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
Exemple #4
0
    def put_spot(self, spot_id, spot_json, etag):
        url = "/api/v1/spot/%s" % spot_id
        dao = SPOTSEEKER_DAO()

        if isinstance(dao._getDAO(), File):
            resp = dao.putURL(url, {})
            content = resp.data
        else:
            try:
                headers = {
                    "X-OAuth-User": settings.OAUTH_USER,
                    "If-Match": etag
                }
                resp, content = dao.putURL(url, headers, spot_json)
            except AttributeError:
                raise ImproperlyConfigured("Must set OAUTH_USER in settings")

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