Skip to content

Commit

Permalink
PIN support added
Browse files Browse the repository at this point in the history
  • Loading branch information
perveevm committed Dec 16, 2021
1 parent bfc70a1 commit 005c70a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>ru.perveevm</groupId>
<artifactId>polygon-api</artifactId>
<version>0.2</version>
<version>0.3</version>

<properties>
<maven.compiler.source>15</maven.compiler.source>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/ru/perveevm/polygon/api/PolygonSession.java
Expand Up @@ -46,7 +46,7 @@ public class PolygonSession implements Closeable {
private final CloseableHttpClient client = HttpClients.createDefault();
private final Gson gson = new Gson();

// TODO pin
private String pin = null;

/**
* Initializes Polygon session with API key.
Expand All @@ -64,6 +64,16 @@ public void close() throws IOException {
client.close();
}

/**
* Sets <code>pin</code> that will be used in all following requests. You can set it to <code>null</code> if no pin
* is required.
*
* @param pin Polygon pin code for problem or contest access.
*/
public void setPin(final String pin) {
this.pin = pin;
}

/**
* Returns a list of problems, available to the user, according to search parameters.
*
Expand Down Expand Up @@ -771,6 +781,9 @@ private JsonElement sendAPIRequest(final String method, final String methodName,
private HttpResponse getAPIResponse(final String methodName, final List<NameValuePair> parameters)
throws PolygonSessionException {
List<NameValuePair> extendedParameters = new ArrayList<>(parameters);
if (pin != null) {
extendedParameters.add(new BasicNameValuePair("pin", pin));
}
extendedParameters.add(new BasicNameValuePair("apiKey", key));
extendedParameters.add(new BasicNameValuePair("time", String.valueOf(System.currentTimeMillis() / 1000)));
extendedParameters.add(new BasicNameValuePair("apiSig", generateApiSig(methodName, extendedParameters)));
Expand Down

0 comments on commit 005c70a

Please sign in to comment.