示例#1
0
	def get(self, auth_token=None, bucket_name=None, item_name=None):
		method = self.request.get('method')
		
		if method == 'post':
			self.post(auth_token, bucket_name, item_name)
			return
			
		if method == 'delete':
			self.delete(auth_token, bucket_name, item_name)
			return
		
		jsonp = self.request.get('jsoncallback')
		user_id, secret = decode_auth(auth_token)
		bucket_name = urllib.unquote(bucket_name.encode('ascii')).decode('utf-8')
		
		bucket = Bucket.get_by_key_name(bucket_name, parent=db.Key.from_path('User', user_id))
		if not bucket:
			return
		if not bucket.is_public and bucket.secret != secret:
			return
			
		if not item_name:
			query = Item.all().ancestor(bucket)
			items = [ item.to_dict() for item in query ]
			json = demjson.encode(items)
			if jsonp:
				json = "%s(%s)" % (jsonp, json)
			self.response.out.write(json)
		else:
			item_name = urllib.unquote(item_name.encode('ascii')).decode('utf-8')
			item = Item.get_by_key_name(item_name, parent=bucket)
			if not item:
				return
			self.response.out.write( item.to_json(jsonp) )
示例#2
0
	def get(self, auth_token=None, bucket_name=None):
			
		user_id, secret = decode_auth(auth_token)
		jsonp = self.request.get('jsoncallback')
		method = self.request.get('method')
		if method == 'post':
			return self.post(auth_token, bucket_name)
		if method == 'delete':
			return self.delete(auth_token, bucket_name)
		
		if not bucket_name:
			# /bucket/<userid>x<api_key>
			# /bucket/123xAB18c
			# list user buckets
			user = User.get_by_id(user_id)
			if not user:
				return
			if user.api_key != secret:
				return
			query = Bucket.all().ancestor(user)
			
			buckets = [ bucket.to_dict() for bucket in query ]
			json = demjson.encode(buckets)
			if jsonp:
				json = "%s(%s)" % (jsonp, json)
			self.response.out.write(json)
		else:
			bucket_name = urllib.unquote(bucket_name.encode('ascii')).decode('utf-8')
			# /bucket/<userid>x<api_key>/<bucket_name>
			# /bucket/123xAB18c/notes
			# get bucket details
			bucket = Bucket.get_by_key_name(bucket_name, parent=db.Key.from_path('User', user_id))
			if bucket and bucket.secret != secret:
				return
			self.response.out.write(bucket.to_json(jsonp))
示例#3
0
    def delete(self, auth_token=None, bucket_name=None):
        user_id, secret = decode_auth(auth_token)
        jsonp = self.request.get('jsoncallback')

        if not bucket_name:
            return
        else:
            bucket_name = urllib.unquote(
                bucket_name.encode('ascii')).decode('utf-8')

        user = User.get_by_id(user_id)
        if not user:
            return
        if user.api_key != secret:
            return
        b = Bucket.get_by_key_name(bucket_name, parent=user)
        if not b:
            return
        else:
            b.delete()
            json = demjson.encode({'response': 'bucket deleted'})
            if jsonp:
                json = "%s(%s)" % (jsonp, json)
            self.response.out.write(json)
            return
示例#4
0
    def post(self, auth_token=None, bucket_name=None, item_name=None):
        jsonp = self.request.get('jsoncallback')
        user_id, secret = decode_auth(auth_token)
        bucket_name = urllib.unquote(
            bucket_name.encode('ascii')).decode('utf-8')
        bucket = Bucket.get_by_key_name(bucket_name,
                                        parent=db.Key.from_path(
                                            'User', user_id))

        application = self.request.get('application', default_value='')
        datatype = self.request.get('datatype', default_value='')
        content = self.request.get('content', default_value='')
        exp_date = self.request.get('exp_date', default_value=None)

        if not bucket:
            return
        if bucket.secret != secret:
            return

        if not item_name:
            item_name = self.request.get('name')
        else:
            item_name = urllib.unquote(
                item_name.encode('ascii')).decode('utf-8')

        i = Item.get_by_key_name(item_name, parent=bucket)
        if i:
            upd = False
            if application:
                i.application = application
                upd = True
            if datatype:
                i.datatype = datatype
                upd = True
            if content:
                i.content = content
                upd = True
            if exp_date:
                i.exp_date = exp_date
                upd = True
            if upd:
                i.put()
        else:
            i = Item(key_name=item_name,
                     parent=bucket,
                     content=content,
                     datatype=datatype,
                     application=application,
                     exp_date=exp_date)
            i.put()
        self.response.out.write(i.to_json(jsonp))
