11class Collections (object ):
2-
32 def __init__ (self , client , token ):
43 """
54 Used to manipulate data at the 'meta' endpoint
@@ -15,7 +14,7 @@ def create_reference(self, collection_name, id):
1514 if isinstance (id , (dict ,)) and id .get ("id" ) is not None :
1615 _id = id .get ("id" )
1716 return "SO:%s:%s" % (collection_name , _id )
18-
17+
1918 def upsert (self , collection_name , data ):
2019 """
2120 "Insert new or update existing data.
@@ -33,8 +32,12 @@ def upsert(self, collection_name, data):
3332
3433 data_json = {collection_name : data }
3534
36- response = self .client .post ('collections/' , service_name = 'api' ,
37- signature = self .token , data = {'data' : data_json })
35+ response = self .client .post (
36+ "collections/" ,
37+ service_name = "api" ,
38+ signature = self .token ,
39+ data = {"data" : data_json },
40+ )
3841 return response
3942
4043 def select (self , collection_name , ids ):
@@ -56,11 +59,15 @@ def select(self, collection_name, ids):
5659
5760 foreign_ids = []
5861 for i in range (len (ids )):
59- foreign_ids .append (' %s:%s' % (collection_name , ids [i ]))
60- foreign_ids = ',' .join (foreign_ids )
62+ foreign_ids .append (" %s:%s" % (collection_name , ids [i ]))
63+ foreign_ids = "," .join (foreign_ids )
6164
62- response = self .client .get ('collections/' , service_name = 'api' , params = {'foreign_ids' : foreign_ids },
63- signature = self .token )
65+ response = self .client .get (
66+ "collections/" ,
67+ service_name = "api" ,
68+ params = {"foreign_ids" : foreign_ids },
69+ signature = self .token ,
70+ )
6471
6572 return response
6673
@@ -80,17 +87,16 @@ def delete_many(self, collection_name, ids):
8087 ids = [ids ]
8188 ids = [str (i ) for i in ids ]
8289
83- params = {' collection_name' : collection_name , ' ids' : ids }
90+ params = {" collection_name" : collection_name , " ids" : ids }
8491
85- response = self .client .delete ('collections/' , service_name = 'api' , params = params ,
86- signature = self .token )
92+ response = self .client .delete (
93+ "collections/" , service_name = "api" , params = params , signature = self .token
94+ )
8795
8896 return response
8997
9098 def add (self , collection_name , data , id = None , user_id = None ):
91- payload = dict (
92- id = id , data = data , user_id = user_id ,
93- )
99+ payload = dict (id = id , data = data , user_id = user_id )
94100 return self .client .post (
95101 "collections/%s" % collection_name ,
96102 service_name = "api" ,
@@ -100,7 +106,9 @@ def add(self, collection_name, data, id=None, user_id=None):
100106
101107 def get (self , collection_name , id ):
102108 return self .client .get (
103- "collections/%s/%s" % (collection_name , id ), service_name = "api" , signature = self .token
109+ "collections/%s/%s" % (collection_name , id ),
110+ service_name = "api" ,
111+ signature = self .token ,
104112 )
105113
106114 def update (self , collection_name , id , data = None ):
@@ -114,5 +122,7 @@ def update(self, collection_name, id, data=None):
114122
115123 def delete (self , collection_name , id ):
116124 return self .client .delete (
117- "collections/%s/%s" % (collection_name , id ), service_name = "api" , signature = self .token
125+ "collections/%s/%s" % (collection_name , id ),
126+ service_name = "api" ,
127+ signature = self .token ,
118128 )
0 commit comments