Skip to content

Commit

Permalink
add makerdao properties files
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Feb 6, 2023
1 parent 1b6bc7b commit 19bd0a3
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public void initialize() {
@CrossOrigin
@RequestMapping(path = {"/request"})
public ResponseEntity<String> handleRequest(
@RequestParam(name="name", required=true) String name,
@RequestParam(name="name", required=true) String name,
@RequestParam(name="properties", required=false) String properties,
@RequestParam(name="headers", required=false) String headers) {
@RequestParam(name="headers", required=false) String headers,
@RequestParam(name="path",required=false) String path) {

// assert that request exists
if(!RequestManager.hasRequestFormat(name))
Expand All @@ -49,6 +50,7 @@ public ResponseEntity<String> handleRequest(
// parse properties and headers
HashMap<String, String> properties_map = new HashMap<String, String>();
HashMap<String, String> headers_map = new HashMap<String, String>();
String[] path_map = new String[] {};

if(properties != null) {
String[] arr = properties.split(",");
Expand All @@ -68,11 +70,14 @@ public ResponseEntity<String> handleRequest(
headers_map.put(arr[i], arr[i + 1]);
}

System.out.println(properties_map);
System.out.println(headers_map);
if(path != null) {
path_map = path.split(",");
if(path_map.length % 2 != 0)
return new ResponseEntity<String>("Path must be in the format of <key, value> pairs.", HttpStatus.PRECONDITION_FAILED);
}

// submit request
String response = request.request(properties_map, headers_map);
String response = request.request(path_map, properties_map, headers_map);
if(response != null)
return new ResponseEntity<String>(response, HttpStatus.SERVICE_UNAVAILABLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public abstract class RequestFramework {
private final String name;
private String url;
private final String[] url_path;
private final HashMap<String, String> properties;
private final HashMap<String, String> headers;
private final HashMap<String, String> tags;
Expand All @@ -26,6 +27,8 @@ public abstract class RequestFramework {
// default constructor used for templating
public RequestFramework() {
this.name = null;
this.url = null;
this.url_path = null;
this.properties = null;
this.headers = null;
this.tags = null;
Expand All @@ -34,10 +37,11 @@ public RequestFramework() {
this.path = null;
}

public RequestFramework(String name, String url, HashMap<String, String> properties, HashMap<String, String> headers,
public RequestFramework(String name, String url, String[] url_path, HashMap<String, String> properties, HashMap<String, String> headers,
HashMap<String, String> tags, String[] recursive_location, String recursive_replacement, String[] path) {
this.name = name;
this.url = url;
this.url_path = url_path;
this.properties = properties;
this.headers = headers;
this.tags = tags;
Expand All @@ -54,6 +58,8 @@ protected final Request getRequest(String url, HashMap<String, String> propertie
// define builder
Builder builder = new Builder();
StringBuilder url_builder = new StringBuilder(url);

// add properties delim if there are properties
if(!properties.isEmpty())
url_builder.append("?");

Expand Down Expand Up @@ -135,8 +141,33 @@ public final String[] getPath() {
return path;
}

public final synchronized String request(HashMap<String, String> properties, HashMap<String, String> headers) {
return process(url, properties, headers);
public final synchronized String request(String[] url_path, HashMap<String, String> properties, HashMap<String, String> headers) {
//
if(url_path.length % 2 != 0) {
System.err.println("Url path is not formatted properly and must be in <key, value> pairs.");
return "Url path is not formatted properly and must be in <key, value> pairs.";
}

// validate that url_path parameter is valid
if(this.url_path.length != url_path.length) {
System.err.println("Url path does not match defined url path.");
return "Url path does not match defined url path.";
}

// update path if there are url path extensions
StringBuilder url_builder = new StringBuilder(url);
if(url_path.length > 0) {
for(int i = 0; i < url_path.length; i+=2) {
if(!url_path[i].equals(this.url_path[i])) {
System.err.println(String.format("Url path key <%s> does not match defined key <%s>", url_path[i], this.url_path[i]));
return String.format("Url path key <%s> does not match defined key <%s>", url_path[i], this.url_path[i]);
}

url_builder.append("/").append(url_path[i+1]);
}
}

return process(url_builder.toString(), properties, headers);
}

protected String process(String url, HashMap<String, String> properties, HashMap<String, String> headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void initialize() throws InstantiationException, IllegalAccessExce
// extract all properties and parse
String name = null;
String url = null;
String[] url_path = {};
HashMap<String, String> properties = new HashMap<String, String>();
HashMap<String, String> headers = new HashMap<String, String>();
String recursive_type = null;
Expand All @@ -64,6 +65,15 @@ public static void initialize() throws InstantiationException, IllegalAccessExce
System.exit(1);
}

// parse url base properties
if(p.containsKey("url.base.path")) {
url_path = p.getProperty("url.base.path").split(",");
if(url_path.length % 2 != 0) {
System.err.println("Url path must be formatted with <key, value> pairs.");
System.exit(1);
}
}

// parse url properties
if(p.containsKey("url.properties")) {
String[] arr = p.getProperty("url.properties").split(",");
Expand Down Expand Up @@ -144,9 +154,9 @@ public static void initialize() throws InstantiationException, IllegalAccessExce
}

RequestManager.requests.put(name, templates.get(recursive_type).getDeclaredConstructor(
String.class, String.class, HashMap.class, HashMap.class,
String.class, String.class, String[].class, HashMap.class, HashMap.class,
HashMap.class, String[].class, String.class, String[].class).newInstance(
name, url, properties, headers, tags, recursive_location, recursive_replacement, path));
name, url, url_path, properties, headers, tags, recursive_location, recursive_replacement, path));

System.out.println(String.format("Successfully added type [%s]", name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public RequestParameterized() {
super();
}

public RequestParameterized(String name, String url, HashMap<String, String> properties, HashMap<String, String> headers,
public RequestParameterized(String name, String url, String[] url_path, HashMap<String, String> properties, HashMap<String, String> headers,
HashMap<String, String> tags, String[] recursive_location, String recursive_replacement, String[] path) {
super(name, url, properties, headers, tags, recursive_location, recursive_replacement, path);
super(name, url, url_path, properties, headers, tags, recursive_location, recursive_replacement, path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static void main(String[] args) {
String recursive_replacement = null;

RequestParameterized request = new RequestParameterized("test",
"https://web3api.io/api/v2/addresses", properties, headers, tags,
"https://web3api.io/api/v2/addresses", new String[]{}, properties, headers, tags,
recursive_location, recursive_replacement, path);

request.request(properties, headers);
request.request(new String[] {}, properties, headers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static void main(String[] args) {
String recursive_replacement = null;

RequestParameterized request = new RequestParameterized("test",
"https://web3api.io/api/v2/defi/lending/makerdao/protocol", properties, headers, tags,
"https://web3api.io/api/v2/defi/lending/makerdao/protocol", new String[]{}, properties, headers, tags,
recursive_location, recursive_replacement, path);

request.request(properties, headers);
request.request(new String[] {}, properties, headers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
request.name= amberdata-makerdao-asset

url.base= https://web3api.io/api/v2/defi/lending/makerdao/assets

url.base.path= asset,.

url.properties= size,900

url.headers= accept,application/json,\
x-amberdata-blockchain-id,ethereum-mainnet,\
x-api-key,.

data.path= payload,\
data

recursion.type= parameterized

recursion.tags= -l,900,\
-t,url

recursion.location= payload,metadata,next
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
request.name= amberdata-makerdao-protocol

url.base= https://web3api.io/api/v2/defi/lending/makerdao/protocol

url.properties= size,900

url.headers= accept,application/json,\
x-amberdata-blockchain-id,ethereum-mainnet,\
x-api-key,.

data.path= payload,\
data

recursion.type= parameterized

recursion.tags= -l,900,\
-t,url

recursion.location= payload,metadata,next
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
request.name= amberdata-makerdao-wallet

url.base= https://web3api.io/api/v2/defi/lending/makerdao/wallets

url.base.path= walletAddress,.

url.properties= size,900

url.headers= accept,application/json,\
x-api-key,.

data.path= payload,\
data

recursion.type= parameterized

recursion.tags= -l,900,\
-t,url

recursion.location= payload,metadata,next
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ request.name= template
# Base url of the REST API call
url.base= http://localhost:8080

# [OPTIONAL]
# Url PATH properties that are required for parsing of the system. For example, if the url is
# https://localhost:8080/api/v1/<asset>/<value> where asset is dictated by the parameter 'asset',
# then this variable will be set to 'asset,.' Note all properties are in sequential order, such that
# asset must be defined before value.
url.base.path= asset,.,\
value,.

# This property details all required properties to be passed on runtime when called. Optional
# properties are not required to be specified here. Note that properties can be given a default
# value or can be forced to be specified. The list is in (<key>, <value>) pairs, with each property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ request.name= template
# Base url of the REST API call
url.base= http://localhost:8080

# [OPTIONAL]
# Url PATH properties that are required for parsing of the system. For example, if the url is
# https://localhost:8080/api/v1/<asset>/<value> where asset is dictated by the parameter 'asset',
# then this variable will be set to 'asset,.' Note all properties are in sequential order, such that
# asset must be defined before value.
url.base.path= asset,.,\
value,.

# This property details all required properties to be passed on runtime when called. Optional
# properties are not required to be specified here. Note that properties can be given a default
# value or can be forced to be specified. The list is in (<key>, <value>) pairs, with each property
Expand Down

0 comments on commit 19bd0a3

Please sign in to comment.