api-client: update to match api
This commit is contained in:
parent
2ca34bccad
commit
f9640d6166
|
@ -38,77 +38,32 @@ class APIWrapper {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
get_child_object(endpoint, class_type){
|
|
||||||
return this.get(endpoint).then(x => new class_type(this, x))
|
|
||||||
}
|
|
||||||
|
|
||||||
get url_base(){
|
get url_base(){
|
||||||
return this.#base
|
return this.#base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PistonEngineRepositoryPackage extends APIWrapper {
|
|
||||||
constructor(repo, {language, language_version, author, buildfile, size, dependencies, installed}){
|
|
||||||
super(url_join(repo.url_base, `/packages/${language}/${language_version}`))
|
|
||||||
|
|
||||||
this.language = language;
|
|
||||||
this.language_version = language_version;
|
|
||||||
this.author = author;
|
|
||||||
this,buildfile = buildfile;
|
|
||||||
this.size = size;
|
|
||||||
this.dependencies = dependencies;
|
|
||||||
this.installed = installed;
|
|
||||||
}
|
|
||||||
|
|
||||||
install(){
|
|
||||||
return this.post('/', {});
|
|
||||||
}
|
|
||||||
|
|
||||||
uninstall(){
|
|
||||||
return this.delete('/', {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PistonEngineRepository extends APIWrapper {
|
|
||||||
|
|
||||||
constructor(engine, {slug, url, packages}){
|
|
||||||
super(url_join(engine.url_base,`/repos/${slug}`))
|
|
||||||
|
|
||||||
this.slug = slug;
|
|
||||||
this.url = url;
|
|
||||||
this.package_count = packages
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
list_packages(){
|
|
||||||
return this.get(`/packages`).then(x=>x.packages)
|
|
||||||
}
|
|
||||||
|
|
||||||
get_package(language, language_version){
|
|
||||||
return this.get_child_object(`/packages/${language}/${language_version}`, PistonEngineRepositoryPackage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PistonEngine extends APIWrapper {
|
class PistonEngine extends APIWrapper {
|
||||||
constructor(base_url = 'http://127.0.0.1:6969'){
|
constructor(base_url = 'http://127.0.0.1:6969'){
|
||||||
super(base_url);
|
super(base_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
list_repos(){
|
|
||||||
return this.get(`/repos`);
|
|
||||||
}
|
|
||||||
|
|
||||||
add_repo(slug, url){
|
|
||||||
return this.post(`/repos`, {slug, url})
|
|
||||||
}
|
|
||||||
|
|
||||||
get_repo(slug){
|
|
||||||
return this.get_child_object(`/repos/${slug}`, PistonEngineRepository)
|
|
||||||
}
|
|
||||||
|
|
||||||
run_job({language, version, files, main, args, stdin, compile_timeout, run_timeout}){
|
run_job({language, version, files, main, args, stdin, compile_timeout, run_timeout}){
|
||||||
return this.post(`/jobs`, {language, version, files, main, args, stdin, compile_timeout, run_timeout})
|
return this.post(`/jobs`, {language, version, files, main, args, stdin, compile_timeout, run_timeout})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_packages(){
|
||||||
|
return this.get('/packages').then(x=>x.packages)
|
||||||
|
}
|
||||||
|
|
||||||
|
install_package({language, version}){
|
||||||
|
return this.post(`/packages/${language}/${version}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall_package({language, version}){
|
||||||
|
return this.post(`/packages/${language}/${version}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue