Usage

Licensing

To use pluralsight in a project

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from pluralsight.licensing import LicensingAPIClient

client = LicensingAPIClient(plan, api_key)

# invites
invites = client.invites.get_all_invites()

# users
users = client.users.get_all_users()

# teams
teams = client.teams.get_all_teams()

Invites

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# This script will find an invitation for a user and show you the invite link

from pluralsight.licensing import LicensingAPIClient
import sys

invite_email = sys.argv[1]
plan = sys.argv[2]
api_key = sys.argv[3]

client = LicensingAPIClient(plan, api_key)

invites = client.invites.get_invites(email=invite_email)

print("Found {0} invites".format(len(invites)))

for invite in invites:
    print("Link - " + invite.generate_url(plan))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# This script will get all the outstanding invitations and send them an email
# via your Exchange Web Access API.
# pip install exchangelib
# Tested on Python 3.5

from pluralsight.licensing import LicensingAPIClient

from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox
from exchangelib.folders import HTMLBody

plan = 'your-plan-name'
api_key = 'your-license-api-key'
email = 'youremail.com'
me = "Your name <{0}>".format(email)

EXCHANGE_PASSWORD = 'password 123'

# Username in WINDOMAIN\username format. Office365 wants usernames in PrimarySMTPAddress
# ('myusername@example.com') format. UPN format is also supported.
#
# By default, fault-tolerant error handling is used. This means that calls may block for a long time
# if the server is unavailable. If you need immediate failures, add 'is_service_account=False' to
# Credentials.
credentials = Credentials(username=email, password=EXCHANGE_PASSWORD)

account = Account(primary_smtp_address=email, credentials=credentials,
                  autodiscover=True)

def generate_email(invite):
    # Create message container - the correct MIME type is multipart/alternative.
    subject = "Please register for your DevOps, Developer and Automation training portal access"

    # Customize this to your own message. 
    html = """\
    <html>
      <body>
        <p>Hi,<br><br>
           Happy New Year. You should have received emails from me regarding access to pluralsight.com, invitations are limited
           to a small group of individuals, of which you are one. Invitations will expire/be reallocated for any users that
           have not accepted their invitations by the deadline. <br><br>
           This is your unique registration link - <a href="{0}">{0}</a>.
           <br><br>
           Please register this week, <u>do not forward this email</u>. Registration links are unique.<br><br>
           Regards,<br>
           
        </p>
      </body>
    </html>
    """.format(invite.generate_url(plan))

    return Message(
        account=account,
        folder=account.sent,
        subject=subject,
        body=HTMLBody(html),
        to_recipients=[Mailbox(email_address=invite.email)]
    )

client = LicensingAPIClient(plan, api_key)

invites = client.invites.get_all_invites()

print("Fetched {0} invites".format(len(invites)))

for invite in invites:
    msg = generate_email(invite)

    try:
        msg.send_and_save()
        print("Sent invite reminder to {0}".format(invite.email))
    except error:
        print(error)
        print("Failed to send invite reminder to {0}".format(invite.email))