Usage¶
Licensing¶
To use pluralsight in a project
1from pluralsight.licensing import LicensingAPIClient
2
3client = LicensingAPIClient(plan, api_key)
4
5# invites
6invites = client.invites.get_all_invites()
7
8# users
9users = client.users.get_all_users()
10
11# teams
12teams = client.teams.get_all_teams()
Invites¶
1# This script will find an invitation for a user and show you the invite link
2
3from pluralsight.licensing import LicensingAPIClient
4import sys
5
6invite_email = sys.argv[1]
7plan = sys.argv[2]
8api_key = sys.argv[3]
9
10client = LicensingAPIClient(plan, api_key)
11
12invites = client.invites.get_invites(email=invite_email)
13
14print("Found {0} invites".format(len(invites)))
15
16for invite in invites:
17 print("Link - " + invite.generate_url(plan))
1# This script will get all the outstanding invitations and send them an email
2# via your Exchange Web Access API.
3# pip install exchangelib
4# Tested on Python 3.5
5
6from pluralsight.licensing import LicensingAPIClient
7
8from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox
9from exchangelib.folders import HTMLBody
10
11plan = 'your-plan-name'
12api_key = 'your-license-api-key'
13email = 'youremail.com'
14me = "Your name <{0}>".format(email)
15
16EXCHANGE_PASSWORD = 'password 123'
17
18# Username in WINDOMAIN\username format. Office365 wants usernames in PrimarySMTPAddress
19# ('myusername@example.com') format. UPN format is also supported.
20#
21# By default, fault-tolerant error handling is used. This means that calls may block for a long time
22# if the server is unavailable. If you need immediate failures, add 'is_service_account=False' to
23# Credentials.
24credentials = Credentials(username=email, password=EXCHANGE_PASSWORD)
25
26account = Account(primary_smtp_address=email, credentials=credentials,
27 autodiscover=True)
28
29def generate_email(invite):
30 # Create message container - the correct MIME type is multipart/alternative.
31 subject = "Please register for your DevOps, Developer and Automation training portal access"
32
33 # Customize this to your own message.
34 html = """\
35 <html>
36 <body>
37 <p>Hi,<br><br>
38 Happy New Year. You should have received emails from me regarding access to pluralsight.com, invitations are limited
39 to a small group of individuals, of which you are one. Invitations will expire/be reallocated for any users that
40 have not accepted their invitations by the deadline. <br><br>
41 This is your unique registration link - <a href="{0}">{0}</a>.
42 <br><br>
43 Please register this week, <u>do not forward this email</u>. Registration links are unique.<br><br>
44 Regards,<br>
45
46 </p>
47 </body>
48 </html>
49 """.format(invite.generate_url(plan))
50
51 return Message(
52 account=account,
53 folder=account.sent,
54 subject=subject,
55 body=HTMLBody(html),
56 to_recipients=[Mailbox(email_address=invite.email)]
57 )
58
59client = LicensingAPIClient(plan, api_key)
60
61invites = client.invites.get_all_invites()
62
63print("Fetched {0} invites".format(len(invites)))
64
65for invite in invites:
66 msg = generate_email(invite)
67
68 try:
69 msg.send_and_save()
70 print("Sent invite reminder to {0}".format(invite.email))
71 except error:
72 print(error)
73 print("Failed to send invite reminder to {0}".format(invite.email))