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")
def get_backend(self): if not ConfProxy.backend: try: guess_backend() except Exception: raise NotConfigured("Must configure a commonconf backend") return ConfProxy.backend
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)
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
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