示例#5
0
    def post(self, auth_token=None, bucket_name=None):
        user_id, secret = decode_auth(auth_token)
        jsonp = self.request.get('jsoncallback')

        if not bucket_name:
            # /bucket/<userid>x<api_key>
            # /bucket/123xAB18c
            # create new bucket
            user = User.get_by_id(user_id)
            if not user:
                return
            if user.api_key != secret:
                return
            bucket_name = self.request.get('name')
            description = self.request.get('description', default_value='')
            is_public = self.request.get('is_public', default_value='0')
            b = Bucket.get_by_key_name(bucket_name, parent=user)
            if b:
                b.description = description
                b.is_public = is_public.upper() in ('TRUE', 'YES', '1')
            else:
                b = Bucket(
                    key_name=bucket_name,
                    parent=user,
                    description=description,
                    is_public=is_public.upper() in ('TRUE', 'YES', '1'),
                )
            b.put()
            self.response.out.write(Bucket.get(b.key()).to_json(jsonp))
        else:
            # /bucket/<userid>x<bucket_secret>/<bucket_name>
            # /bucket/123xAB18c/mybucket
            # update bucket properties
            bucket_name = urllib.unquote(
                bucket_name.encode('ascii')).decode('utf-8')
            description = self.request.get('description', default_value='')
            is_public = self.request.get('is_public', default_value='undef')

            b = Bucket.get_by_auth_name(auth_token, bucket_name)
            if not b:
                return
            upd = False
            if description:
                b.description = description
                upd = True
            if is_public != 'undef':
                b.is_public = is_public.upper() in ('TRUE', 'YES', '1')
                upd = True
            if upd:
                b.put()
            self.response.out.write(Bucket.get(b.key()).to_json(jsonp))
示例#6
0
	def post(self, auth_token=None, bucket_name=None):
		user_id, secret = decode_auth(auth_token)
		jsonp = self.request.get('jsoncallback')
		
		if not bucket_name:
			# /bucket/<userid>x<api_key>
			# /bucket/123xAB18c
			# create new bucket
			user = User.get_by_id(user_id)
			if not user:
				return
			if user.api_key != secret:
				return
			bucket_name = self.request.get('name')
			description = self.request.get('description', default_value='')
			is_public = self.request.get('is_public', default_value='0')
			b = Bucket.get_by_key_name(bucket_name, parent=user)
			if b:
				b.description = description
				b.is_public = is_public.upper() in ('TRUE','YES', '1' )
			else:
				b = Bucket(
					key_name = bucket_name, 
					parent=user,
					description = description,
					is_public = is_public.upper() in ('TRUE','YES', '1' ),
					)
			b.put()
			self.response.out.write(Bucket.get(b.key()).to_json(jsonp))
		else:
			# /bucket/<userid>x<bucket_secret>/<bucket_name>
			# /bucket/123xAB18c/mybucket
			# update bucket properties
			bucket_name = urllib.unquote(bucket_name.encode('ascii')).decode('utf-8')
			description = self.request.get('description', default_value='')
			is_public = self.request.get('is_public', default_value='undef')
			
			b = Bucket.get_by_auth_name(auth_token, bucket_name)
			if not b:
				return
			upd = False
			if description:
				b.description = description
				upd = True
			if is_public != 'undef':
				b.is_public = is_public.upper() in ('TRUE','YES', '1' )
				upd = True
			if upd:
				b.put()
			self.response.out.write(Bucket.get(b.key()).to_json(jsonp))
示例#7
0
	def post(self, auth_token=None, bucket_name=None, item_name=None):
		jsonp = self.request.get('jsoncallback')
		user_id, secret = decode_auth(auth_token)
		bucket_name = urllib.unquote(bucket_name.encode('ascii')).decode('utf-8')
		bucket = Bucket.get_by_key_name(bucket_name, parent=db.Key.from_path('User', user_id))
		
		application = self.request.get('application', default_value='')
		datatype = self.request.get('datatype', default_value='')
		content = self.request.get('content', default_value='')
		exp_date = self.request.get('exp_date', default_value=None)		
				
		if not bucket:
			return
		if bucket.secret != secret:
			return
			
		if not item_name:
			item_name = self.request.get('name')
		else:
			item_name = urllib.unquote(item_name.encode('ascii')).decode('utf-8')
			
		i = Item.get_by_key_name(item_name, parent=bucket)
		if i:
			upd = False 
			if application:
				i.application = application
				upd = True
			if datatype:
				i.datatype = datatype
				upd = True
			if content:
				i.content = content
				upd = True
			if exp_date:
				i.exp_date = exp_date
				upd = True
			if upd:
				i.put()	
		else:
			i = Item(
				key_name = item_name,
				parent = bucket,
				content = content,
				datatype = datatype,
				application = application,
				exp_date = exp_date
			)
			i.put()
		self.response.out.write(i.to_json(jsonp))
