Skip to content

Latest commit

 

History

History
177 lines (120 loc) · 3.63 KB

File metadata and controls

177 lines (120 loc) · 3.63 KB

lcs_client

This is intended to be a server-side client to help with HackRU services that piggyback on lcs login and user data

set_root_url

set_root_url(url: str) -> None

Sets root url. defaults to https://api.hackru.org

set_testing

set_testing(testing: bool) -> None

Whether or not to use test endpoint, defaults to False

User Objects

class User()

A user object to easily call other endpoints on behalf of a user

__init__

 | __init__(email: str = None, password: str = None, token: str = None) -> None

Constructor logs the user and gets a handle. Requires you to pass a token OR an email and password

profile

 | profile() -> Dict

Call lcs to get the user's profile

create_dm_link_to

 | create_dm_link_to(other_user_email: str)

Get a link to a slack DM between this User and another user identified by other_user_email

ResponseError Objects

class ResponseError(Exception)

Error with an attached HTTP Response

InternalServerError Objects

class InternalServerError(ResponseError)

An error occurred which prevented LCS from servicing the request

RequestError Objects

class RequestError(ResponseError)

Ideally you shouldn't receive this. There was an issue with the input to the API

CredentialError Objects

class CredentialError(RequestError)

There was an issue login in with that credential, or a token is invalid

on_login

on_login(fn: Callable)

Decorator. Call the decorated function whenever we find a new user Use case: get their profile and update local db. Function should take in the user object as the first param

@lcs_client.on_login
def your_func(user_profile):
    # updating the user profile or something

login

login(email: str, password: str) -> str

Gets an authentication token by calling the authorize LCS endpoint

validate_token

validate_token(token: str) -> Dict

Validates a lcs token

get_profile

get_profile(auth_token: str, user_email: str = None) -> Dict

Gets the profile of a user associated with user_email. The permissions associated with the auth_token user are used. If no user_email is specified or the user doesn't have enough privilege to view someone else's profile, the profile associated with the auth_token is fetched

create_dm_link_between

create_dm_link_between(token: str, other_user_email: str) -> str

Get a dm link to talk with another user on slack

get_base_url

get_base_url() -> str

Get the LCS base url

get

get(endpoint: str, *args, **kwargs) -> requests.models.Response

Performs a GET request to a LCS endpoint

post

post(endpoint: str, *args, **kwargs) -> requests.models.Response

Performs a POST request to a LCS endpoint