import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; /** * v0.1 DRAFT. The Java snippets, run against the sandbox (Java 17+). * *
 *   export BORROU_BASE_URL=https://api.borrou.capital
 *   export BORROU_CLIENT_ID=bpc_test_...        # your sandbox credential
 *   export BORROU_CLIENT_SECRET=...             # from your secret store, never from a file you commit
 *   javac -d out *.java && java -cp out Quickstart
 * 
* *

Reads your products, a quote, the first page of your events and every one of your loans, and * submits one application for a synthetic borrower: an idempotent POST, sent twice with the same key * to show the replay. Writes run with a sandbox credential only. */ public final class Quickstart { private Quickstart() {} public static void main(String[] args) throws Exception { String clientId = required("BORROU_CLIENT_ID"); String baseUrl = System.getenv().getOrDefault("BORROU_BASE_URL", "https://api.borrou.capital"); BorrouClient client = new BorrouClient(baseUrl, clientId, required("BORROU_CLIENT_SECRET")); try { run(client, clientId); } catch (BorrouClient.ApiError e) { System.err.println(e.getMessage() + " (request " + e.requestId + ")"); System.exit(1); } } private static void run(BorrouClient client, String clientId) throws Exception { List products = MiniJson.array(MiniJson.object(client.get("/v1/products", Map.of()).body()).get("data")); Map product = null; for (Object item : products) { Map candidate = MiniJson.object(item); if (Boolean.TRUE.equals(candidate.get("api_lendable"))) { product = candidate; break; } } if (product == null) throw new IllegalStateException("No product can lend through the API yet: ask TFG to activate one."); String code = (String) product.get("code"); System.out.println("Product " + code); Map quote = MiniJson.object(client.get("/v1/quote", Map.of("principal_usdt", "1000.00", "product", code)).body()); System.out.println("1000.00 USDT needs " + quote.get("required_collateral_btc") + " BTC at " + quote.get("btc_price_usd") + " USD (indicative)"); if (clientId.startsWith("bpc_test_")) { // One key for this request. A retry after a timeout sends the same key and gets the stored answer. String key = UUID.randomUUID().toString(); Map borrower = new LinkedHashMap<>(); borrower.put("full_name", "Snippet Borrower"); borrower.put("email", "snippet-" + key.substring(0, 8) + "@partner-sandbox.test"); borrower.put("country", "AR"); Map application = new LinkedHashMap<>(); application.put("principal_usdt", "1000.00"); application.put("external_reference", "snippet-" + key); application.put("borrower", borrower); BorrouClient.Response first = client.post("/v1/applications", application, key); BorrouClient.Response again = client.post("/v1/applications", application, key); Object id = MiniJson.object(first.body()).get("id"); boolean replayed = again.replayed() && id.equals(MiniJson.object(again.body()).get("id")); System.out.println("Application " + id + " is " + MiniJson.object(first.body()).get("status") + "; the retry replayed it: " + replayed); } int[] events = {0}; client.paginate("/v1/events", Map.of("limit", "50"), "after", event -> { System.out.println("Event " + event.get("id") + " " + event.get("type")); return ++events[0] < 5; }); int[] loans = {0}; client.paginate("/v1/loans", Map.of("limit", "100"), "starting_after", loan -> { loans[0]++; return true; }); System.out.println(loans[0] + " loan(s) in all"); } private static String required(String name) { String value = System.getenv(name); if (value == null || value.isEmpty()) { System.err.println("Set " + name + "."); System.exit(1); } return value; } }