Skip to content

Commit

Permalink
:clown:
Browse files Browse the repository at this point in the history
  • Loading branch information
RustySnek committed Dec 6, 2024
1 parent e54c41a commit 5d1c229
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions priv/python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
encode_basic_type_strings,
)

<<<<<<< HEAD
ELIXIRUS_TEST = os.getenv("ELIXIRUS_TEST")
if ELIXIRUS_TEST and not (MOCK_API_URL := os.getenv("MOCK_API_URL")):
=======
if not (MOCK_API_URL := os.getenv("MOCK_API_URL")):
>>>>>>> b092fc2 (:clown:)
raise Exception("Couldn't find MOCK_API_URL env")


Expand Down Expand Up @@ -111,6 +115,7 @@ class ClientStruct(VenomousTrait, Client):
proxy: Dict[str, str] = field(default_factory=dict)
__struct__: Atom = Atom(b"Elixir.Elixirus.Types.Client")

<<<<<<< HEAD
if ELIXIRUS_TEST:

@staticmethod
Expand Down Expand Up @@ -150,6 +155,37 @@ def from_dict(dic, structs={}):
self = VenomousTrait.from_dict.__func__(ClientStruct, dic, structs)
Client.__init__(self, self.token, proxy=self.proxy)
return self
=======
@staticmethod
def from_dict(dic, structs={}):
global MOCK_API_URL
self = VenomousTrait.from_dict.__func__(ClientStruct, dic, structs)
Client.__init__(
self,
self.token,
proxy=self.proxy,
api_url=MOCK_API_URL + "/login",
base_url=MOCK_API_URL,
grades_url=MOCK_API_URL + "/grades.html",
timetable_url=MOCK_API_URL + "/timetable.html",
announcements_url=MOCK_API_URL + "/announcements.html",
message_url=MOCK_API_URL + "/messages.html",
send_message_url=MOCK_API_URL + "/send_message.html",
attendance_url=MOCK_API_URL + "/attendance.html",
attendance_details_url=MOCK_API_URL + "/attendance_detail.html",
schedule_url=MOCK_API_URL + "/schedule.html",
homework_url=MOCK_API_URL + "/homework.html",
homework_details_url=MOCK_API_URL + "/homework_detail.html",
info_url=MOCK_API_URL + "/student_info.html",
recipients_url=MOCK_API_URL + "/recipients.html",
recipient_groups_url=MOCK_API_URL + "/recipient_groups.html",
completed_lessons_url=MOCK_API_URL + "/completed.html",
gateway_api_attendance=MOCK_API_URL + "/api_attendance",
refresh_oauth_url=MOCK_API_URL + "/oauth",
index_url=MOCK_API_URL + "/notifications.html",
)
return self
>>>>>>> b092fc2 (:clown:)

def into_erl(self) -> Dict:
return {
Expand Down Expand Up @@ -198,6 +234,7 @@ class GpaStruct(VenomousTrait, Gpa):

if ELIXIRUS_TEST:

<<<<<<< HEAD
def get_client_from_credentials(
username: str, password: str, proxy: Dict[str, str]
) -> Tuple[Atom, Client | str]:
Expand Down Expand Up @@ -275,6 +312,65 @@ def get_client(token: str, proxy: Dict[str, str]) -> Client:

def get_client(token: str, proxy: Dict[str, str]) -> Client:
return new_client(token=Token(API_Key=token), proxy=proxy)
=======
def get_client_from_credentials(
username: str, password: str, proxy: Dict[str, str]
) -> Tuple[Atom, Client | str]:
global MOCK_API_URL
c = new_client(
proxy=proxy,
api_url=MOCK_API_URL + "/login",
base_url=MOCK_API_URL,
grades_url=MOCK_API_URL + "/grades.html",
timetable_url=MOCK_API_URL + "/timetable.html",
announcements_url=MOCK_API_URL + "/announcements.html",
message_url=MOCK_API_URL + "/messages.html",
send_message_url=MOCK_API_URL + "/send_message.html",
attendance_url=MOCK_API_URL + "/attendance.html",
attendance_details_url=MOCK_API_URL + "/attendance_detail.html",
schedule_url=MOCK_API_URL + "/schedule.html",
homework_url=MOCK_API_URL + "/homework.html",
homework_details_url=MOCK_API_URL + "/homework_detail.html",
info_url=MOCK_API_URL + "/student_info.html",
recipients_url=MOCK_API_URL + "/recipients.html",
recipient_groups_url=MOCK_API_URL + "/recipient_groups.html",
completed_lessons_url=MOCK_API_URL + "/completed.html",
gateway_api_attendance=MOCK_API_URL + "/api_attendance",
refresh_oauth_url=MOCK_API_URL + "/oauth",
index_url=MOCK_API_URL + "/notifications.html",
)
try:
c.get_token(username, password)
return Atom(b"ok"), c
except AuthorizationError as e:
return Atom(b"error"), str(e)


def get_client(token: str, proxy: Dict[str, str]) -> Client:
return new_client(
token=Token(API_Key=token),
proxy=proxy,
api_url=MOCK_API_URL + "/login",
base_url=MOCK_API_URL,
grades_url=MOCK_API_URL + "/grades.html",
timetable_url=MOCK_API_URL + "/timetable.html",
announcements_url=MOCK_API_URL + "/announcements.html",
message_url=MOCK_API_URL + "/messages.html",
send_message_url=MOCK_API_URL + "/send_message.html",
attendance_url=MOCK_API_URL + "/attendance.html",
attendance_details_url=MOCK_API_URL + "/attendance_detail.html",
schedule_url=MOCK_API_URL + "/schedule.html",
homework_url=MOCK_API_URL + "/homework.html",
homework_details_url=MOCK_API_URL + "/homework_detail.html",
info_url=MOCK_API_URL + "/student_info.html",
recipients_url=MOCK_API_URL + "/recipients.html",
recipient_groups_url=MOCK_API_URL + "/recipient_groups.html",
completed_lessons_url=MOCK_API_URL + "/completed.html",
gateway_api_attendance=MOCK_API_URL + "/api_attendance",
refresh_oauth_url=MOCK_API_URL + "/oauth",
index_url=MOCK_API_URL + "/notifications.html",
)
>>>>>>> b092fc2 (:clown:)


def encoder(value: Any) -> Any:
Expand Down

0 comments on commit 5d1c229

Please sign in to comment.