@@ -4,6 +4,8 @@ import type { Input } from './ContentTypeHelper';
44import { DataFile , DataDir } from './Data' ;
55import { URLSearchParams } from 'url' ;
66import { Organization , OrgType , OrgTypes } from './Algorithm' ;
7+ import dotenv from 'dotenv' ;
8+ dotenv . config ( ) ;
79
810class AlgorithmiaClient {
911 private defaultApiAddress = 'https://api.algorithmia.com' ;
@@ -23,16 +25,15 @@ class AlgorithmiaClient {
2325 apiAddress ||
2426 process . env . ALGORITHMIA_API_ADDRESS ||
2527 this . defaultApiAddress ;
26- this . key = key || process . env . ALGORITHMIA_API_KEY || '' ;
28+ this . key = key || process . env . ALGORITHMIA_DEFAULT_API_KEY || '' ;
2729 if ( key ) {
2830 if ( key . startsWith ( 'Simple ' ) ) {
2931 this . key = key ;
3032 } else {
3133 this . key = 'Simple ' + key ;
3234 }
33- } else {
34- this . key = '' ;
3535 }
36+
3637 this . httpClient = new HttpClient ( this . key ) ;
3738 }
3839
@@ -60,6 +61,41 @@ class AlgorithmiaClient {
6061 ) ;
6162 }
6263
64+ /**
65+ * Get an Algorithm build object from this client
66+ * @param userName the algorithmia user name
67+ * @param algoName the name of the algorithm
68+ * @return an Algorithm build object for the specified algorithm
69+ */
70+ buildAlgo ( userName : string , algoName : string ) {
71+ return this . httpClient . post (
72+ `${ this . apiAddress } ${ this . algorithmsPrefix } /${ userName } /${ algoName } /compile` ,
73+ { } ,
74+ 'application/json'
75+ ) ;
76+ }
77+
78+ /**
79+ * Get an Algorithm published object from this client
80+ * @param userName the algorithmia user name
81+ * @param algoName the name of the algorithm
82+ * @return an Algorithm published object for the specified algorithm
83+ */
84+ publishAlgo ( userName : string , algoName : string ) {
85+ return this . httpClient . post (
86+ `${ this . apiAddress } ${ this . algorithmsPrefix } /${ userName } /${ algoName } /version` ,
87+ {
88+ settings : {
89+ algorithm_callability : 'private' ,
90+ insights_enabled : false ,
91+ royalty_microcredits : 0 ,
92+ } ,
93+ version_info : { version_type : 'revision' } ,
94+ } ,
95+ 'application/json'
96+ ) ;
97+ }
98+
6399 /**
64100 * List algorithm versions from this client
65101 * @param userName the users Algorithmia user name
@@ -130,8 +166,9 @@ class AlgorithmiaClient {
130166 * @return a BuildLogs object for the specified algorithm
131167 */
132168 getAlgoBuildLogs ( userName : string , algoName : string , buildId : string ) {
133- const path = `${ this . algorithmsPrefix } /${ userName } /${ algoName } /builds/${ buildId } /logs` ;
134- return this . httpClient . get ( `${ this . apiAddress } ${ path } ` ) ;
169+ return this . httpClient . get (
170+ `${ this . apiAddress } ${ this . algorithmsPrefix } /${ userName } /${ algoName } /builds/${ buildId } /logs`
171+ ) ;
135172 }
136173
137174 /**
@@ -239,6 +276,17 @@ class AlgorithmiaClient {
239276 ) ;
240277 }
241278
279+ /**
280+ * Delete an organization from this client
281+ * @param orgName the organization name
282+ * @return an empty response
283+ */
284+ deleteOrganization ( orgName : string ) {
285+ return this . httpClient . delete (
286+ `${ this . apiAddress } ${ this . organizationsPrefix } /${ orgName } `
287+ ) ;
288+ }
289+
242290 clone ( obj : Input ) {
243291 return JSON . parse ( JSON . stringify ( obj ) ) ;
244292 }
0 commit comments