Client library for Apereo OpenLRW API
Project description
# OpenLRW Python API Client
> A Python Client making your scripts for OpenLRW easier
<p align="center">
<a href='https://www.python.org/dev/peps/pep-0008/'><img src="https://img.shields.io/badge/code%20style-pep8-orange.svg" alt="code style pep 8"></a>
<a href="https://badge.fury.io/py/openlrw"><img src="https://badge.fury.io/py/openlrw.svg" alt="PyPI version"></a>
</p>
## Getting Started
` pip install openlrw `
## Usage
#### Some examples of what you can do
```python
from openlrw.client import OpenLRW
from openlrw.exceptions import ExpiredTokenException
# 1. Settings
openlrw = OpenLRW(uri, username, password) # Create an instance of the client
openlrw.setup_email('localhost', 'script@openlrw.dev', 'your_email@domain.com') # Allows you to send emails
# 2. Authentication
jwt = openlrw.generate_jwt() # Generate a JSON Web Token for using OneRoster routes
# 3. Users
try:
user = openlrw.get_user(user_id, jwt) # One user
users = openlrw.get_users(jwt) # All the users
new_user_res = openlrw.post_user(json, jwt, True) # Creates a user
patch_user_res = openlrw.patch_user(user_id, json, jwt)
delete_user_res = openlrw.delete_user(user_id, jwt)
except ExpiredTokenException:
OpenLRW.pretty_error("Error", "JWT Expired")
# 4. Line items
try:
line_item = openlrw.get_lineitem("lineItemId", jwt)
line_items = openlrw.get_lineitems(jwt)
openlrw.post_lineitem_for_a_class("classId", json, jwt, True)
openlrw.post_lineitem(json, jwt, True)
except ExpiredTokenException:
OpenLRW.pretty_error("Error", "JWT Expired")
except InternalServerErrorException as e:
script_name = str(sys.argv[0])
openlrw.mail_server(script_name + " error", str(e.message)) # Send an email with the details
exit()
except BadRequestException:
OpenLRW.pretty_error("Bad Request", "Lorem ipsum")
#5 Class
try:
openlrw.post_class(json, jwt, True)
except InternalServerErrorException as e:
script_name = str(sys.argv[0])
openlrw.mail_server(script_name + " error", str(e.message)) # Send an email with the details
exit()
except BadRequestException:
OpenLRW.pretty_error("Bad Request", "Lorem ipsum")
# 6. Result
try:
result = openlrw.post_result_for_a_class("classId", json, jwt, True)
except ExpiredTokenException:
OpenLRW.pretty_error("Error", "JWT Expired")
except InternalServerErrorException as e:
script_name = str(sys.argv[0])
openlrw.mail_server(script_name + " error", str(e.message)) # Send an email with the details
exit()
except BadRequestException:
OpenLRW.pretty_error("Bad Request", "Lorem ipsum")
# 7. Send a Caliper statement
try:
response_code = openlrw.send_caliper(statement)
except BadRequestException as e:
print(str(e.message))
OpenLRW.pretty_error("Bad Request", "An error happened.")
except InternalServerErrorException as e:
print(str(e.message))
OpenLRW.pretty_error("Internal Server Error", "An error happened.")
OpenLRW.pretty_message("Script finished", "Ask the features you want in the pull requests!")
```
> A Python Client making your scripts for OpenLRW easier
<p align="center">
<a href='https://www.python.org/dev/peps/pep-0008/'><img src="https://img.shields.io/badge/code%20style-pep8-orange.svg" alt="code style pep 8"></a>
<a href="https://badge.fury.io/py/openlrw"><img src="https://badge.fury.io/py/openlrw.svg" alt="PyPI version"></a>
</p>
## Getting Started
` pip install openlrw `
## Usage
#### Some examples of what you can do
```python
from openlrw.client import OpenLRW
from openlrw.exceptions import ExpiredTokenException
# 1. Settings
openlrw = OpenLRW(uri, username, password) # Create an instance of the client
openlrw.setup_email('localhost', 'script@openlrw.dev', 'your_email@domain.com') # Allows you to send emails
# 2. Authentication
jwt = openlrw.generate_jwt() # Generate a JSON Web Token for using OneRoster routes
# 3. Users
try:
user = openlrw.get_user(user_id, jwt) # One user
users = openlrw.get_users(jwt) # All the users
new_user_res = openlrw.post_user(json, jwt, True) # Creates a user
patch_user_res = openlrw.patch_user(user_id, json, jwt)
delete_user_res = openlrw.delete_user(user_id, jwt)
except ExpiredTokenException:
OpenLRW.pretty_error("Error", "JWT Expired")
# 4. Line items
try:
line_item = openlrw.get_lineitem("lineItemId", jwt)
line_items = openlrw.get_lineitems(jwt)
openlrw.post_lineitem_for_a_class("classId", json, jwt, True)
openlrw.post_lineitem(json, jwt, True)
except ExpiredTokenException:
OpenLRW.pretty_error("Error", "JWT Expired")
except InternalServerErrorException as e:
script_name = str(sys.argv[0])
openlrw.mail_server(script_name + " error", str(e.message)) # Send an email with the details
exit()
except BadRequestException:
OpenLRW.pretty_error("Bad Request", "Lorem ipsum")
#5 Class
try:
openlrw.post_class(json, jwt, True)
except InternalServerErrorException as e:
script_name = str(sys.argv[0])
openlrw.mail_server(script_name + " error", str(e.message)) # Send an email with the details
exit()
except BadRequestException:
OpenLRW.pretty_error("Bad Request", "Lorem ipsum")
# 6. Result
try:
result = openlrw.post_result_for_a_class("classId", json, jwt, True)
except ExpiredTokenException:
OpenLRW.pretty_error("Error", "JWT Expired")
except InternalServerErrorException as e:
script_name = str(sys.argv[0])
openlrw.mail_server(script_name + " error", str(e.message)) # Send an email with the details
exit()
except BadRequestException:
OpenLRW.pretty_error("Bad Request", "Lorem ipsum")
# 7. Send a Caliper statement
try:
response_code = openlrw.send_caliper(statement)
except BadRequestException as e:
print(str(e.message))
OpenLRW.pretty_error("Bad Request", "An error happened.")
except InternalServerErrorException as e:
print(str(e.message))
OpenLRW.pretty_error("Internal Server Error", "An error happened.")
OpenLRW.pretty_message("Script finished", "Ask the features you want in the pull requests!")
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
openlrw-1.0.2rc1.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file openlrw-1.0.2rc1.tar.gz
.
File metadata
- Download URL: openlrw-1.0.2rc1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70f1a54b33a93650fe2efe63edaa7101952ff9e1e9bc948919ea8899788460a2 |
|
MD5 | 9498bad4b9298c9ade40fc9a68bf28df |
|
BLAKE2b-256 | 9bca356b1462d26094fa636f89d7efc0f1c7a82795e9a63449ef2a418d970437 |
File details
Details for the file openlrw-1.0.2rc1-py3-none-any.whl
.
File metadata
- Download URL: openlrw-1.0.2rc1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c485c4e4e80601c4ccdec0a2a9bd0e9e9529fc0352fa8568d72bf67d333b2fe |
|
MD5 | 3fae26c67710c48fa4c29db5a492a161 |
|
BLAKE2b-256 | dd15c183822829c3da897ed41302e9816b3ac6b6a383d80f8573cb340260b4e8 |