|
| 1 | +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved |
| 2 | + |
| 3 | +import logging |
| 4 | +import os |
| 5 | + |
| 6 | +import lightspark |
| 7 | + |
| 8 | +logger = logging.getLogger("uma_invites") |
| 9 | +logger.setLevel(logging.DEBUG) |
| 10 | + |
| 11 | +################################################################# |
| 12 | +## MODIFY THOSE VARIABLES BEFORE RUNNING THE EXAMPLE |
| 13 | +################################################################# |
| 14 | +## |
| 15 | +## We defined those variables as environment variables, but if you are just |
| 16 | +## running the example locally, feel free to just set the values in Python. |
| 17 | +## |
| 18 | + |
| 19 | +api_token_id = os.environ.get("LIGHTSPARK_API_TOKEN_CLIENT_ID") |
| 20 | +api_token_secret = os.environ.get("LIGHTSPARK_API_TOKEN_CLIENT_SECRET") |
| 21 | +base_url = os.environ.get("LIGHTSPARK_EXAMPLE_BASE_URL") |
| 22 | + |
| 23 | +# Let's start by creating a client |
| 24 | + |
| 25 | +assert api_token_secret |
| 26 | +assert api_token_id |
| 27 | + |
| 28 | +client = lightspark.LightsparkSyncClient( |
| 29 | + api_token_client_id=api_token_id, |
| 30 | + api_token_client_secret=api_token_secret, |
| 31 | + base_url=base_url, |
| 32 | +) |
| 33 | + |
| 34 | +# Create an invitation |
| 35 | +invitation = client.create_uma_invitation_with_incentives( |
| 36 | + inviter_uma="$alice@testvasp1.com", |
| 37 | + inviter_phone_number_e164="+11234567890", |
| 38 | + inviter_region=lightspark.RegionCode.US, |
| 39 | +) |
| 40 | + |
| 41 | +print( |
| 42 | + f"Created an invitation with code={invitation.code}, url={invitation.url}, and incentives status={invitation.incentives_status.name}" |
| 43 | +) |
| 44 | + |
| 45 | + |
| 46 | +# Claim an invitation |
| 47 | + |
| 48 | +client.claim_uma_invitation_with_incentives( |
| 49 | + invitation_code=invitation.code, |
| 50 | + invitee_uma="$bob@testvasp2.com", |
| 51 | + invitee_phone_number_e164="+520987654321", |
| 52 | + invitee_region=lightspark.RegionCode.MX, |
| 53 | +) |
| 54 | + |
| 55 | +print("Claimed invitation!") |
| 56 | + |
| 57 | + |
| 58 | +# Claiming an invitation again! |
| 59 | + |
| 60 | +try: |
| 61 | + print("Claiming the same invitation again...") |
| 62 | + client.claim_uma_invitation_with_incentives( |
| 63 | + invitation_code=invitation.code, |
| 64 | + invitee_uma="$bob@testvasp2.com", |
| 65 | + invitee_phone_number_e164="+520987654321", |
| 66 | + invitee_region=lightspark.RegionCode.MX, |
| 67 | + ) |
| 68 | + failed = False |
| 69 | +except: |
| 70 | + failed = True |
| 71 | + |
| 72 | +assert failed, "Claiming an invitation twice should fail." |
| 73 | +print("Claiming an invitation twice failed, as expected!") |
0 commit comments