@@ -48,6 +48,47 @@ def caltechdata_accept(ids, token=None, production=False):
4848 if result .status_code != 200 :
4949 raise Exception (result .text )
5050
51+ def caltechdata_reject (ids , token = None , production = False , authors = False ):
52+ # Reject a record from a community
53+
54+ # If no token is provided, get from RDMTOK environment variable
55+ if not token :
56+ token = os .environ ["RDMTOK" ]
57+
58+ if production == True :
59+ if authors :
60+ url = "https://authors.library.caltech.edu"
61+ else :
62+ url = "https://data.caltech.edu"
63+ else :
64+ if authors :
65+ url = "https://authors.caltechlibrary.dev"
66+ else :
67+ url = "https://data.caltechlibrary.dev"
68+
69+ headers = {
70+ "Authorization" : "Bearer %s" % token ,
71+ "Content-type" : "application/json" ,
72+ }
73+
74+ for idv in ids :
75+ result = requests .get (
76+ url + "/api/records/" + idv + "/draft/review" , headers = headers
77+ )
78+ print (url + "/api/records/" + idv + "/draft/review" )
79+ if result .status_code != 200 :
80+ raise Exception (result .text )
81+ accept_link = result .json ()["links" ]["actions" ]["decline" ]
82+ data = comment = {
83+ "payload" : {
84+ "content" : "This record was declined automatically with the CaltechDATA API" ,
85+ "format" : "html" ,
86+ }
87+ }
88+ result = requests .post (accept_link , json = data , headers = headers )
89+ if result .status_code != 200 :
90+ raise Exception (result .text )
91+
5192
5293def caltechdata_edit (
5394 idv ,
0 commit comments