Skip to content

Commit

Permalink
Refactor and format with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Lee authored and Joel Lee committed Jan 31, 2021
1 parent bd5d03b commit 2fc2747
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion supabase_py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .src import *
from .client import Client
from .client import Client
60 changes: 33 additions & 27 deletions supabase_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
from .src.SupabaseQueryBuilder import SupabaseQueryBuilder


DEFAULT_OPTIONS = {
"schema": "public",
"auto_refresh_token": True,
"persist_session": True,
"detect_session_in_url": True,
"headers": {},
}


class Client:
def __init__(self, supabaseUrl: str, supabaseKey: str):
if not supabaseUrl or not supabaseKey:
raise("supabaseUrl is required")
DEFAULT_HEADERS = {}

SETTINGS = {
"schema": "public",
"autoRefreshToken": True,
"persistSession": True,
"detectSessionInUrl": True,
# TODO: Verify if the localStorage parameter is relevant in the python implementation
"localStorage": None,
"headers": DEFAULT_HEADERS,
}
if not supabaseUrl:
raise Exception("supabaseUrl is required")
if not supabaseKey:
raise Exception("supabaseKey is required")

settings = {**DEFAULT_OPTIONS, **options}
self.restUrl = f"{supabaseUrl}/rest/v1"
self.realtimeUrl = f"{supabaseUrl}/realtime/v1".replace('http', 'ws')
self.realtimeUrl = f"{supabaseUrl}/realtime/v1".replace("http", "ws")
self.authUrl = f"{supabaseUrl}/auth/v1"
# TODO: Allow user to pass in schema. This is hardcoded
self.schema = SETTINGS["schema"]
self.supabaseUrl = supabaseUrl
self.supabaseKey = supabaseKey
Expand All @@ -43,10 +44,9 @@ def rpc(self, fn, params):
rest = self._initPostgrestClient()
return rest.rpc(fn, params)


def removeSubscription(self):
pass

def _closeSubscription(self, subscription):
pass

Expand All @@ -56,21 +56,27 @@ def getSubscriptions(self):
def _initRealtimeClient(self):
pass

def _initSupabaseAuthClient(self, autoRefreshToken, persistSession,
detectSessionInUrl,localStorage):
return SupabaseAuthClient(self.authUrl, autoRefreshToken, persistSession, detectSessionInUrl, localStorage)

def _initSupabaseAuthClient(
self, autoRefreshToken, persistSession, detectSessionInUrl, localStorage
):
return SupabaseAuthClient(
self.authUrl,
autoRefreshToken,
persistSession,
detectSessionInUrl,
localStorage,
)

def _initPostgrestClient(self):
return PostgrestClient(self.restUrl)
def _getAuthHeaders(self):

def _getAuthHeaders(self):
headers = {}
# What's the corresponding method to get the token
# authBearer = self.auth.session().token if self.auth.session().token else self.supabaseKey
headers['apiKey'] = self.supabaseKey
headers['Authorization'] = f"Bearer {self.supabaseKey}"
headers["apiKey"] = self.supabaseKey
headers["Authorization"] = f"Bearer {self.supabaseKey}"
return headers

def _closeChannel(self):
pass

14 changes: 12 additions & 2 deletions supabase_py/src/SupabaseAuthClient.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import gotrue


class SupabaseAuthClient(gotrue.Client):
def __init__(self,authURL, headers=None, detectSessionInUrl=False, autoRefreshToken=False, persistSession=False, localStorage=None):
def __init__(
self,
authURL,
headers=None,
detectSessionInUrl=False,
autoRefreshToken=False,
persistSession=False,
localStorage=None,
):
super().__init__(authURL)
self.headers = headers
self.detectSessionInUrl = detectSessionInUrl
self.autoRefreshToken = autoRefreshToken
self.persistSession = persistSession
self.localStorage = localStorage
self.localStorage = localStorage
11 changes: 7 additions & 4 deletions supabase_py/src/SupabaseQueryBuilder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from postgrest_py import PostgrestClient
class SupabaseQueryBuilder:
def __init__(self):
from postgrest_py.request_builder import RequestBuilder


class SupabaseQueryBuilder(RequestBuilder):
def __init__(self, session: AsyncClient, path: str):
super().__init__(session, path)
pass

def on(self):
pass
pass
4 changes: 2 additions & 2 deletions supabase_py/src/SupabaseRealtimeClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def __init__(self):

def on(self):
pass

def subscribe(self):
pass
pass

0 comments on commit 2fc2747

Please sign in to comment.