@@ -123,6 +123,43 @@ export class OFS {
123123 return fetchPromise ;
124124 }
125125
126+ private _post ( partialURL : string , data : any ) : Promise < OFSResponse > {
127+ var theURL = new URL ( partialURL , this . _baseURL ) ;
128+ var myHeaders = new Headers ( ) ;
129+ myHeaders . append ( "Authorization" , this . authorization ) ;
130+ myHeaders . append ( "Content-Type" , "application/json" ) ;
131+ var requestOptions : RequestInit = {
132+ method : "POST" ,
133+ headers : myHeaders ,
134+ body : JSON . stringify ( data ) ,
135+ } ;
136+ const fetchPromise = fetch ( theURL , requestOptions )
137+ . then ( async function ( response ) {
138+ // Your code for handling the data you get from the API
139+ if ( response . status < 400 ) {
140+ var data = await response . json ( ) ;
141+ return new OFSResponse (
142+ theURL ,
143+ response . status ,
144+ undefined ,
145+ data
146+ ) ;
147+ } else {
148+ return new OFSResponse (
149+ theURL ,
150+ response . status ,
151+ response . statusText ,
152+ await response . json ( )
153+ ) ;
154+ }
155+ } )
156+ . catch ( ( error ) => {
157+ console . log ( "error" , error ) ;
158+ return new OFSResponse ( theURL , - 1 ) ;
159+ } ) ;
160+ return fetchPromise ;
161+ }
162+
126163 private _postMultiPart (
127164 partialURL : string ,
128165 data : FormData
@@ -174,12 +211,57 @@ export class OFS {
174211 return fetchPromise ;
175212 }
176213
177- // Specific functions
214+ private _delete ( partialURL : string ) : Promise < OFSResponse > {
215+ var theURL = new URL ( partialURL , this . _baseURL ) ;
216+ var myHeaders = new Headers ( ) ;
217+ myHeaders . append ( "Authorization" , this . authorization ) ;
218+ var requestOptions = {
219+ method : "DELETE" ,
220+ headers : myHeaders ,
221+ } ;
222+ const fetchPromise = fetch ( theURL , requestOptions )
223+ . then ( async function ( response ) {
224+ // Your code for handling the data you get from the API
225+ if ( response . status == 204 ) {
226+ return new OFSResponse (
227+ theURL ,
228+ response . status ,
229+ undefined ,
230+ undefined
231+ ) ;
232+ } else {
233+ return new OFSResponse (
234+ theURL ,
235+ response . status ,
236+ response . statusText ,
237+ await response . json ( )
238+ ) ;
239+ }
240+ } )
241+ . catch ( ( error ) => {
242+ console . log ( "error" , error ) ;
243+ return new OFSResponse ( theURL , - 1 ) ;
244+ } ) ;
245+ return fetchPromise ;
246+ }
247+
248+ // Core: Subscription Management
178249 async getSubscriptions ( ) : Promise < OFSSubscriptionResponse > {
179250 const partialURL = "/rest/ofscCore/v1/events/subscriptions" ;
180251 return this . _get ( partialURL ) ;
181252 }
182253
254+ // Core: Activity Management
255+ async createActivity ( data : any ) : Promise < OFSResponse > {
256+ const partialURL = "/rest/ofscCore/v1/activities" ;
257+ return this . _post ( partialURL , data ) ;
258+ }
259+
260+ async deleteActivity ( aid : number ) : Promise < OFSResponse > {
261+ const partialURL = `/rest/ofscCore/v1/activities/${ aid } ` ;
262+ return this . _delete ( partialURL ) ;
263+ }
264+
183265 async getActivityDetails ( aid : number ) : Promise < OFSActivityResponse > {
184266 const partialURL = `/rest/ofscCore/v1/activities/${ aid } ` ;
185267 return this . _get ( partialURL ) ;
@@ -189,6 +271,7 @@ export class OFS {
189271 return this . _patch ( partialURL , data ) ;
190272 }
191273
274+ // Metadata: Plugin Management
192275 async importPlugins ( file ?: PathLike , data ?: string ) : Promise < OFSResponse > {
193276 const partialURL =
194277 "/rest/ofscMetadata/v1/plugins/custom-actions/import" ;
0 commit comments