@@ -20,6 +20,7 @@ public struct MeiliSearch {
2020 private let stats : Stats
2121 private let system : System
2222 private let dumps : Dumps
23+ private let tasks : Tasks
2324
2425 // MARK: Initializers
2526
@@ -41,6 +42,7 @@ public struct MeiliSearch {
4142 self . stats = Stats ( self . request)
4243 self . system = System ( self . request)
4344 self . dumps = Dumps ( self . request)
45+ self . tasks = Tasks ( self . request)
4446 }
4547
4648 // MARK: Index
@@ -65,28 +67,10 @@ public struct MeiliSearch {
6567 public func createIndex(
6668 uid: String ,
6769 primaryKey: String ? = nil ,
68- _ completion: @escaping ( Result < Indexes , Swift . Error > ) -> Void ) {
70+ _ completion: @escaping ( Result < Task , Swift . Error > ) -> Void ) {
6971 Indexes . create ( uid: uid, primaryKey: primaryKey, config: self . config, completion)
7072 }
7173
72- /**
73- Get or create an index.
74-
75- - parameter uid: The unique identifier for the `Index` to be created.
76- - parameter primaryKey: the unique field of a document.
77- - parameter completion: The completion closure used to notify when the server
78- completes the write request, it returns a `Result` object that contains `Index`
79- value. If the request was sucessful or `Error` if a failure occured.
80- */
81-
82- // DONE
83- public func getOrCreateIndex(
84- uid: String ,
85- primaryKey: String ? = nil ,
86- _ completion: @escaping ( Result < Indexes , Swift . Error > ) -> Void ) {
87- Indexes . getOrCreate ( uid: uid, primaryKey: primaryKey, config: self . config, completion)
88- }
89-
9074 /**
9175 Get an index.
9276
@@ -97,7 +81,7 @@ public struct MeiliSearch {
9781 */
9882 public func getIndex(
9983 _ uid: String ,
100- _ completion: @escaping ( Result < Indexes , Swift . Error > ) -> Void ) {
84+ _ completion: @escaping ( Result < Index , Swift . Error > ) -> Void ) {
10185 self . index ( uid) . get ( completion)
10286 }
10387
@@ -109,7 +93,7 @@ public struct MeiliSearch {
10993 value. If the request was sucessful or `Error` if a failure occured.
11094 */
11195 public func getIndexes(
112- _ completion: @escaping ( Result < [ Indexes ] , Swift . Error > ) -> Void ) {
96+ _ completion: @escaping ( Result < [ Index ] , Swift . Error > ) -> Void ) {
11397 Indexes . getAll ( config: self . config, completion)
11498 }
11599
@@ -125,7 +109,7 @@ public struct MeiliSearch {
125109 public func updateIndex(
126110 uid: String ,
127111 primaryKey: String ,
128- _ completion: @escaping ( Result < Indexes , Swift . Error > ) -> Void ) {
112+ _ completion: @escaping ( Result < Task , Swift . Error > ) -> Void ) {
129113 self . index ( uid) . update ( primaryKey: primaryKey, completion)
130114 }
131115
@@ -139,24 +123,151 @@ public struct MeiliSearch {
139123 */
140124 public func deleteIndex(
141125 _ uid: String ,
142- _ completion: @escaping ( Result < ( ) , Swift . Error > ) -> Void ) {
126+ _ completion: @escaping ( Result < Task , Swift . Error > ) -> Void ) {
143127 self . index ( uid) . delete ( completion)
144128 }
145129
130+ // MARK: WAIT FOR TASK
131+
132+ /**
133+ Wait for a task to be succesfull or failed.
134+
135+ Using a task returned by an asynchronous route of MeiliSearch, wait for completion.
136+
137+ - parameter: taskId: The id of the task.
138+ - parameter: options Optionnal configuration for timeout and interval
139+ - parameter: completion: The completion closure used to notify when the server
140+ **/
141+ public func waitForTask(
142+ taskUid: Int ,
143+ options: WaitOptions ? = nil ,
144+ _ completion: @escaping ( Result < Task , Swift . Error >
145+ ) -> Void ) {
146+ self . tasks. waitForTask ( taskUid: taskUid, options: options, completion)
147+ }
148+
149+ /**
150+ Wait for a task to be succeeded or failed.
151+
152+ Using a task returned by an asynchronous route of MeiliSearch, wait for completion.
153+
154+ - parameter task: The task.
155+ - parameter: options: Optionnal configuration for timeout and interval
156+ - parameter completion: The completion closure used to notify when the server
157+ **/
158+ public func waitForTask(
159+ task: Task ,
160+ options: WaitOptions ? = nil ,
161+ _ completion: @escaping ( Result < Task , Swift . Error >
162+ ) -> Void ) {
163+ self . tasks. waitForTask ( task: task, options: options, completion)
164+ }
165+
166+ // MARK: Tasks
167+
168+ /**
169+ Get the information of a task.
170+
171+ - parameter taskUid: The task identifier.
172+ - parameter completion: The completion closure used to notify when the server
173+ completes the query request, it returns a `Result` object that contains `Key` value.
174+ If the request was sucessful or `Error` if a failure occured.
175+ */
176+ public func getTask(
177+ taskUid: Int ,
178+ _ completion: @escaping ( Result < Task , Swift . Error > ) -> Void ) {
179+ self . tasks. get ( taskUid: taskUid, completion)
180+ }
181+
182+ /**
183+ Get all tasks.
184+
185+ - parameter completion: The completion closure used to notify when the server
186+ completes the query request, it returns a `Result` object that contains `Key` value.
187+ If the request was sucessful or `Error` if a failure occured.
188+ */
189+ public func getTasks(
190+ _ completion: @escaping ( Result < Results < Task > , Swift . Error > ) -> Void ) {
191+ self . tasks. getAll ( completion)
192+ }
193+
146194 // MARK: Keys
147195
148196 /**
149- Protected instances of Meilisearch require API keys to perform certain actions. Only the master key has
150- the right to access the list of all API keys.
197+ Get all keys.
198+
199+ - parameter completion: The completion closure used to notify when the server
200+ completes the query request, it returns a `Result` object that contains `Key` value.
201+ If the request was sucessful or `Error` if a failure occured.
202+ */
203+ public func getKeys(
204+ _ completion: @escaping ( Result < Results < Key > , Swift . Error > ) -> Void ) {
205+ self . keys. getAll ( completion)
206+ }
207+
208+ /**
209+ Get one key's information using the key value.
151210
152- - parameter masterKey : Master key to access the `keys` function .
211+ - parameter key : The key value .
153212 - parameter completion: The completion closure used to notify when the server
154213 completes the query request, it returns a `Result` object that contains `Key` value.
155214 If the request was sucessful or `Error` if a failure occured.
156215 */
157- public func keys(
216+ public func getKey(
217+ key: String ,
218+ _ completion: @escaping ( Result < Key , Swift . Error > ) -> Void ) {
219+ self . keys. get ( key: key, completion)
220+ }
221+
222+ /**
223+ Create an API key.
224+
225+ - parameter keyParams: Parameters object required to create a key.
226+ - parameter completion: The completion closure used to notify when the server
227+ completes the query request, it returns a `Result` object that contains `Key` value.
228+ If the request was sucessful or `Error` if a failure occured.
229+ */
230+ public func createKey(
231+ _ keyParams: KeyParams ,
158232 _ completion: @escaping ( Result < Key , Swift . Error > ) -> Void ) {
159- self . keys. get ( completion)
233+ self . keys. create ( keyParams, completion)
234+ }
235+
236+ /**
237+ Update an API key.
238+
239+ - parameter key: The key value.
240+ - parameter keyParams: Parameters object required to update a key.
241+ - parameter completion: The completion closure used to notify when the server
242+ completes the query request, it returns a `Result` object that contains `Key` value.
243+ If the request was sucessful or `Error` if a failure occured.
244+ */
245+ public func updateKey(
246+ key: String ,
247+ keyParams: KeyParams ,
248+ _ completion: @escaping ( Result < Key , Swift . Error > ) -> Void ) {
249+ self . keys. update (
250+ key: key,
251+ keyParams: keyParams,
252+ completion
253+ )
254+ }
255+
256+ /**
257+ Delete an API key.
258+
259+ - parameter key: The key value.
260+ - parameter completion: The completion closure used to notify when the server
261+ completes the query request, it returns a `Result` object that contains `Key` value.
262+ If the request was sucessful or `Error` if a failure occured.
263+ */
264+ public func deleteKey(
265+ key: String ,
266+ _ completion: @escaping ( Result < ( ) , Swift . Error > ) -> Void ) {
267+ self . keys. delete (
268+ key: key,
269+ completion
270+ )
160271 }
161272
162273 // MARK: Stats
0 commit comments