Giter VIP home page Giter VIP logo

openlrw-python-api-client's Introduction

OpenLRW Python API Client

A Python Client making your scripts for OpenLRW easier

code style pep 8 PyPI version

BETA VERSION

Getting Started

pip install openlrw

Usage

Import the library

Add this import before using the next examples

from openlrw.client import OpenLRW
from openlrw.exceptions import *

Setup the client

openlrw = OpenLRW(uri, username, password) # Create an instance of the client
openlrw.setup_email('localhost', '[email protected]', '[email protected]')  # Optional: Allows you to send emails

Create JSON Web Token

jwt = openlrw.generate_jwt()

Use OneRoster Routes

There are two ways to call OneRoster routes: by using a generic call or use implemented methods

Generic methods

# GET
try: 
  classes = openlrw.http_auth_get('/api/classes', jwt)
except ExpiredTokenException:
  print("Error: JWT Expired)
  
# POST
try: 
  openlrw.http_auth_post('/api/classes', data, jwt)
except ExpiredTokenException:
  print("Error: JWT Expired)
except BadRequestException as e:
  print("Error: " + str(e.message.content))
except InternalServerErrorException as e:
  print("Error: " + str(e.message.content))
  
 

Users

Get a user

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")

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")

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")

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")

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!")     
   
  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.