diff --git a/httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt b/httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt index 95d711a8..078edf99 100644 --- a/httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt +++ b/httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt @@ -1,6 +1,7 @@ package tbdex.sdk.httpclient import com.fasterxml.jackson.module.kotlin.convertValue +import de.fxlae.typeid.TypeId import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient @@ -100,6 +101,19 @@ object TbdexHttpClient { } } + /** + * Fetches a specific exchange identified by its ID from the PFI. + * + * @param pfiDid The decentralized identifier of the PFI. + * @param requesterDid The decentralized identifier of the entity requesting the exchange. + * @param exchangeId The unique identifier of the exchange to be fetched. + * @return An [Exchange] containing the requested exchange. + * @throws TbdexResponseException for request or response errors. + */ + fun getExchange(pfiDid: String, requesterDid: Did, exchangeId: TypeId): Exchange { + return this.getExchange(pfiDid, requesterDid, exchangeId.toString()) + } + /** * Fetches a specific exchange identified by its ID from the PFI. * diff --git a/httpclient/src/test/kotlin/tbdex/sdk/httpclient/TbdexHttpClientTest.kt b/httpclient/src/test/kotlin/tbdex/sdk/httpclient/TbdexHttpClientTest.kt index 70e97202..038f887a 100644 --- a/httpclient/src/test/kotlin/tbdex/sdk/httpclient/TbdexHttpClientTest.kt +++ b/httpclient/src/test/kotlin/tbdex/sdk/httpclient/TbdexHttpClientTest.kt @@ -117,6 +117,18 @@ class TbdexHttpClientTest { assertEquals("400", exception.errors?.get(0)?.status) } + @Test + fun `get exchange TypeId overload success via mockwebserver`() { + val offeringId = TypeId.generate("offering") + val exchange = listOf(rfq(offeringId), quote()) + val mockResponseString = Json.jsonMapper.writeValueAsString(mapOf("data" to exchange)) + server.enqueue(MockResponse().setBody(mockResponseString).setResponseCode(HttpURLConnection.HTTP_OK)) + + val response = TbdexHttpClient.getExchange(pfiDid.uri, alice, TypeId.generate("rfq")) + + assertEquals(offeringId, (response[0] as Rfq).data.offeringId) + } + @Test fun `get exchange success via mockwebserver`() { val offeringId = TypeId.generate("offering")