@@ -81,7 +81,7 @@ impl Client {
8181        Ok ( json_indexes) 
8282    } 
8383
84-     /// Get an [index](../indexes/struct.Index.html). 
84+     /// Get an [index](../indexes/struct.Index.html), this index should already exist . 
8585/// 
8686/// # Example 
8787/// 
@@ -104,7 +104,7 @@ impl Client {
104104        } 
105105    } 
106106
107-     /// Get a raw JSON [index](../indexes/struct.Index.html). 
107+     /// Get a raw JSON [index](../indexes/struct.Index.html), this index should already exist . 
108108/// 
109109/// # Example 
110110/// 
@@ -120,17 +120,13 @@ impl Client {
120120/// let movies = client.get_raw_index("movies").await.unwrap(); 
121121/// # }); 
122122/// ``` 
123+ /// If you use it directly from an index, you can use the method [fetch_info](#method.fetch_info), which is the equivalent method from an index. 
123124pub  async  fn  get_raw_index ( & self ,  uid :  impl  AsRef < str > )  -> Result < JsonIndex ,  Error >  { 
124-         Ok ( request :: < ( ) ,  JsonIndex > ( 
125-             & format ! ( "{}/indexes/{}" ,  self . host,  uid. as_ref( ) ) , 
126-             & self . api_key , 
127-             Method :: Get , 
128-             200 , 
129-         ) . await ?) 
125+         Index :: fetch_info ( & self . index ( uid. as_ref ( ) ) ) . await 
130126    } 
131127
132-     /// Assume that  an [index](../indexes/struct.Index.html) exist and create a corresponding object without any check . 
133- pub  fn  assume_index ( & self ,  uid :  impl  Into < String > )  -> Index  { 
128+     /// Create a corresponding object of  an [index](../indexes/struct.Index.html) without any check or doing an HTTP call . 
129+ pub  fn  index ( & self ,  uid :  impl  Into < String > )  -> Index  { 
134130        Index  { 
135131            uid :  Rc :: new ( uid. into ( ) ) , 
136132            host :  Rc :: clone ( & self . host ) , 
@@ -383,7 +379,18 @@ mod tests {
383379    #[ async_test]  
384380    async  fn  test_get_keys ( )  { 
385381        let  client = Client :: new ( "http://localhost:7700" ,  "masterKey" ) ; 
386-         client. get_keys ( ) . await . unwrap ( ) ; 
382+         let  keys = client. get_keys ( ) . await . unwrap ( ) ; 
383+         assert ! ( keys. private. is_some( ) ) ; 
384+         assert ! ( keys. public. is_some( ) ) ; 
385+     } 
386+ 
387+     #[ async_test]  
388+     async  fn  test_get_index ( )  { 
389+         let  client = Client :: new ( "http://localhost:7700" ,  "masterKey" ) ; 
390+         let  index_name = "get_index" ; 
391+         client. create_index ( index_name,  None ) . await . unwrap ( ) ; 
392+         let  index = client. get_index ( index_name) . await . unwrap ( ) ; 
393+         assert_eq ! ( index. uid. to_string( ) ,  index_name) ; 
387394    } 
388395
389396    #[ async_test]  
@@ -431,4 +438,33 @@ mod tests {
431438        let  deleted = client. delete_index_if_exists ( "bad" ) . await . unwrap ( ) ; 
432439        assert_eq ! ( deleted,  false ) ; 
433440    } 
441+ 
442+     #[ async_test]  
443+     async  fn  test_fetch_info ( )  { 
444+         let  client = Client :: new ( "http://localhost:7700" ,  "masterKey" ) ; 
445+         let  index_name = "fetch_info" ; 
446+         client. create_index ( index_name,  None ) . await . unwrap ( ) ; 
447+         let  index = client. index ( index_name) . fetch_info ( ) . await ; 
448+         assert ! ( index. is_ok( ) ) ; 
449+     } 
450+ 
451+     #[ async_test]  
452+     async  fn  test_get_primary_key_is_none ( )  { 
453+         let  client = Client :: new ( "http://localhost:7700" ,  "masterKey" ) ; 
454+         let  index_name = "get_primary_key_is_none" ; 
455+         client. create_index ( index_name,  None ) . await . unwrap ( ) ; 
456+         let  primary_key = client. index ( index_name) . get_primary_key ( ) . await ; 
457+         assert ! ( primary_key. is_ok( ) ) ; 
458+         assert ! ( primary_key. unwrap( ) . is_none( ) ) ; 
459+     } 
460+ 
461+     #[ async_test]  
462+     async  fn  test_get_primary_key ( )  { 
463+         let  client = Client :: new ( "http://localhost:7700" ,  "masterKey" ) ; 
464+         let  index_name = "get_primary_key" ; 
465+         client. create_index ( index_name,  Some ( "primary_key" ) ) . await . unwrap ( ) ; 
466+         let  primary_key = client. index ( index_name) . get_primary_key ( ) . await ; 
467+         assert ! ( primary_key. is_ok( ) ) ; 
468+         assert_eq ! ( primary_key. unwrap( ) . unwrap( ) ,  "primary_key" ) ; 
469+     } 
434470} 
0 commit comments