Skip to content

Commit 89ad477

Browse files
committed
feat: add LTI tools for LTI APIS in edX
1 parent 56ab615 commit 89ad477

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

edx_api/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .grades import UserCurrentGrades
1616
from .user_info import UserInfo
1717
from .user_validation import UserValidation
18+
from .lti_tools import LTITools
1819

1920

2021
class EdxApi:
@@ -123,3 +124,9 @@ def user_validation(self):
123124
def course_runs(self):
124125
"""Course runs management API (Works with CMS)"""
125126
return CourseRuns(self.get_requester(token_type="jwt"), self.base_url)
127+
128+
@property
129+
def lti_tools(self):
130+
"""LTI Tools API"""
131+
return LTITools(self.get_requester(), self.base_url)
132+

edx_api/lti_tools/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Client for user_validation API"""
2+
from urllib.parse import urljoin
3+
4+
5+
class LTITools:
6+
"""
7+
Open edX user validation client
8+
"""
9+
10+
def __init__(self, requester, base_url):
11+
"""
12+
Args:
13+
requester (Requester): an authenticated objects for requests to edX
14+
base_url (str): string representing the base URL of an edX LMS instance
15+
"""
16+
self.requester = requester
17+
self.base_url = base_url
18+
19+
20+
def fix_lti_user(self, username, email):
21+
"""
22+
Fixes an LTI user with duplicate email
23+
24+
Args:
25+
username (str): Username of the Application user
26+
email (str): Email of the Application user
27+
28+
Returns:
29+
bool: True if the user was fixed successfully, False otherwise
30+
"""
31+
request_data = dict(username=username, email=email)
32+
33+
# the request is done on behalf of the current logged in user
34+
return self.requester.post(
35+
urljoin(
36+
self.base_url,
37+
'/api/lti-user-fix/'
38+
),
39+
json=request_data)

0 commit comments

Comments
 (0)