1616
1717class Client :
1818 def __init__ (self , url ):
19- self .url = url
19+ header = {'content-type' : 'application/json' , 'accept' :
20+ 'application/json' }
21+ self .url = url .rstrip ('/' )
22+ self .cookies = None
23+ self .header = header
2024 logger .info ('Initializing client' )
2125
2226 def authenticate (self , email , password ):
27+ header = self .header
2328 data = {'email' : email , 'password' : password }
24- header = {'content-type' : 'application/json' , 'accept' :
25- 'application/json' }
26- session = requests .post (self .url + '/rest/login' , headers = header ,
29+ session = requests .post (f'{ self .url } /login' , headers = header ,
2730 params = data ).cookies ['JSESSIONID' ]
2831 cookies = {'JSESSIONID' : session }
29- status = requests .get (self .url + '/rest /status' , headers = header ,
32+ status = requests .get (f' { self .url } /status' , headers = header ,
3033 cookies = cookies ).json ()
3134 self .user_full_name = status ['fullname' ]
3235 self .cookies = cookies
@@ -35,7 +38,7 @@ def authenticate(self, email, password):
3538
3639 def get_record (self , uuid , rec_type ):
3740 """Retrieve an individual record of a particular type."""
38- url = f'{ self .url } /rest/ { rec_type } /{ uuid } ?expand=all'
41+ url = f'{ self .url } /{ rec_type } /{ uuid } ?expand=all'
3942 record = requests .get (url , headers = self .header ,
4043 cookies = self .cookies ).json ()
4144 if rec_type == 'items' :
@@ -55,7 +58,7 @@ def filtered_item_search(self, key, string, query_type,
5558 items = ''
5659 item_links = []
5760 while items != []:
58- endpoint = f'{ self .url } /rest/ filtered-items?'
61+ endpoint = f'{ self .url } /filtered-items?'
5962 params = {'query_field[]' : key , 'query_op[]' : query_type ,
6063 'query_val[]' : string , '&collSel[]' :
6164 selected_collections , 'limit' : 200 , 'offset' : offset }
@@ -71,6 +74,17 @@ def filtered_item_search(self, key, string, query_type,
7174 offset = offset + 200
7275 return item_links
7376
77+ def post_coll_to_comm (self , comm_handle , coll_name ):
78+ endpoint = f'{ self .url } /handle/{ comm_handle } '
79+ community = requests .get (endpoint , headers = self .header ,
80+ cookies = self .cookies ).json ()
81+ comm_id = community ['uuid' ]
82+ collection = {'name' : coll_name }
83+ endpoint2 = f'{ self .url } /communities/{ comm_id } /collections'
84+ coll_id = requests .post (endpoint2 , headers = self .header ,
85+ cookies = self .cookies , json = collection ).json ()
86+ return coll_id ['link' ]
87+
7488 def _pop_inst (self , class_type , rec_obj ):
7589 """Populate class instance with data from record."""
7690 fields = [op (field ) for field in attr .fields (class_type )]
0 commit comments