Skip to content

Commit

Permalink
#41 implemented find
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar Atef committed Feb 25, 2019
1 parent 1c5be27 commit 1f35940
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
28 changes: 24 additions & 4 deletions src/main/java/com/amihaiemil/zold/RtWallet.java
Expand Up @@ -29,13 +29,16 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.json.Json;
import javax.json.JsonArray;

/**
* RESTful Zold wallet.
Expand Down Expand Up @@ -143,10 +146,27 @@ public void pay(
}

@Override
public void find(final String id, final String details) {
throw new UnsupportedOperationException(
"Not yet implemented. If you can contribute please, do it at "
+ "https://github.com/amihaiemil/zold-java-client"
public JsonArray find(
final String id, final String details
) throws IOException, URISyntaxException {
URIBuilder builder = new URIBuilder(this.baseUri.toString() + "/find");
builder.setParameter("bnf", id);
builder.setParameter("details", details);
final HttpGet request = new HttpGet(
builder.build()
);
try {
return this.client.execute(
request,
new ReadJsonArray(
new MatchStatus(
request.getURI(),
HttpStatus.SC_OK
)
)
);
} finally {
request.releaseConnection();
}
}
}
17 changes: 11 additions & 6 deletions src/main/java/com/amihaiemil/zold/Wallet.java
Expand Up @@ -25,7 +25,9 @@
*/
package com.amihaiemil.zold;

import javax.json.JsonArray;
import java.io.IOException;
import java.net.URISyntaxException;

/**
* Zold Wallet.
Expand Down Expand Up @@ -64,10 +66,13 @@ void pay(
)throws IOException;

/**
* Finds all payments that match this query and returns.
* @param id Wallet id
* @param details Regex of payment details
* @throws IOException If there's a networking problem.
*/
void find(String id, String details)throws IOException;
* Finds all payments that match this query and returns.
* @return Array of found transactions.
* @param id Wallet id
* @param details Regex of payment details
* @throws IOException If there's a networking problem.
* @throws URISyntaxException If there's a problem building URI.
*/
JsonArray find(String id, String details)
throws IOException, URISyntaxException;
}

0 comments on commit 1f35940

Please sign in to comment.