示例#1
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")
示例#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")
示例#3
0
    def get_spot_by_id(self, spot_id):
        url = "/api/v1/spot/%s" % spot_id
        dao = SPOTSEEKER_DAO()
        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
        return self._spot_from_data(json.loads(content))
示例#4
0
    def get_spot_by_id(self, spot_id):
        url = "/api/v1/spot/%s" % spot_id
        dao = SPOTSEEKER_DAO()
        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
        return self._spot_from_data(json.loads(content))
示例#5
0
 def _get_image(self, image_app_type, parent_id, image_id, width=None):
     dao = SPOTSEEKER_DAO()
     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)
     if isinstance(dao._getDAO(), File):
         resp = dao.getURL(url, {})
         content = resp.data
     else:
         resp, content = dao.getURL(url, {})
     return resp, content
示例#6
0
    def get_building_list(self, campus, app_type=None):
        url = "/api/v1/buildings?extended_info:campus=" + campus
        if app_type:
            url += "&extended_info:app_type=" + app_type

        dao = SPOTSEEKER_DAO()
        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
        return json.loads(content)
示例#7
0
    def get_building_list(self, campus, app_type=None):
        url = "/api/v1/buildings?extended_info:campus=" + campus
        if app_type:
            url += "&extended_info:app_type=" + app_type

        dao = SPOTSEEKER_DAO()
        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
        return json.loads(content)
示例#8
0
 def delete_spot(self, spot_id, etag):
     url = "/api/v1/spot/%s" % spot_id
     dao = SPOTSEEKER_DAO()
     if isinstance(dao._getDAO(), File):
         resp = dao.deleteURL(url, {})
         content = resp.data
     else:
         try:
             headers = {"X-OAuth-User": settings.OAUTH_USER,
                        "If-Match": etag}
             resp, content = dao.deleteURL(url,
                                           headers)
         except AttributeError:
             raise ImproperlyConfigured("Must set OAUTH_USER in settings")
     if resp.status != 200:
         raise DataFailureException(url, resp.status, content)
示例#9
0
    def delete_item_image(self, item_id, image_id, etag):
        url = "/api/v1/item/%s/image/%s" % (item_id, image_id)
        dao = SPOTSEEKER_DAO()

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

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
示例#10
0
 def delete_spot(self, spot_id, etag):
     url = "/api/v1/spot/%s" % spot_id
     dao = SPOTSEEKER_DAO()
     if isinstance(dao._getDAO(), File):
         resp = dao.deleteURL(url, {})
         content = resp.data
     else:
         try:
             headers = {
                 "X-OAuth-User": settings.OAUTH_USER,
                 "If-Match": etag
             }
             resp, content = dao.deleteURL(url, headers)
         except AttributeError:
             raise ImproperlyConfigured("Must set OAUTH_USER in settings")
     if resp.status != 200:
         raise DataFailureException(url, resp.status, content)
示例#11
0
    def delete_item_image(self, item_id, image_id, etag):
        url = "/api/v1/item/%s/image/%s" % (item_id, image_id)
        dao = SPOTSEEKER_DAO()

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

        if resp.status != 200:
            raise DataFailureException(url, resp.status, content)
示例#12
0
 def _get_image(self, image_app_type, parent_id, image_id, width=None):
     dao = SPOTSEEKER_DAO()
     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)
     if isinstance(dao._getDAO(), File):
         resp = dao.getURL(url, {})
         content = resp.data
     else:
         resp, content = dao.getURL(url, {})
     return resp, content
示例#13
0
    def post_spot(self, spot_json):
        url = "/api/v1/spot/"
        dao = SPOTSEEKER_DAO()

        if isinstance(dao._getDAO(), File):
            resp = dao.postURL(url, {})
            content = resp.data
        else:
            try:
                headers = {
                    "X-OAuth-User": settings.OAUTH_USER,
                    "Content-Type": "application/json"
                }
                resp, content = dao.postURL(url, headers, spot_json)
            except AttributeError:
                raise ImproperlyConfigured("Must set OAUTH_USER in settings")

        if resp.status != 201:
            raise DataFailureException(url, resp.status, content)
        return resp
示例#14
0
    def post_spot(self, spot_json):
        url = "/api/v1/spot/"
        dao = SPOTSEEKER_DAO()

        if isinstance(dao._getDAO(), File):
            resp = dao.postURL(url, {})
            content = resp.data
        else:
            try:
                headers = {"X-OAuth-User": settings.OAUTH_USER,
                           "Content-Type": "application/json"
                           }
                resp, content = dao.postURL(url,
                                            headers,
                                            spot_json)
            except AttributeError:
                raise ImproperlyConfigured("Must set OAUTH_USER in settings")

        if resp.status != 201:
            raise DataFailureException(url, resp.status, content)
        return resp
示例#15
0
    def search_spots(self, query_tuple):
        """
        Returns a list of spots matching the passed parameters.
        """

        dao = SPOTSEEKER_DAO()
        url = "/api/v1/spot?" + urlencode(query_tuple)

        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

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

        results = json.loads(content)

        spots = []
        for res in results:
            spots.append(self._spot_from_data(res))

        return spots
示例#16
0
    def all_spots(self):
        """
        Returns a list of all spots.
        """

        dao = SPOTSEEKER_DAO()
        url = "/api/v1/spot/all"

        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

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

        results = json.loads(content)

        spots = []
        for res in results:
            spots.append(self._spot_from_data(res))

        return spots
示例#17
0
    def search_spots(self, query_tuple):
        """
        Returns a list of spots matching the passed parameters.
        """

        dao = SPOTSEEKER_DAO()
        url = "/api/v1/spot?" + urlencode(query_tuple)

        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

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

        results = json.loads(content)

        spots = []
        for res in results:
            spots.append(self._spot_from_data(res))

        return spots
示例#18
0
    def all_spots(self):
        """
        Returns a list of all spots.
        """

        dao = SPOTSEEKER_DAO()
        url = "/api/v1/spot/all"

        if isinstance(dao._getDAO(), File):
            resp = dao.getURL(url, {})
            content = resp.data
        else:
            resp, content = dao.getURL(url, {})

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

        results = json.loads(content)

        spots = []
        for res in results:
            spots.append(self._spot_from_data(res))

        return spots