Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bongloy Agent Network Code Snippits
require "net/http"
require "uri"
require "jwt"
jwt_payload = {
"api_token": "[your api token]",
"timestamp": Time.now.to_i
}
private_key = OpenSSL::PKey::RSA.new(File.read("private_key.pem"))
jwt = JWT.encode(jwt_payload, private_key, 'RS256')
uri = URI.parse("https://agent-network-sandbox.bongloy.com/v1/transfers")
request = Net::HTTP::Post.new(uri.request_uri)
request["Content-Type"] = "application/vnd.api+json"
request["Authorization"] = "Bearer #{jwt}"
request.body = File.read("payload.json")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.request(request)
p response.body
import java.net.URI;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.file.*;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.*;
import java.time.Instant;
import java.util.Base64;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
class AgentNetworkApp {
public static void main(String[] args) throws Exception {
long unixTimestamp = Instant.now().getEpochSecond();
String payload = Files.readString(Paths.get("payload.json"));
Algorithm algorithm = Algorithm.RSA256(null, (RSAPrivateKey) getPrivateKey());
String token = JWT.create()
.withClaim("api_token", "[your api token]")
.withClaim("timestamp", unixTimestamp)
.sign(algorithm);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://agent-network-sandbox.bongloy.com/v1/transfers"))
.header("Content-Type", "application/vnd.api+json")
.header("Authorization", "Bearer " + token)
.POST(BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
private static PrivateKey getPrivateKey() throws Exception {
String privateKeyContent = Files.readString(Paths.get("private_key.pem"));
privateKeyContent = privateKeyContent
.replaceAll("\\n", "")
.replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "");
PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyContent));
return KeyFactory.getInstance("RSA").generatePrivate(keySpecPKCS8);
}
}
{
"data": {
"type": "transfer",
"attributes": {
"amount": 10000,
"currency": "USD",
"destination_account_number": "bongloy_testing-P01-1234560",
"metadata": {
"foobar": "foobar"
}
}
}
}
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCdqMMobHq/l2ZT
Q+IXRFyvCiw4+t60tDBamSGkv1/1h7ZwbWgkFq7Yp7L4mC3zYk9ygti84onGWAxN
tHgQZR+jmVSxUc9UxCzD7pVNzab3cBW8pP+RoxUHa2d3Ish+oTpqG6PSC9F4a6Ak
La8VwnczsCqYd712fBftS8n0YZOrFbYDUaIpzBpOHoOz+MfILyxXGBL2Rj09qFjo
niYkUCItJ18nKM7LyrTKb+OvLulrhW/eOb4p/f73ucLmmy74M61XQQ8PeDsUD9Cm
nkXbx8BDREXNh9v9RoxAU5tAYtzYfubSIZ+RQsA5lUqRQlr7qlnDv0+5TfSm71LR
l1p+gewt9jn69WTuZt8LfVH6NTDXY1gCh+fsBpQWr0mBYsnNGPLOy4jbg0z33hNs
0t40w9/5nRFWPfzazCnwZ4uqI4XETjwIpzM0KqlHbZh32e9wciQXOpJfWDWZJ86d
QlOhsTvG6GqL7QCh81SwJZzubjVSn/R/sel1xI9Zhhb761wj0AIT2bTJnLX4AKmE
o8/YmCt59zCrI7qLnk+EPKev4E99C8210g54vBtFT4PPJRzJsknWj5pMR1/bvSD1
HBK+6L7YmJX8s+2lgp3bdNl2SBEHYkJiNcCqpW397H/fp7aMVFg84bVjUpcHT9l5
fOh/LgkQahGUIqogJ7u01oT5u0IPnwIDAQABAoICABtrbHWtWDPWGv/EQKAXTZ9L
v6ExUGZRKE+5bjZ+6iuDrOEkxgXww/v+Powpu2Qm5vZdd2Bybc/HJGynRHJlg/kq
A6bLOanebIKvDdx4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2wRnxEBDI7fv+YMcg5FquBgWhZ1pSKo9xrKgt+cULrdefI
qLH0a/DXPiOaI2hsLn9sqN+l+XSnfzgRkccfP5TaawP56w32NHNCj38iHEx4UxoP
4alB38b8YLW+2JvnZhjwi1xTqcNwda3PbQueSYrA6FYho701mz2UpyorywCLdhRt
8mFFhvnbdcVIui7wwxk4cyaTSedXzKQ=
-----END PRIVATE KEY-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.