Skip to content

Commit

Permalink
stable api integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Feb 6, 2023
1 parent 5b89139 commit 1b6bc7b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public static void main(String[] args) {
public final static void output(String data) {
System.out.println(data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public ResponseEntity<String> handleRequest(
headers_map.put(arr[i], arr[i + 1]);
}

System.out.println(properties_map);
System.out.println(headers_map);

// submit request
String response = request.request(properties_map, headers_map);
if(response != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,15 @@ protected final Request getRequest(HashMap<String, String> properties, HashMap<S
}

protected final Request getRequest(String url, HashMap<String, String> properties, HashMap<String, String> headers) {
HashMap<String, String> all_properties = new HashMap<String, String>();
HashMap<String, String> all_headers = new HashMap<String, String>();

// add all properties and headers
for(String property : this.properties.keySet())
all_properties.put(property, this.properties.get(property));

for(String header : this.headers.keySet())
all_headers.put(header, this.headers.get(header));

for(String property : properties.keySet())
all_properties.put(property, properties.get(property));

for(String header : headers.keySet())
all_headers.put(header, headers.get(header));

// define builder
Builder builder = new Builder();
StringBuilder url_builder = new StringBuilder(url);
if(!all_properties.isEmpty())
if(!properties.isEmpty())
url_builder.append("?");

// add all required/optional properties
for(String property : all_properties.keySet()) {
String value = all_properties.get(property);
for(String property : properties.keySet()) {
String value = properties.get(property);

// check if empty
if(value == null || value.equals("")) {
Expand All @@ -98,8 +82,8 @@ protected final Request getRequest(String url, HashMap<String, String> propertie
builder = builder.url(url_builder.toString());

// add all headers
for(String header : all_headers.keySet()) {
String value = all_headers.get(header);
for(String header : headers.keySet()) {
String value = headers.get(header);

// check if empty
if(value == null || value.equals("")) {
Expand Down Expand Up @@ -152,30 +136,28 @@ public final String[] getPath() {
}

public final synchronized String request(HashMap<String, String> properties, HashMap<String, String> headers) {
// create new maps and add all properties and headers
HashMap<String, String> properties_combined = new HashMap<String, String>();
HashMap<String, String> headers_combined = new HashMap<String, String>();
return process(url, properties, headers);
}

protected String process(String url, HashMap<String, String> properties, HashMap<String, String> headers) {
HashMap<String, String> all_properties = new HashMap<String, String>();
HashMap<String, String> all_headers = new HashMap<String, String>();

// add all default properties
for(String key : this.properties.keySet())
properties_combined.put(key, this.properties.get(key));
// add all properties and headers
for(String property : this.properties.keySet())
all_properties.put(property, this.properties.get(property));

for(String key : this.headers.keySet())
headers_combined.put(key, this.headers.get(key));
for(String header : this.headers.keySet())
all_headers.put(header, this.headers.get(header));

// add all defined properties
for(String key : properties.keySet())
properties_combined.put(key, properties.get(key));
for(String property : properties.keySet())
all_properties.put(property, properties.get(property));

for(String key : headers.keySet())
headers_combined.put(key, headers.get(key));
for(String header : headers.keySet())
all_headers.put(header, headers.get(header));

return process(url, properties_combined, headers_combined);
}

protected String process(String url, HashMap<String, String> properties, HashMap<String, String> headers) {
OkHttpClient client = new OkHttpClient();
Request request = getRequest(url, properties, headers);
Request request = getRequest(url, all_properties, all_headers);
if(request == null) {
System.err.println("Malformed request, killing process.");
return "Malformed request, killing process.";
Expand All @@ -201,7 +183,7 @@ protected String process(String url, HashMap<String, String> properties, HashMap

// send to specific request handler
try {
handle(body, properties, headers);
handle(body, all_properties, all_headers);
} catch(Exception e) {
e.printStackTrace();
return e.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ request.name= amberdata-blockchain-addresses
url.base= https://web3api.io/api/v2/addresses

url.properties= page,0,\
size,1000
size,900

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

data.path= payload,\
records

recursion.type= parameterized

recursion.tags= -rp,page,\
-l,1000\
recursion.tags= -l,900,\
-t,incremental

data.path= payload,\
records
recursion.location= page
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ recursion.type= parameterized
# -l: limit on items from request
# -t: type of recursive parameter (url, incremental, static)
recursion.tags= -l,1000,\
-t,url
-t,url

# [OPTIONAL]:
# - url.recursion.type = static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ recursion.type= parameterized
# -l: limit on items from request
# -t: type of recursive parameter (url, incremental, static)
recursion.tags= -l,1000,\
-t,url
-t,url

# [OPTIONAL]:
# - url.recursion.type = static
Expand Down

0 comments on commit 1b6bc7b

Please sign in to comment.