Skip to content

Commit

Permalink
New feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
perveevm committed Aug 22, 2022
1 parent 3e4931a commit fc10852
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 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.6.1</version>
<version>0.6.2</version>

<properties>
<maven.compiler.source>15</maven.compiler.source>
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/ru/perveevm/polygon/user/PolygonUserSession.java
Expand Up @@ -12,6 +12,7 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import ru.perveevm.polygon.exceptions.user.PolygonUserSessionException;

import java.io.Closeable;
Expand Down Expand Up @@ -121,6 +122,27 @@ public void problemBuildPackage(final String name, final boolean createFull, fin
problemBuildPackage(null, name, createFull, doVerification);
}

public String problemGetShareURL(final int id) throws PolygonUserSessionException {
return problemGetShareUrl(id, null);
}

public String problemGetShareUrl(final String name) throws PolygonUserSessionException {
return problemGetShareUrl(null, name);
}

private String problemGetShareUrl(final Integer id, final String name) throws PolygonUserSessionException {
authorize();

String html = getProblemPage(id, name).toString();
int pos = html.indexOf("supportCopyingToClipboard");
int firstQuote = html.indexOf("\"", pos);
int secondQuote = html.indexOf("\"", firstQuote + 1);
int thirdQuote = html.indexOf("\"", secondQuote + 1);
int fourthQuote = html.indexOf("\"", thirdQuote + 1);

return html.substring(thirdQuote + 1, fourthQuote);
}

private void problemBuildPackage(final Integer id, final String name, final boolean createFull,
final boolean doVerification) throws PolygonUserSessionException {
String session = getSessionBySearchRequest(id, name);
Expand Down Expand Up @@ -178,7 +200,7 @@ private List<Element> searchProblemByIdOrName(final Integer id, final String nam
.collect(Collectors.toList());
}

private String getSessionBySearchRequest(final Integer id, final String name) throws PolygonUserSessionException {
private Element getProblemPage(final Integer id, final String name) throws PolygonUserSessionException {
List<Element> rows = searchProblemByIdOrName(id, name);

if (rows.isEmpty()) {
Expand All @@ -201,7 +223,11 @@ private String getSessionBySearchRequest(final Integer id, final String name) th
throw new PolygonUserSessionException("Problem not found");
}

Element sessionTag = parseDocument(getHtml(BASE_URL + link)).getElementById("session");
return parseDocument(getHtml(BASE_URL + link));
}

private String getSessionBySearchRequest(final Integer id, final String name) throws PolygonUserSessionException {
Element sessionTag = getProblemPage(id, name).getElementById("session");
if (sessionTag == null) {
throw new PolygonUserSessionException("Cannot find session");
}
Expand Down

0 comments on commit fc10852

Please sign in to comment.