示例#8
0
	def delete(self, auth_token=None, bucket_name=None, item_name=None):
		jsonp = self.request.get('jsoncallback')
		user_id, secret = decode_auth(auth_token)
		bucket_name = urllib.unquote(bucket_name.encode('ascii')).decode('utf-8')
		item_name = urllib.unquote(item_name.encode('ascii')).decode('utf-8')
		bucket = Bucket.get_by_key_name(bucket_name, parent=db.Key.from_path('User', user_id))

		if not bucket or bucket.secret != secret:
			return
			
		i = Item.get_by_key_name(item_name, parent=bucket)
		if i:
			i.delete()
			json = demjson.encode({'response': 'item deleted'})
			if jsonp:
				json = "%s(%s)" % (jsonp, json)
			self.response.out.write(json)
			return
示例#9
0
    def delete(self, auth_token=None, bucket_name=None, item_name=None):
        jsonp = self.request.get('jsoncallback')
        user_id, secret = decode_auth(auth_token)
        bucket_name = urllib.unquote(
            bucket_name.encode('ascii')).decode('utf-8')
        item_name = urllib.unquote(item_name.encode('ascii')).decode('utf-8')
        bucket = Bucket.get_by_key_name(bucket_name,
                                        parent=db.Key.from_path(
                                            'User', user_id))

        if not bucket or bucket.secret != secret:
            return

        i = Item.get_by_key_name(item_name, parent=bucket)
        if i:
            i.delete()
            json = demjson.encode({'response': 'item deleted'})
            if jsonp:
                json = "%s(%s)" % (jsonp, json)
            self.response.out.write(json)
            return
示例#10
0
    def get(self, auth_token=None, bucket_name=None, item_name=None):
        method = self.request.get('method')

        if method == 'post':
            self.post(auth_token, bucket_name, item_name)
            return

        if method == 'delete':
            self.delete(auth_token, bucket_name, item_name)
            return

        jsonp = self.request.get('jsoncallback')
        user_id, secret = decode_auth(auth_token)
        bucket_name = urllib.unquote(
            bucket_name.encode('ascii')).decode('utf-8')

        bucket = Bucket.get_by_key_name(bucket_name,
                                        parent=db.Key.from_path(
                                            'User', user_id))
        if not bucket:
            return
        if not bucket.is_public and bucket.secret != secret:
            return

        if not item_name:
            query = Item.all().ancestor(bucket)
            items = [item.to_dict() for item in query]
            json = demjson.encode(items)
            if jsonp:
                json = "%s(%s)" % (jsonp, json)
            self.response.out.write(json)
        else:
            item_name = urllib.unquote(
                item_name.encode('ascii')).decode('utf-8')
            item = Item.get_by_key_name(item_name, parent=bucket)
            if not item:
                return
            self.response.out.write(item.to_json(jsonp))
示例#11
0
    def get(self, auth_token=None, bucket_name=None):

        user_id, secret = decode_auth(auth_token)
        jsonp = self.request.get('jsoncallback')
        method = self.request.get('method')
        if method == 'post':
            return self.post(auth_token, bucket_name)
        if method == 'delete':
            return self.delete(auth_token, bucket_name)

        if not bucket_name:
            # /bucket/<userid>x<api_key>
            # /bucket/123xAB18c
            # list user buckets
            user = User.get_by_id(user_id)
            if not user:
                return
            if user.api_key != secret:
                return
            query = Bucket.all().ancestor(user)

            buckets = [bucket.to_dict() for bucket in query]
            json = demjson.encode(buckets)
            if jsonp:
                json = "%s(%s)" % (jsonp, json)
            self.response.out.write(json)
        else:
            bucket_name = urllib.unquote(
                bucket_name.encode('ascii')).decode('utf-8')
            # /bucket/<userid>x<api_key>/<bucket_name>
            # /bucket/123xAB18c/notes
            # get bucket details
            bucket = Bucket.get_by_key_name(bucket_name,
                                            parent=db.Key.from_path(
                                                'User', user_id))
            if bucket and bucket.secret != secret:
                return
            self.response.out.write(bucket.to_json(jsonp))
示例#12
0
	def delete(self, auth_token=None, bucket_name=None):
		user_id, secret = decode_auth(auth_token)
		jsonp = self.request.get('jsoncallback')
		
		if not bucket_name:
			return;
		else:
			bucket_name = urllib.unquote(bucket_name.encode('ascii')).decode('utf-8')
			
		user = User.get_by_id(user_id)
		if not user:
			return
		if user.api_key != secret:
			return
		b = Bucket.get_by_key_name(bucket_name, parent=user)
		if not b:
			return
		else:
			b.delete()
			json = demjson.encode({'response': 'bucket deleted'})
			if jsonp:
				json = "%s(%s)" % (jsonp, json)
			self.response.out.write(json)
			return