Skip to content

Commit

Permalink
add ESH-RQST
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Mar 14, 2023
1 parent 40fb398 commit 61b6282
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public static Response response426(String hash, String subscription) {
return Response.create(426, String.format("Stream with hash <%s> does not contain a subscription request of type <%s>.", hash, subscription));
}

public static Response response427(String hash, String subscription, String response) {
return Response.create(427, String.format("Stream with hash <%s> returned an irregular response when attempting to subscribe to <%s>. Response returned is: <%s>", hash, subscription, response));
public static Response response427(String type, String response) {
return Response.create(427, String.format("Stream of type <%s> returned an irregular response when attempting to send request. Response returned is: <%s>", type, response));
}

public static Response response428(String hash, String request) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Response processRQST(Packet packet) {
if((validate = packet.validate("type")) != null)
return ResponseFactory.response500("ExternalStreamHandler", validate);

// validate type exists
if(!manager.containsType(packet.getData("type")))
return ResponseFactory.response420(packet.getData("type"));

Object[] response;

// check to see if dated
Expand All @@ -46,8 +50,11 @@ public Response processRQST(Packet packet) {

// check to see if valid
if(!((boolean)response[0])) {

return ResponseFactory.response427(packet.getData("type"), response[1].toString());
}

// return valid
return ResponseFactory.response200();
}

// // source: source of data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected Object[] request(String type, HashMap<String, String> data, String sta
if(raw_properties.length % 2 != 0)
return new Object[] {false, String.format("Properties must be in <key, value> pairs.")};

for(int i = 0; i < raw_properties.length; i++)
for(int i = 0; i < raw_properties.length; i+=2)
properties.put(raw_properties[i], raw_properties[i + 1]);
}

Expand All @@ -66,8 +66,8 @@ protected Object[] request(String type, HashMap<String, String> data, String sta
if(raw_headers.length % 2 != 0)
return new Object[] {false, String.format("Headers must be in <key, value> pairs.")};

for(int i = 0; i < raw_headers.length; i++)
properties.put(raw_headers[i], raw_headers[i + 1]);
for(int i = 0; i < raw_headers.length; i+=2)
headers.put(raw_headers[i], raw_headers[i + 1]);
}

// retrieve request framework
Expand All @@ -90,6 +90,7 @@ public void processRequest(String collection, HashMap<String, String> data) {
if(data == null || data.isEmpty())
return;

System.out.println(collection + ": " + data.toString());
// TODO: FINISH
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
import java.util.HashMap;

import org.core.core.Core;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestExternalRequestManager {

public static Core core;

@BeforeClass
public static void init() {
core = new Core();
}

@Test
public void TestEXSR() {
Core core = new Core();

HashMap<String, String> data = new HashMap<String, String>();
data.put("type", "amberdata-aave-protocol");

Expand All @@ -22,4 +28,16 @@ public void TestEXSR() {

assertEquals("false", core.send("ESH", "EXSR", data).data());
}

@Test
public void TestRQST() {
HashMap<String, String> data = new HashMap<String, String>();
data.put("type", "amberdata-uniswap-pool");
data.put("url_path", "poolAddress,0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc");
data.put("headers", "x-api-key,UAK7ed69235426c360be22bfc2bde1809b6");
data.put("startDate", "2022-09-01");
data.put("endDate", "2022-09-02");

assertEquals(200, core.send("ESH", "RQST", data).code());
}
}

0 comments on commit 61b6282

Please sign in to comment.