badgr_lite package¶
Submodules¶
badgr_lite.cli module¶
Console script for badgr_lite.
badgr_lite.exceptions module¶
BadgrLite Custom Exceptions
-
exception
badgr_lite.exceptions.
AwardBadgeBadDataError
[source]¶ Bases:
BaseException
Award Badge given bad data
-
exception
badgr_lite.exceptions.
BadBadgeIdError
[source]¶ Bases:
BaseException
Award Badge given bad badge_id
Please consider the badge ID that you are trying to award is correct.
-
exception
badgr_lite.exceptions.
RequiredAttributesMissingError
[source]¶ Bases:
BaseException
Required Badge Attributes Missing
-
exception
badgr_lite.exceptions.
TokenAndRefreshExpiredError
[source]¶ Bases:
BaseException
Token and refresh expired
The token has expired. We tried refreshing the token from the refresh token and are still not able to get authorization to work correctly.
Use prime_initial_token (see Installation instructions) to reconfigure tokens.
-
exception
badgr_lite.exceptions.
TokenFileNotFoundError
[source]¶ Bases:
BaseException
Token file not found
The token_filename argument that you passed into BadgrLite is not found. Please consider:
- Using using prime_initial_token (see Installation instructions)
- Checking the filename is correct
- Ensuring the filename exists and is in JSON format
badgr_lite.helpers module¶
BadgrLite Helper functions
-
badgr_lite.helpers.
pythonic
(name: str) → str[source]¶ Convert camelCase identifier to pythonic identifier
- Citaton: (https://stackoverflow.com/questions/1175208/
- elegant-python-function-to-convert-camelcase- to-snake-case/17328907)
The Badgr API returns attributes in camel case (e.g., issuerOpenBadgeId). We wish to also see those attributes in a pythonic way (e.g., issuer_open_badgee_id).
badgr_lite.models module¶
BadgrLite module for automating Badr awards (assertions)
-
class
badgr_lite.models.
Badge
(attrs: dict)[source]¶ Bases:
object
Pythonic representation of API BadgeClass
Given a dictionary when instantiating the object, create a Pythonic representation of a OpenBadge.
The JSON object given by the Badgr API, loaded as a dict, can be used to instantiate the Badge class.
-
REQUIRED_ATTRS
= ['entity_id', 'expires', 'entity_type', 'extensions', 'open_badge_id', 'created_by', 'issuer', 'image', 'issuer_open_badge_id', 'created_at']¶
-
REQUIRED_JSON
= ['entityId', 'expires', 'entityType', 'extensions', 'openBadgeId', 'createdBy', 'issuer', 'image', 'issuerOpenBadgeId', 'createdAt']¶
-
-
class
badgr_lite.models.
BadgrLite
(token_filename: str)[source]¶ Bases:
object
Automate using Badgr API without the overhead of badgr-server
-
award_badge
(badge_id: str, badge_data: dict) → badgr_lite.models.Badge[source]¶ Given a previously created badge_id and badge_data, award badge
Example:
>>> badgr = BadgrLite(token_filename='./token.json') >>> badge_data = { ... "name": "Sample badge", ... "recipient": { ... "identity": "joe@example.com" ... }, ... "notify": True, ... "evidence": [{ ... "url": "http://example.com/", ... "narrative": "Glen completed all the prereqs for..." ... }] ... } >>> >>> badge_id = '2TfNNqMLT8CoAhfGKqSv6Q' >>> result = badgr.award_badge(badge_id, badge_data) >>> print(result) qv4DMvnYT0Gwz7wquRasvg: <No name>
-
badges
¶ Get list of badges from Server
Example:
>>> badgr = BadgrLite(token_filename='./token.json') >>> for badge in badgr.badges: ... print(badge) ... cTjxL52HQBiSgIp5JuVq5w: Bay Area Python Interest Group TDD Participant 5YhFytMUQb2loOMEy63gQA: Bay Area Python Interest Group TDD Quiz Champion yzExTDvOTnOx_R3YhwPf3A: Test Driven Development Fundamentals Champion yNjcY70FSn603SO9vMGhBA: Install Python with Virtual Environments
-
Module contents¶
Top-level package for badgr-lite.