diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-01 20:41:13 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-01 20:41:13 -0400 |
commit | da47fdfddc46e35a939b7771eda21debec50c094 (patch) | |
tree | 0eb9ac1333dd3b17e25eca6c4c96f732da357b89 | |
parent | 3e58313bde5e3e572d84fe014d9902dfb04712c3 (diff) | |
download | levitating-da47fdfddc46e35a939b7771eda21debec50c094.tar.gz levitating-da47fdfddc46e35a939b7771eda21debec50c094.zip |
Started work on API implementation
-rw-r--r-- | captain/api.f90 | 51 | ||||
-rw-r--r-- | captain/gemini.f90 | 15 | ||||
-rw-r--r-- | captain/levitating-captain.prj | 3 | ||||
-rw-r--r-- | captain/response.f90 | 18 |
4 files changed, 78 insertions, 9 deletions
diff --git a/captain/api.f90 b/captain/api.f90 new file mode 100644 index 0000000..025251d --- /dev/null +++ b/captain/api.f90 @@ -0,0 +1,51 @@ +module api_handling +implicit none + +contains + + function api_request_gemini(req) result(resp) + use server_response + implicit none + + type(request), intent(in)::req + type(response)::resp + + integer::i + + ! Complete - "/api/player/{name}/job/{jobid}/complete" + ! Failed - "/api/player/{name}/job/{jobid}/failed" + ! Task - "/api/player/{name}/job/{jobid}/task/{task num}" + if(trim(req%component(2)) == "player" .and. trim(req%component(4)) == "job") then + if(trim(req%component(6)) == "complete") then + + end if + end if + + + end function api_request_gemini + + function api_request_titan(req) result(resp) + use server_response + implicit none + + type(request), intent(in)::req + type(response)::resp + + end function api_request_titan + + function api_request(req) result(resp) + use server_response + implicit none + + type(request), intent(in)::req + type(response)::resp + + if(req%protocol == "gemini") then + resp = api_request_gemini(req) + else if(req%protocol == "titan") then + resp = api_request_titan(req) + end if + + end function api_request + +end module api_handling
\ No newline at end of file diff --git a/captain/gemini.f90 b/captain/gemini.f90 index 46725cb..8822ed5 100644 --- a/captain/gemini.f90 +++ b/captain/gemini.f90 @@ -178,6 +178,7 @@ contains use config use iso_fortran_env use external_handling, only: external_request_gemini + use api_handling, only: api_request use logging, only: write_log use server_response implicit none @@ -193,6 +194,8 @@ contains ! Requested file character(1024)::text_request + + character(32)::first integer::rendered_unit, ioerror @@ -258,13 +261,11 @@ contains call req%init(text_request) call write_log("Request object created") - if(len(req%location) .ge. 4) then - if(req%location(1:4) == '/api') then - !call handle_api_request(request) - else - resp = external_request_gemini(req) - end if - else + + call req%path_component(1, first) + if(trim(first) == 'api') then + resp = api_request(request) + else resp = external_request_gemini(req) end if diff --git a/captain/levitating-captain.prj b/captain/levitating-captain.prj index 0122d1f..415398c 100644 --- a/captain/levitating-captain.prj +++ b/captain/levitating-captain.prj @@ -49,6 +49,9 @@ }], "Name":"+levitating-captain (levitating-captain)", "Files":[{ + "filename":".\\api.f90", + "enabled":"1" + },{ "filename":".\\captian.f90", "enabled":"1" },{ diff --git a/captain/response.f90 b/captain/response.f90 index 37eaf58..e1d80eb 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -41,7 +41,8 @@ module server_response procedure :: destroy => request_destroy procedure :: last_component => request_last_component procedure :: path_component => request_component - + procedure :: component => request_component_func + end type request contains @@ -136,6 +137,19 @@ contains end if end subroutine request_component + + function request_component_func(self, i) result(res) + implicit none + + class(request) :: self + integer, intent(in)::i + character(128) :: res + + res = " " + + call self%path_component(i, res) + + end function request_component_func subroutine request_last_component(self, res) implicit none @@ -165,7 +179,7 @@ contains end if end subroutine request_last_component - + subroutine request_destroy(self) implicit none |