Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit de2b848

Browse files
authored
feat(PlacesClient): GetByObjectID (#390)
1 parent 732029a commit de2b848

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/places/PlacesClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@ protected JSONObject search(@NonNull PlacesQuery params) throws AlgoliaException
127127
throw new RuntimeException(e); // should never happen
128128
}
129129
}
130+
131+
/**
132+
* Get a place by its objectID.
133+
* @param objectID the record's identifier.
134+
* @return the corresponding record.
135+
* @throws AlgoliaException when the given objectID does not exist.
136+
*/
137+
public JSONObject getByObjectID(@NonNull String objectID) throws AlgoliaException {
138+
return getRequest("/1/places/" + objectID, false);
139+
}
130140
}

algoliasearch/src/test/java/com/algolia/search/saas/places/PlacesClientTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
import org.mockito.internal.util.reflection.Whitebox;
3636
import org.robolectric.util.concurrent.RoboExecutorService;
3737

38+
import static org.junit.Assert.assertEquals;
3839
import static org.junit.Assert.assertNotNull;
3940
import static org.junit.Assert.assertTrue;
4041
import static org.junit.Assert.fail;
4142

4243
@SuppressLint("DefaultLocale")
4344
public class PlacesClientTest extends RobolectricTestCase {
45+
public static final String OBJECT_ID_RUE_RIVOLI = "95057362_123324299";
4446
PlacesClient places;
4547

4648
@Override
@@ -80,4 +82,16 @@ public void searchAsync() throws Exception {
8082
}
8183
});
8284
}
85+
86+
@Test
87+
public void getByObjectIDValid() throws Exception {
88+
final JSONObject rivoli = places.getByObjectID(OBJECT_ID_RUE_RIVOLI);
89+
assertNotNull(rivoli);
90+
assertEquals(OBJECT_ID_RUE_RIVOLI, rivoli.getString("objectID"));
91+
}
92+
93+
@Test(expected = AlgoliaException.class)
94+
public void getByObjectIDInvalid() throws Exception {
95+
places.getByObjectID("4242424242");
96+
}
8397
}

0 commit comments

Comments
 (0)