Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ ext {
}

allprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'

checkstyle {
configFile = file("$rootProject.projectDir/src/checkstyle/checkstyle.xml")
ignoreFailures = false
}

checkstyleMain {
source = 'src/main/java'
}

checkstyleTest {
source = 'src/test/java'
}

repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public interface FunPayClient {
*
* @param goldenKey golden key which will be used to authorize the user
* @param csrfToken csrf token which is required to interact with the user in this operation
* @param PHPSESSID user session without which the csrf token will be useless
* @param phpSessionId user session without which the csrf token will be useless
* @param request request storing all necessary data for saving offer
* @throws FunPayApiException if the other api-related exception
* @throws InvalidGoldenKeyException if the golden key is invalid
* @throws InvalidCsrfTokenOrPHPSESSIDException if the csrf token or PHPSESSID is invalid
*/
void saveOffer(String goldenKey, String csrfToken, String PHPSESSID, SaveOfferRequest request) throws FunPayApiException,
void saveOffer(String goldenKey, String csrfToken, String phpSessionId , SaveOfferRequest request) throws FunPayApiException,
InvalidGoldenKeyException, InvalidCsrfTokenOrPHPSESSIDException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.NonNull;
import okhttp3.*;
import okhttp3.OkHttpClient;
import okhttp3.Response;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.MultipartBody;
import ru.funpay4j.client.request.SaveOfferRequest;
import ru.funpay4j.client.exceptions.FunPayApiException;
import ru.funpay4j.client.exceptions.InvalidCsrfTokenOrPHPSESSIDException;
Expand Down Expand Up @@ -108,7 +112,7 @@ public void raiseAllOffers(@NonNull String goldenKey, long gameId, long lotId) t
*/
@Override
public void saveOffer(@NonNull String goldenKey, @NonNull String csrfToken,
@NonNull String PHPSESSID, @NonNull SaveOfferRequest request) throws FunPayApiException, InvalidGoldenKeyException{
@NonNull String phpSessionId, @NonNull SaveOfferRequest request) throws FunPayApiException, InvalidGoldenKeyException{
MultipartBody.Builder multipartBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("csrf_token", csrfToken)
Expand Down Expand Up @@ -138,7 +142,7 @@ public void saveOffer(@NonNull String goldenKey, @NonNull String csrfToken,
}

try (Response response = httpClient.newCall(new Request.Builder().post(multipartBody.build()).url(baseURL + "/lots/offerSave")
.addHeader("Cookie", "golden_key=" + goldenKey + "; PHPSESSID=" + PHPSESSID)
.addHeader("Cookie", "golden_key=" + goldenKey + "; PHPSESSID=" + phpSessionId)
.addHeader("x-requested-with", "XMLHttpRequest")
.build()).execute()) {
String responseBodyString = response.body().string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.client.objects.user;

import lombok.*;
import lombok.Getter;
import lombok.Setter;
import lombok.EqualsAndHashCode;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.client.objects.user;

import lombok.*;
import lombok.Getter;
import lombok.Setter;
import lombok.EqualsAndHashCode;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.client.objects.user;

import lombok.*;
import lombok.Getter;
import lombok.Setter;
import lombok.EqualsAndHashCode;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import ru.funpay4j.client.objects.offer.ParsedPreviewOffer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

import com.google.gson.JsonParser;
import lombok.NonNull;
import okhttp3.*;
import okhttp3.OkHttpClient;
import okhttp3.Response;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.MultipartBody;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand All @@ -26,7 +30,11 @@
import ru.funpay4j.client.objects.lot.ParsedLotCounter;
import ru.funpay4j.client.objects.offer.ParsedOffer;
import ru.funpay4j.client.objects.offer.ParsedPreviewOffer;
import ru.funpay4j.client.objects.user.*;
import ru.funpay4j.client.objects.user.ParsedPreviewSeller;
import ru.funpay4j.client.objects.user.ParsedSeller;
import ru.funpay4j.client.objects.user.ParsedSellerReview;
import ru.funpay4j.client.objects.user.ParsedUser;
import ru.funpay4j.client.objects.user.ParsedAdvancedSellerReview;
import ru.funpay4j.utils.FunPayUserUtil;
import ru.funpay4j.client.exceptions.FunPayApiException;
import ru.funpay4j.client.exceptions.offer.OfferNotFoundException;
Expand All @@ -36,7 +44,12 @@

import java.io.IOException;
import java.text.ParseException;
import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;

/**
* This implementation of FunPayParser uses Jsoup to parse
Expand Down Expand Up @@ -402,12 +415,12 @@ public CsrfTokenAndPHPSESSID parseCsrfTokenAndPHPSESSID(@NonNull String goldenKe
String dataAppData = funPayDocument.getElementsByTag("body").attr("data-app-data");

String csrfToken = JsonParser.parseString(dataAppData).getAsJsonObject().get("csrf-token").getAsString();
//Use this regex to get the value of the PHPSESSID key from the Set-Cookie header
String PHPSESSID = funPayHtmlResponse.header("Set-Cookie").replaceAll(".*PHPSESSID=([^;]*).*", "$1");
//Use this regex to get the value of the PHP_SESSION_ID key from the Set-Cookie header
String phpSessionId = funPayHtmlResponse.header("Set-Cookie").replaceAll(".*PHPSESSID=([^;]*).*", "$1");

return CsrfTokenAndPHPSESSID.builder()
.csrfToken(csrfToken)
.PHPSESSID(PHPSESSID)
.PHPSESSID(phpSessionId)
.build();
} catch (IOException e) {
throw new FunPayApiException(e.getLocalizedMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

import java.io.IOException;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author panic08
Expand All @@ -52,6 +55,7 @@ void setUp() throws IOException {
void tearDown() throws IOException {
this.mockWebServer.shutdown();
}

@Test
void testUpdateAvatar() throws Exception {
String goldenKey = "valid_golden_key";
Expand Down Expand Up @@ -113,7 +117,7 @@ void testRaiseAllOffersAlreadyRaised() throws Exception {
void testSaveOffer() throws Exception {
String goldenKey = "valid_golden_key";
String csrfToken = "valid_csrf_token";
String PHPSESSID = "valid_phpsessid";
String phpSessId = "valid_phpsessid";
SaveOfferRequest request = SaveOfferRequest.builder()
.offerId(33502824L)
.nodeId(149L)
Expand All @@ -135,7 +139,7 @@ void testSaveOffer() throws Exception {

mockWebServer.enqueue(new MockResponse().setBody("{\"done\": true}").setResponseCode(200));

client.saveOffer(goldenKey, csrfToken, PHPSESSID, request);
client.saveOffer(goldenKey, csrfToken, phpSessId, request);

assertEquals(1, mockWebServer.getRequestCount());
}
Expand All @@ -144,36 +148,36 @@ void testSaveOffer() throws Exception {
void testSaveOfferInvalidGoldenKey() throws Exception {
String goldenKey = "invalid_golden_key";
String csrfToken = "valid_csrf_token";
String PHPSESSID = "valid_phpsessid";
String phpSessId = "valid_phpsessid";
SaveOfferRequest request = SaveOfferRequest.builder().build();

mockWebServer.enqueue(new MockResponse().setResponseCode(403));

assertThrows(InvalidGoldenKeyException.class, () -> client.saveOffer(goldenKey, csrfToken, PHPSESSID, request));
assertThrows(InvalidGoldenKeyException.class, () -> client.saveOffer(goldenKey, csrfToken, phpSessId, request));
}

@Test
void testSaveOfferInvalidCsrfTokenOrPHPSESSID() throws Exception {
String goldenKey = "valid_golden_key";
String csrfToken = "invalid_csrf_token";
String PHPSESSID = "invalid_phpsessid";
String phpSessId = "invalid_phpsessid";
SaveOfferRequest request = SaveOfferRequest.builder().build();

mockWebServer.enqueue(new MockResponse().setBody("{\"msg\": \"Обновите страницу и повторите попытку.\"}").setResponseCode(400));

assertThrows(InvalidCsrfTokenOrPHPSESSIDException.class, () -> client.saveOffer(goldenKey, csrfToken, PHPSESSID, request));
assertThrows(InvalidCsrfTokenOrPHPSESSIDException.class, () -> client.saveOffer(goldenKey, csrfToken, phpSessId, request));
}

@Test
void testSaveOfferErrorResponse() throws Exception {
String goldenKey = "valid_golden_key";
String csrfToken = "valid_csrf_token";
String PHPSESSID = "valid_phpsessid";
String phpSessId = "valid_phpsessid";
SaveOfferRequest request = SaveOfferRequest.builder().build();

mockWebServer.enqueue(new MockResponse().setBody("{\"done\": false, \"error\": \"some error\", \"errors\": {}}").setResponseCode(200));

assertThrows(RuntimeException.class, () -> client.saveOffer(goldenKey, csrfToken, PHPSESSID, request));
assertThrows(RuntimeException.class, () -> client.saveOffer(goldenKey, csrfToken, phpSessId, request));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,24 @@
import ru.funpay4j.client.objects.lot.ParsedLotCounter;
import ru.funpay4j.client.objects.offer.ParsedOffer;
import ru.funpay4j.client.objects.offer.ParsedPreviewOffer;
import ru.funpay4j.client.objects.user.*;
import ru.funpay4j.client.objects.user.ParsedUser;
import ru.funpay4j.client.objects.user.ParsedSeller;
import ru.funpay4j.client.objects.user.ParsedSellerReview;
import ru.funpay4j.client.objects.user.ParsedAdvancedSellerReview;
import ru.funpay4j.client.objects.user.ParsedPreviewSeller;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* @author panic08
Expand Down Expand Up @@ -273,17 +283,17 @@ void testParseSellerReviewsUserNotFound() throws Exception {
void testParseCsrfTokenAndPHPSESSID() throws Exception {
String goldenKey = "some_golden_key";
String csrfToken = "some_csrf_token";
String phpsessid = "some_phpsessid";
String phpSessId = "some_phpsessid";
String html = "<body data-app-data='{\"csrf-token\": \"" + csrfToken + "\"}'></body>";
mockWebServer.enqueue(new MockResponse()
.setBody(html)
.addHeader("Set-Cookie", "PHPSESSID=" + phpsessid + "; path=/")
.addHeader("Set-Cookie", "PHPSESSID=" + phpSessId + "; path=/")
.setResponseCode(200));

CsrfTokenAndPHPSESSID result = parser.parseCsrfTokenAndPHPSESSID(goldenKey);

assertNotNull(result);
assertEquals(csrfToken, result.getCsrfToken());
assertEquals(phpsessid, result.getPHPSESSID());
assertEquals(phpSessId, result.getPHPSESSID());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import ru.funpay4j.client.objects.user.ParsedSellerReview;
import ru.funpay4j.client.objects.user.ParsedUser;
import ru.funpay4j.client.request.SaveOfferRequest;
import ru.funpay4j.core.commands.offer.*;
import ru.funpay4j.core.commands.offer.EditOffer;
import ru.funpay4j.core.commands.offer.CreateOffer;
import ru.funpay4j.core.commands.offer.DeleteOffer;
import ru.funpay4j.core.commands.offer.CreateOfferImage;
import ru.funpay4j.core.commands.offer.RaiseAllOffers;
import ru.funpay4j.core.commands.user.GetSellerReviews;
import ru.funpay4j.core.commands.user.GetUser;
import ru.funpay4j.core.commands.user.UpdateAvatar;
Expand Down
13 changes: 10 additions & 3 deletions core/src/main/java/ru/funpay4j/core/FunPayExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import ru.funpay4j.client.objects.game.ParsedPromoGame;
import ru.funpay4j.client.objects.lot.ParsedLot;
import ru.funpay4j.client.objects.offer.ParsedOffer;
import ru.funpay4j.client.objects.user.*;
import ru.funpay4j.client.objects.user.ParsedAdvancedSellerReview;
import ru.funpay4j.client.objects.user.ParsedSellerReview;
import ru.funpay4j.client.objects.user.ParsedUser;
import ru.funpay4j.client.objects.user.ParsedPreviewSeller;
import ru.funpay4j.client.objects.user.ParsedSeller;
import ru.funpay4j.client.client.OkHttpFunPayClient;
import ru.funpay4j.core.commands.offer.GetOffer;
import ru.funpay4j.core.commands.game.GetPromoGames;
Expand All @@ -39,8 +43,11 @@
import ru.funpay4j.core.objects.lot.LotCounter;
import ru.funpay4j.core.objects.offer.Offer;
import ru.funpay4j.core.objects.offer.PreviewOffer;
import ru.funpay4j.core.objects.user.*;

import ru.funpay4j.core.objects.user.AdvancedSellerReview;
import ru.funpay4j.core.objects.user.SellerReview;
import ru.funpay4j.core.objects.user.User;
import ru.funpay4j.core.objects.user.Seller;
import ru.funpay4j.core.objects.user.PreviewSeller;
import java.net.Proxy;
import java.util.List;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.core.commands.game;

import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NonNull;

/**
* Use this command to get promo games
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/ru/funpay4j/core/commands/lot/GetLot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.core.commands.lot;

import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NonNull;

/**
* Use this command to get lot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.core.commands.offer;

import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package ru.funpay4j.core.commands.offer;

import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NonNull;

/**
* Use this command to create offer image
Expand Down
Loading