Exemplo n.º 1
0
class VideoLinkCreator:
    def __init__(self, learnfqdn, key, secret, course_id, video_url, title,
                 description):  # mbk added username pass for user auth.
        '''
        Constructor of uploader instance. 
        This goes through authorization step of the target server.
        '''
        self.learnfqdn = learnfqdn
        self.key = key
        self.secret = secret
        self.course_id = course_id  # represents the courseId could be "_2_7", or "uuid:<a_uuid>" or "courseId:mbk-ultra"
        self.video_url = video_url
        self.title = title
        self.description = description

        self.bb = BbRest(key, secret, f"https://{learnfqdn}")

        self.the_payload = {
            'title': f"{title}",
            'description': f"{description}",
            'body': "contentBody",
            'position': 0,
            'contentHandler': {
                'id': 'resource/x-bb-externallink',
                'url': f"{video_url}"
            },
            'availability': {
                'available': 'Yes',
            }
        }
        print("init: " + course_id + " " + self.course_id)
        # Instead of the following, tryint to switch to the above for OAuth calls to the Learn REST App.
        # Use requests module's Session object.
        # This is not mandatory, but this enables applying the same settings (especially
        # OAuth2 access token) to all calls and also makes the calls more efficient.
        # ref. https://2.python-requests.org/en/master/user/advanced/#session-objects
        # self.requests_session = requests.Session()
        # self.__setup_resource_owner_grant_access_token()

    def get_system_version(self):
        '''
        Test method that just makes REST call to /learn/api/public/v1/system/version
        '''
        self.bb.GetSystemVersion()

    def create_video_link(self):
        resp = self.bb.CreateChild(courseId=f'{self.course_id}',
                                   contentId='root',
                                   payload=self.the_payload)
Exemplo n.º 2
0
class LinkContentCreator:
    def __init__(self, learnfqdn, key, secret, course_id, link_url, title,
                 description):
        '''
        Constructor of uploader instance. 
        This goes through authorization step of the target server.
        '''
        self.learnfqdn = learnfqdn
        self.key = key
        self.secret = secret
        self.course_id = course_id  # represents the courseId could be "_2_7", or "uuid:<a_uuid>" or "courseId:mbk-ultra"
        self.link_url = link_url
        self.title = title
        self.description = description

        self.bb = BbRest(key, secret, f"https://{learnfqdn}")

        self.the_payload = {
            'title': f"{title}",
            'description': f"{description}",
            'body': "contentBody",
            'position': 0,
            'contentHandler': {
                'id': 'resource/x-bb-externallink',
                'url': f"{link_url}"
            },
            'availability': {
                'available': 'Yes',
            }
        }

    def get_system_version(self):
        '''
        Test method that just makes REST call to /learn/api/public/v1/system/version
        '''
        resp = self.bb.GetSystemVersion()
        return resp

    def create_content(self):  # Use the values given when instantiating this.
        resp = self.bb.CreateChild(courseId=f'{self.course_id}',
                                   contentId='root',
                                   payload=self.the_payload)
        return resp

    def create_content_containing_link(
            self, course, link_url, title,
            description):  #Python can't overload method signatures.
        new_payload = {
            'title': f"{title}",
            'description': f"{description}",
            'body': "contentBody",
            'position': 0,
            'contentHandler': {
                'id': 'resource/x-bb-externallink',
                'url': f"{link_url}"
            },
            'availability': {
                'available': 'Yes',
            }
        }
        resp = self.bb.CreateChild(courseId=f'{self.course_id}',
                                   contentId='root',
                                   payload=new_payload)
        print(resp.json())
        return resp