Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOFT Core
SOFT 161 and 162
rest
Commits
6c149cd7
Commit
6c149cd7
authored
Jul 19, 2020
by
Brady James Garvin
Browse files
Backported updated RESTConnection.
parent
fa7c4c06
Changes
2
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
6c149cd7
...
...
@@ -13,7 +13,7 @@ class RestApp(App):
def
load_locations
(
self
):
self
.
root
.
ids
.
results
.
clear_widgets
()
self
.
openmrs_connection
.
send_request
(
'location'
,
None
,
self
.
on_locations_loaded
,
self
.
openmrs_connection
.
send_request
(
'location'
,
None
,
None
,
self
.
on_locations_loaded
,
self
.
on_locations_not_loaded
,
self
.
on_locations_not_loaded
)
def
on_locations_loaded
(
self
,
_
,
response
):
...
...
openmrs.py
View file @
6c149cd7
...
...
@@ -8,11 +8,7 @@ except ImportError:
from
urllib.parse
import
quote
class
RESTConnection
(
object
):
@
staticmethod
def
_construct_url
(
authority
,
port
,
resource
):
return
f
'http://
{
authority
}
:
{
port
}
/openmrs/ws/rest/v1/
{
resource
}
'
class
RESTConnection
:
def
__init__
(
self
,
authority
,
port
,
username
,
password
):
self
.
authority
=
authority
self
.
port
=
port
...
...
@@ -23,8 +19,16 @@ class RESTConnection(object):
'Content-type'
:
'application/json'
,
}
def
send_request
(
self
,
resource
,
post_parameters
,
on_success
,
on_failure
,
on_error
):
url
=
RESTConnection
.
_construct_url
(
self
.
authority
,
self
.
port
,
resource
)
post_parameters
=
json
.
dumps
(
post_parameters
)
if
post_parameters
is
not
None
else
None
UrlRequest
(
url
,
req_headers
=
self
.
headers
,
req_body
=
post_parameters
,
def
construct_url
(
self
,
resource
,
get_parameters
=
None
):
get_parameters
=
'&'
.
join
(
f
'
{
quote
(
str
(
key
))
}
=
{
quote
(
str
(
value
))
}
'
for
key
,
value
in
get_parameters
.
items
())
\
if
get_parameters
is
not
None
else
''
return
f
'http://
{
self
.
authority
}
:
{
self
.
port
}
/openmrs/ws/rest/v1/
{
resource
}
?
{
get_parameters
}
'
def
send_request_by_url
(
self
,
url
,
post_parameters
,
on_success
,
on_failure
,
on_error
):
UrlRequest
(
url
,
req_headers
=
self
.
headers
,
req_body
=
json
.
dumps
(
post_parameters
)
if
post_parameters
is
not
None
else
None
,
on_success
=
on_success
,
on_failure
=
on_failure
,
on_error
=
on_error
)
def
send_request
(
self
,
resource
,
get_parameters
,
post_parameters
,
on_success
,
on_failure
,
on_error
):
url
=
self
.
construct_url
(
resource
,
get_parameters
)
self
.
send_request_by_url
(
url
,
post_parameters
,
on_success
,
on_failure
,
on_error
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment