Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 161 and 162
rest
Commits
6c149cd7
Commit
6c149cd7
authored
4 years ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Backported updated RESTConnection.
parent
fa7c4c06
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+1
-1
1 addition, 1 deletion
main.py
openmrs.py
+13
-9
13 additions, 9 deletions
openmrs.py
with
14 additions
and
10 deletions
main.py
+
1
−
1
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
):
...
...
This diff is collapsed.
Click to expand it.
openmrs.py
+
13
−
9
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment