Skip to content

Commit 22692f1

Browse files
committed
Use common api call object for all resources.
Ensures that meta information about node failures are shared across different resource calls.
1 parent d439c3f commit 22692f1

File tree

10 files changed

+36
-46
lines changed

10 files changed

+36
-46
lines changed

typesense/alias.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
from .documents import Documents
2-
from .api_call import ApiCall
3-
4-
51
class Alias(object):
6-
def __init__(self, config, name):
2+
def __init__(self, config, api_call, name):
73
self.config = config
4+
self.api_call = api_call
85
self.name = name
9-
self.api_call = ApiCall(config)
106

117
def _endpoint_path(self):
128
from .aliases import Aliases

typesense/aliases.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from typesense.alias import Alias
2-
from .api_call import ApiCall
32

43

54
class Aliases(object):
65
RESOURCE_PATH = '/aliases'
76

8-
def __init__(self, config):
7+
def __init__(self, config, api_call):
98
self.config = config
10-
self.api_call = ApiCall(config)
9+
self.api_call = api_call
1110
self.aliases = {}
1211

1312
def __getitem__(self, name):
1413
if name not in self.aliases:
15-
self.aliases[name] = Alias(self.config, name)
14+
self.aliases[name] = Alias(self.config, self.api_call, name)
1615

1716
return self.aliases.get(name)
1817

typesense/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from .aliases import Aliases
2+
from .debug import Debug
23
from .collections import Collections
34
from .configuration import Configuration
5+
from .api_call import ApiCall
46

57

68
class Client(object):
79
def __init__(self, config_dict):
810
self.config = Configuration(config_dict)
9-
self.collections = Collections(self.config)
10-
self.aliases = Aliases(self.config)
11+
self.api_call = ApiCall(self.config)
12+
self.collections = Collections(self.config, self.api_call)
13+
self.aliases = Aliases(self.config, self.api_call)
14+
self.debug = Debug(self.config, self.api_call)

typesense/collection.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from .overrides import Overrides
22
from .documents import Documents
3-
from .api_call import ApiCall
43

54

65
class Collection(object):
7-
def __init__(self, config, name):
6+
def __init__(self, config, api_call, name):
87
self.config = config
98
self.name = name
10-
self.api_call = ApiCall(config)
11-
self.documents = Documents(config, name)
12-
self.overrides = Overrides(config, name)
9+
self.api_call = api_call
10+
self.documents = Documents(config, api_call, name)
11+
self.overrides = Overrides(config, api_call, name)
1312

1413
def _endpoint_path(self):
1514
from .collections import Collections

typesense/collections.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
from .api_call import ApiCall
21
from .collection import Collection
32

43

54
class Collections(object):
65
RESOURCE_PATH = '/collections'
76

8-
def __init__(self, config):
7+
def __init__(self, config, api_call):
98
self.config = config
10-
self.api_call = ApiCall(config)
9+
self.api_call = api_call
1110
self.collections = {}
1211

1312
def __getitem__(self, collection_name):
1413
if collection_name not in self.collections:
15-
self.collections[collection_name] = Collection(self.config, collection_name)
14+
self.collections[collection_name] = Collection(self.config, self.api_call, collection_name)
1615

1716
return self.collections.get(collection_name)
1817

typesense/debug.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from .api_call import ApiCall
2-
3-
41
class Debug(object):
5-
ENDPOINT_PATH = '/debug'
2+
RESOURCE_PATH = '/debug'
3+
4+
def __init__(self, config, api_call):
5+
self.config = config
6+
self.api_call = api_call
7+
self.collections = {}
68

7-
@staticmethod
8-
def retrieve():
9-
ApiCall.get(Debug.ENDPOINT_PATH, {})
9+
def retrieve(self):
10+
return self.api_call.get('{0}'.format(Debug.RESOURCE_PATH))

typesense/document.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from .api_call import ApiCall
2-
3-
41
class Document(object):
5-
def __init__(self, config, collection_name, document_id):
2+
def __init__(self, config, api_call, collection_name, document_id):
63
self.config = config
4+
self.api_call = api_call
75
self.collection_name = collection_name
86
self.document_id = document_id
9-
self.api_call = ApiCall(config)
107

118
def _endpoint_path(self):
129
from .documents import Documents

typesense/documents.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import json
22

33
from .document import Document
4-
from .api_call import ApiCall
54

65

76
class Documents(object):
87
RESOURCE_PATH = 'documents'
98

10-
def __init__(self, config, collection_name):
9+
def __init__(self, config, api_call, collection_name):
1110
self.config = config
11+
self.api_call = api_call
1212
self.collection_name = collection_name
13-
self.api_call = ApiCall(config)
1413
self.documents = {}
1514

1615
def __getitem__(self, document_id):
1716
if document_id not in self.documents:
18-
self.documents[document_id] = Document(self.config, self.collection_name, document_id)
17+
self.documents[document_id] = Document(self.config, self.api_call, self.collection_name, document_id)
1918

2019
return self.documents[document_id]
2120

typesense/override.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from .api_call import ApiCall
2-
3-
41
class Override(object):
5-
def __init__(self, config, collection_name, override_id):
2+
def __init__(self, config, api_call, collection_name, override_id):
63
self.config = config
4+
self.api_call = api_call
75
self.collection_name = collection_name
86
self.override_id = override_id
9-
self.api_call = ApiCall(config)
107

118
def _endpoint_path(self):
129
from .overrides import Overrides

typesense/overrides.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
from .override import Override
2-
from .api_call import ApiCall
32

43

54
class Overrides(object):
65
RESOURCE_PATH = 'overrides'
76

8-
def __init__(self, config, collection_name):
7+
def __init__(self, config, api_call, collection_name):
98
self.config = config
10-
self.api_call = ApiCall(config)
9+
self.api_call = api_call
1110
self.collection_name = collection_name
1211
self.overrides = {}
1312

1413
def __getitem__(self, override_id):
1514
if override_id not in self.overrides:
16-
self.overrides[override_id] = Override(self.config, self.collection_name, override_id)
15+
self.overrides[override_id] = Override(self.config, self.api_call, self.collection_name, override_id)
1716

1817
return self.overrides[override_id]
1918

0 commit comments

Comments
 (0)