From 774406c183ee96c02980bb6b4f01267cbf8420e3 Mon Sep 17 00:00:00 2001 From: allyans3 Date: Sun, 23 Feb 2025 19:40:16 -0500 Subject: [PATCH] Unofficial TargetsByTitle method and detailed() chain method --- .gitignore | 3 +- README.md | 4 ++ src/Configs/Engine.php | 83 +++++++++++++++++++++++++ src/DMarketAuthApi.php | 70 +++++++++++++-------- src/Engine/Request.php | 96 +++++++++++++++++++++++++---- src/Requests/AggregatedPrices.php | 4 +- src/Requests/BuyOffers.php | 4 +- src/Requests/ClosedUserOffers.php | 4 +- src/Requests/ClosedUserTargets.php | 4 +- src/Requests/CreateUserOffers.php | 4 +- src/Requests/CreateUserTargets.php | 4 +- src/Requests/CustomizedFees.php | 4 +- src/Requests/DeleteOffers.php | 4 +- src/Requests/DeleteUserTargets.php | 4 +- src/Requests/DepositAssets.php | 4 +- src/Requests/DepositStatus.php | 8 +-- src/Requests/EditUserOffers.php | 4 +- src/Requests/EditUserTargets.php | 4 +- src/Requests/LastSales.php | 4 +- src/Requests/MarketItems.php | 4 +- src/Requests/OffersByTitle.php | 4 +- src/Requests/SyncUserInventory.php | 4 +- src/Requests/TargetsByTitle.php | 44 +++++++++++++ src/Requests/UserBalance.php | 4 +- src/Requests/UserInventory.php | 4 +- src/Requests/UserItems.php | 4 +- src/Requests/UserOffers.php | 4 +- src/Requests/UserProfile.php | 4 +- src/Requests/UserTargets.php | 4 +- src/Requests/WithdrawAssets.php | 4 +- src/Responses/AggregatedPrices.php | 24 +++++++- src/Responses/BuyOffers.php | 24 +++++++- src/Responses/ClosedUserOffers.php | 24 +++++++- src/Responses/ClosedUserTargets.php | 24 +++++++- src/Responses/CreateUserOffers.php | 24 +++++++- src/Responses/CreateUserTargets.php | 24 +++++++- src/Responses/CustomizedFees.php | 24 +++++++- src/Responses/DeleteOffers.php | 24 +++++++- src/Responses/DeleteUserTargets.php | 24 +++++++- src/Responses/DepositAssets.php | 24 +++++++- src/Responses/DepositStatus.php | 24 +++++++- src/Responses/EditUserOffers.php | 24 +++++++- src/Responses/EditUserTargets.php | 24 +++++++- src/Responses/LastSales.php | 24 +++++++- src/Responses/MarketItems.php | 24 +++++++- src/Responses/OffersByTitle.php | 24 +++++++- src/Responses/SyncUserInventory.php | 24 +++++++- src/Responses/TargetsByTitle.php | 45 ++++++++++++++ src/Responses/UserBalance.php | 24 +++++++- src/Responses/UserInventory.php | 24 +++++++- src/Responses/UserItems.php | 24 +++++++- src/Responses/UserOffers.php | 24 +++++++- src/Responses/UserProfile.php | 24 +++++++- src/Responses/UserTargets.php | 24 +++++++- src/Responses/WithdrawAssets.php | 24 +++++++- 55 files changed, 887 insertions(+), 134 deletions(-) create mode 100644 src/Configs/Engine.php create mode 100644 src/Requests/TargetsByTitle.php create mode 100644 src/Responses/TargetsByTitle.php diff --git a/.gitignore b/.gitignore index 943cb85..5669292 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,5 @@ $RECYCLE.BIN/ /example /example/* -composer.lock \ No newline at end of file +composer.lock +index.php \ No newline at end of file diff --git a/README.md b/README.md index 306af03..803334d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ Methods ------------------- ```php +// Used to get detailed response +$api->detailed()->getUserProfile() + // Account $api->getUserProfile(array $proxy = []) $api->getUserBalance(array $proxy = []) @@ -54,6 +57,7 @@ $api->getClosedUserOffers(array $queries = [], array $proxy = []) // Buy items $api->getOffersByTitle(array $queries, array $proxy = []) +$api->getTargetsByTitle(string $gameId, string $title, array $proxy = []) $api->getAggregatedPrices(array $queries, array $proxy = []) $api->getUserTargets(array $queries = [], array $proxy = []) $api->getClosedUserTargets(array $queries = [], array $proxy = []) diff --git a/src/Configs/Engine.php b/src/Configs/Engine.php new file mode 100644 index 0000000..fb6b3ee --- /dev/null +++ b/src/Configs/Engine.php @@ -0,0 +1,83 @@ + "OK", + 201 => "Created", + 202 => "Accepted", + 203 => "Non-Authoritative Information", + 204 => "No Content", + 205 => "Reset Content", + 206 => "Partial Content", + 207 => "Multi-Status (WebDAV)", + 208 => "Already Reported (WebDAV)", + 226 => "IM Used", + + // Redirection 3xx + 300 => "Multiple Choices", + 301 => "Moved Permanently", + 302 => "Found", + 303 => "See Other", + 304 => "Not Modified", + 305 => "Use Proxy", + 306 => "(Unused)", + 307 => "Temporary Redirect", + 308 => "Permanent Redirect", + + // Client Error 4xx + 400 => "Bad Request", + 401 => "Unauthorized", + 402 => "Payment Required", + 403 => "Forbidden", + 404 => "Not Found", + 405 => "Method Not Allowed", + 406 => "Not Acceptable", + 407 => "Proxy Authentication Required", + 408 => "Request Timeout", + 409 => "Conflict", + 410 => "Gone", + 411 => "Length Required", + 412 => "Precondition Failed", + 413 => "Content Too Large", + 414 => "URI Too Long", + 415 => "Unsupported Media Type", + 416 => "Range Not Satisfiable", + 417 => "Expectation Failed", + 418 => "(Unused)", + 420 => "Enhance Your Calm (Twitter)", + 421 => "Misdirected Request", + 422 => "Unprocessable Content", + 423 => "Locked (WebDAV)", + 424 => "Failed Dependency (WebDAV)", + 425 => "Reserved for WebDAV", + 426 => "Upgrade Required", + 428 => "Precondition Required", + 429 => "Too Many Requests", + 431 => "Request Header Fields Too Large", + 444 => "No Response (Nginx)", + 449 => "Retry With (Microsoft)", + 450 => "Blocked by Windows Parental Controls (Microsoft)", + 451 => "Unavailable For Legal Reasons", + 499 => "Client Closed Request (Nginx)", + + // Server Error 5xx + 500 => "Internal Server Error", + 501 => "Not Implemented", + 502 => "Bad Gateway", + 503 => "Service Unavailable", + 504 => "Gateway Timeout", + 505 => "HTTP Version Not Supported", + 506 => "Variant Also Negotiates (Experimental)", + 507 => "Insufficient Storage (WebDAV)", + 508 => "Loop Detected (WebDAV)", + 509 => "Bandwidth Limit Exceeded (Apache)", + 510 => "Not Extended", + 511 => "Network Authentication Required", + 598 => "Network read timeout error", + 599 => "Network connect timeout error" + ]; +} \ No newline at end of file diff --git a/src/DMarketAuthApi.php b/src/DMarketAuthApi.php index e3f0524..a6c11ce 100644 --- a/src/DMarketAuthApi.php +++ b/src/DMarketAuthApi.php @@ -19,6 +19,7 @@ use DMarketAuthApi\Requests\MarketItems; use DMarketAuthApi\Requests\OffersByTitle; use DMarketAuthApi\Requests\SyncUserInventory; +use DMarketAuthApi\Requests\TargetsByTitle; use DMarketAuthApi\Requests\UserBalance; use DMarketAuthApi\Requests\UserInventory; use DMarketAuthApi\Requests\UserItems; @@ -32,12 +33,23 @@ class DMarketAuthApi private string $publicKey; private string $secretKey; + private bool $detailed = false; + public function __construct($publicKey, $secretKey) { $this->publicKey = $publicKey; $this->secretKey = $secretKey; } + /** + * @return $this + */ + public function detailed(): DMarketAuthApi + { + $this->detailed = true; + return $this; + } + // Account /** @@ -47,7 +59,7 @@ public function getUserProfile(array $proxy = []) { $class = new UserProfile(); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -57,7 +69,7 @@ public function getUserBalance(array $proxy = []) { $class = new UserBalance(); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } @@ -70,7 +82,7 @@ public function depositAssets(array $postParams, array $proxy = []) { $class = new DepositAssets(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -80,7 +92,7 @@ public function getDepositStatus(string $depositId, array $proxy = []) { $class = new DepositStatus($depositId); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -90,7 +102,7 @@ public function getUserOffers(array $queries = [], array $proxy = []) { $class = new UserOffers($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -100,7 +112,7 @@ public function createUserOffers(array $postParams, array $proxy = []) { $class = new CreateUserOffers(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -110,7 +122,7 @@ public function editUserOffers(array $postParams, array $proxy = []) { $class = new EditUserOffers(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -120,7 +132,7 @@ public function getMarketItems(array $queries, array $proxy = []) { $class = new MarketItems($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -130,7 +142,7 @@ public function deleteOffers(array $postParams, array $proxy = []) { $class = new DeleteOffers(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } @@ -143,7 +155,7 @@ public function getUserInventory(array $queries = [], array $proxy = []) { $class = new UserInventory($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -153,7 +165,7 @@ public function syncUserInventory(array $postParams, array $proxy = []) { $class = new SyncUserInventory(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -163,7 +175,7 @@ public function withdrawAssets(array $postParams, array $proxy = []) { $class = new WithdrawAssets(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -173,7 +185,7 @@ public function getUserItems(array $queries, array $proxy = []) { $class = new UserItems($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -183,7 +195,7 @@ public function getCustomizedFees(array $queries, array $proxy = []) { $class = new CustomizedFees($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } @@ -197,7 +209,7 @@ public function getClosedUserOffers(array $queries = [], array $proxy = []) { $class = new ClosedUserOffers($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } @@ -211,7 +223,17 @@ public function getOffersByTitle(array $queries, array $proxy = []) { $class = new OffersByTitle($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); + } + + /** + * @throws \SodiumException + */ + public function getTargetsByTitle(string $gameId, string $title, array $proxy = []) + { + $class = new TargetsByTitle($gameId, $title); + + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -221,7 +243,7 @@ public function getAggregatedPrices(array $queries, array $proxy = []) { $class = new AggregatedPrices($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -231,7 +253,7 @@ public function getUserTargets(array $queries = [], array $proxy = []) { $class = new UserTargets($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -241,7 +263,7 @@ public function getClosedUserTargets(array $queries = [], array $proxy = []) { $class = new ClosedUserTargets($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } /** @@ -251,7 +273,7 @@ public function createUserTargets(array $postParams, array $proxy = []) { $class = new CreateUserTargets(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -261,7 +283,7 @@ public function editUserTargets(array $postParams, array $proxy = []) { $class = new EditUserTargets(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } @@ -272,7 +294,7 @@ public function deleteUserTargets(array $postParams, array $proxy = []) { $class = new DeleteUserTargets(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } /** @@ -282,7 +304,7 @@ public function buyOffers(array $postParams, array $proxy = []) { $class = new BuyOffers(); - return $class->call($this->publicKey, $this->secretKey, $postParams, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $postParams, $this->detailed, $proxy)->response(); } @@ -295,6 +317,6 @@ public function getLastSales(array $queries, array $proxy = []) { $class = new LastSales($queries); - return $class->call($this->publicKey, $this->secretKey, $proxy)->response(); + return $class->call($this->publicKey, $this->secretKey, $this->detailed, $proxy)->response(); } } \ No newline at end of file diff --git a/src/Engine/Request.php b/src/Engine/Request.php index a9827eb..856e46d 100644 --- a/src/Engine/Request.php +++ b/src/Engine/Request.php @@ -4,12 +4,13 @@ use Carbon\Carbon; use RuntimeException; +use DMarketAuthApi\Configs\Engine; abstract class Request { const RESPONSE_PREFIX = '\\DMarketAuthApi\\Responses\\'; - private $ch; + private $curl; private $curlOpts = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, @@ -19,26 +20,25 @@ abstract class Request public function initCurl() { - $this->ch = curl_init(); + $this->curl = curl_init(); } /** * @throws \SodiumException */ - public function dmarketHttpRequest($publicKey, $secretKey, $postParams = [], $proxy = []) + public function dmarketHttpRequest($publicKey, $secretKey, $postParams = [], bool $detailed = false, array $proxy = []) { - if (!isset($this->ch)) { + if (!isset($this->curl)) $this->initCurl(); - } $postFields = []; - if (!empty($postParams)) + if ($postParams) $postFields = [ CURLOPT_POSTFIELDS => json_encode($postParams) ]; - curl_setopt_array($this->ch, $this->curlOpts + $proxy + [ + curl_setopt_array($this->curl, $this->curlOpts + $proxy + [ CURLOPT_CUSTOMREQUEST => $this->getRequestMethod(), CURLOPT_URL => $this->getRootUrl() . $this->getUrl(), CURLOPT_HTTPHEADER => [ @@ -47,15 +47,89 @@ public function dmarketHttpRequest($publicKey, $secretKey, $postParams = [], $pr 'X-Sign-Date: ' . Carbon::now()->timestamp, 'Content-Type: ' . 'application/json' ], + CURLOPT_HEADER => $detailed, ] + $postFields ); - return $this->response(curl_exec($this->ch)); + return $this->response($detailed ? self::exec() : curl_exec($this->curl), $detailed); + } + + /** + * @return array + */ + public function exec(): array + { + $response = curl_exec($this->curl); + + $requestHeaders = curl_getinfo($this->curl,CURLINFO_HEADER_OUT); + $headerSize = curl_getinfo($this->curl,CURLINFO_HEADER_SIZE); + $responseHeader = substr($response, 0, $headerSize); + + $code = curl_getinfo($this->curl,CURLINFO_HTTP_CODE) ?: ''; + $messageCode = array_key_exists($code, Engine::HTTP_CODES) ? Engine::HTTP_CODES[$code] : ''; + + return [ + 'request_headers' => self::headersToArray($requestHeaders), + 'response_headers' => self::headersToArray($responseHeader), + 'url' => curl_getinfo($this->curl,CURLINFO_EFFECTIVE_URL), + 'code' => $code, + 'message' => $messageCode, + 'error' => curl_error($this->curl), + 'cookies' => self::getCookie($response), + 'remote_ip' => curl_getinfo($this->curl,CURLINFO_PRIMARY_IP), + 'local_ip' => curl_getinfo($this->curl,CURLINFO_LOCAL_IP), + 'total_time' => bcdiv(curl_getinfo($this->curl,CURLINFO_TOTAL_TIME_T), 1000), + 'response' => substr($response, $headerSize) + ]; + } + + /** + * @param string $header + * @return array + */ + private function headersToArray(string $header): array + { + $headers = []; + $headersTmpArray = explode("\r\n", $header); + + for ($i = 0 ; $i < count( $headersTmpArray ) ; ++$i) { + // we don't care about the two \r\n lines at the end of the headers + if (strlen( $headersTmpArray[$i] ) > 0) { + + // the headers start with HTTP status codes, which do not contain a colon, so we can filter them out too + if (strpos( $headersTmpArray[$i] , ":")) { + $headerName = substr( $headersTmpArray[$i] , 0 , strpos( $headersTmpArray[$i] , ":" ) ); + $headerValue = substr( $headersTmpArray[$i] , strpos( $headersTmpArray[$i] , ":" )+1 ); + $headers[$headerName] = trim($headerValue); + } + } + } + + return $headers; + } + + /** + * @param $response + * @return array + */ + private function getCookie($response): array + { + preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', + $response, $match_found); + + $cookies = []; + + foreach ($match_found[1] as $item) { + parse_str($item, $cookie); + $cookies = array_merge($cookies, $cookie); + } + + return $cookies; } - public function response($data) + public function response($data, bool $detailed = false) { - curl_close($this->ch); + curl_close($this->curl); $class = self::RESPONSE_PREFIX . strrev(explode('\\', strrev(get_called_class()), 2)[0]); @@ -63,7 +137,7 @@ public function response($data) throw new RuntimeException('Call to undefined response type'); } - return new $class($data); + return new $class($data, $detailed); } /** diff --git a/src/Requests/AggregatedPrices.php b/src/Requests/AggregatedPrices.php index bded5cb..8866cf5 100644 --- a/src/Requests/AggregatedPrices.php +++ b/src/Requests/AggregatedPrices.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/BuyOffers.php b/src/Requests/BuyOffers.php index 9fe9480..63271a5 100644 --- a/src/Requests/BuyOffers.php +++ b/src/Requests/BuyOffers.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/ClosedUserOffers.php b/src/Requests/ClosedUserOffers.php index 114faf3..50e6216 100644 --- a/src/Requests/ClosedUserOffers.php +++ b/src/Requests/ClosedUserOffers.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/ClosedUserTargets.php b/src/Requests/ClosedUserTargets.php index aedf2de..ceff1ea 100644 --- a/src/Requests/ClosedUserTargets.php +++ b/src/Requests/ClosedUserTargets.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/CreateUserOffers.php b/src/Requests/CreateUserOffers.php index 8b73e3c..05e892d 100644 --- a/src/Requests/CreateUserOffers.php +++ b/src/Requests/CreateUserOffers.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/CreateUserTargets.php b/src/Requests/CreateUserTargets.php index 02b92b9..d882ddd 100644 --- a/src/Requests/CreateUserTargets.php +++ b/src/Requests/CreateUserTargets.php @@ -21,9 +21,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/CustomizedFees.php b/src/Requests/CustomizedFees.php index 6b9132a..4cbaf04 100644 --- a/src/Requests/CustomizedFees.php +++ b/src/Requests/CustomizedFees.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/DeleteOffers.php b/src/Requests/DeleteOffers.php index 109ac4b..6209885 100644 --- a/src/Requests/DeleteOffers.php +++ b/src/Requests/DeleteOffers.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/DeleteUserTargets.php b/src/Requests/DeleteUserTargets.php index f4d784c..3ed28bb 100644 --- a/src/Requests/DeleteUserTargets.php +++ b/src/Requests/DeleteUserTargets.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/DepositAssets.php b/src/Requests/DepositAssets.php index 0b13264..ccc436b 100644 --- a/src/Requests/DepositAssets.php +++ b/src/Requests/DepositAssets.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/DepositStatus.php b/src/Requests/DepositStatus.php index d142270..84a4301 100644 --- a/src/Requests/DepositStatus.php +++ b/src/Requests/DepositStatus.php @@ -7,7 +7,7 @@ class DepositStatus extends Request implements RequestInterface { - const URL = "/marketplace-api/v1/deposit-status/"; + const URL = "/marketplace-api/v1/deposit-status/%s"; private string $depositId; private string $method = 'GET'; @@ -19,15 +19,15 @@ public function __construct($depositId) public function getUrl(): string { - return self::URL . $this->depositId; + return sprintf(self::URL, $this->depositId); } /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/EditUserOffers.php b/src/Requests/EditUserOffers.php index 4db0d66..3ad2747 100644 --- a/src/Requests/EditUserOffers.php +++ b/src/Requests/EditUserOffers.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/EditUserTargets.php b/src/Requests/EditUserTargets.php index 5e1aa33..2199839 100644 --- a/src/Requests/EditUserTargets.php +++ b/src/Requests/EditUserTargets.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/LastSales.php b/src/Requests/LastSales.php index 7bb2b81..0c628fe 100644 --- a/src/Requests/LastSales.php +++ b/src/Requests/LastSales.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/MarketItems.php b/src/Requests/MarketItems.php index 1314a39..0f2c537 100644 --- a/src/Requests/MarketItems.php +++ b/src/Requests/MarketItems.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/OffersByTitle.php b/src/Requests/OffersByTitle.php index ae530d0..3fd4556 100644 --- a/src/Requests/OffersByTitle.php +++ b/src/Requests/OffersByTitle.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/SyncUserInventory.php b/src/Requests/SyncUserInventory.php index 1ea5486..7e76827 100644 --- a/src/Requests/SyncUserInventory.php +++ b/src/Requests/SyncUserInventory.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/TargetsByTitle.php b/src/Requests/TargetsByTitle.php new file mode 100644 index 0000000..cf6446c --- /dev/null +++ b/src/Requests/TargetsByTitle.php @@ -0,0 +1,44 @@ +gameId = $gameId; + $this->title = $title; + } + + public function getUrl(): string + { + return sprintf(self::URL, $this->gameId, $this->title); + } + + /** + * @throws \SodiumException + */ + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) + { + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); + } + + public function getRequestMethod(): string + { + return $this->method; + } + + public function getRootUrl(): string + { + return "https://api.dmarket.com"; + } +} \ No newline at end of file diff --git a/src/Requests/UserBalance.php b/src/Requests/UserBalance.php index f6685e8..7131a9d 100644 --- a/src/Requests/UserBalance.php +++ b/src/Requests/UserBalance.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/UserInventory.php b/src/Requests/UserInventory.php index b0702b0..399bb0a 100644 --- a/src/Requests/UserInventory.php +++ b/src/Requests/UserInventory.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/UserItems.php b/src/Requests/UserItems.php index 2c930f3..41adbec 100644 --- a/src/Requests/UserItems.php +++ b/src/Requests/UserItems.php @@ -25,9 +25,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/UserOffers.php b/src/Requests/UserOffers.php index d671433..7263b12 100644 --- a/src/Requests/UserOffers.php +++ b/src/Requests/UserOffers.php @@ -27,9 +27,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/UserProfile.php b/src/Requests/UserProfile.php index 799532f..e241ede 100644 --- a/src/Requests/UserProfile.php +++ b/src/Requests/UserProfile.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/UserTargets.php b/src/Requests/UserTargets.php index 2420ef9..182591f 100644 --- a/src/Requests/UserTargets.php +++ b/src/Requests/UserTargets.php @@ -27,9 +27,9 @@ public function getUrl(): string return self::URL . (!empty($this->queryPath) ? '?' . $this->queryPath : ''); } - public function call(string $publicKey, string $secretKey, array $proxy = []) + public function call(string $publicKey, string $secretKey, bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, [], $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, [], $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Requests/WithdrawAssets.php b/src/Requests/WithdrawAssets.php index 324f6b7..ae59364 100644 --- a/src/Requests/WithdrawAssets.php +++ b/src/Requests/WithdrawAssets.php @@ -19,9 +19,9 @@ public function getUrl(): string /** * @throws \SodiumException */ - public function call(string $publicKey, string $secretKey, array $postParams = [], array $proxy = []) + public function call(string $publicKey, string $secretKey, array $postParams = [], bool $detailed = false, array $proxy = []) { - return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $proxy); + return $this->dmarketHttpRequest($publicKey, $secretKey, $postParams, $detailed, $proxy); } public function getRequestMethod(): string diff --git a/src/Responses/AggregatedPrices.php b/src/Responses/AggregatedPrices.php index 81ccccb..c4ac9af 100644 --- a/src/Responses/AggregatedPrices.php +++ b/src/Responses/AggregatedPrices.php @@ -7,9 +7,11 @@ class AggregatedPrices implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/BuyOffers.php b/src/Responses/BuyOffers.php index a566c5a..1f7b39e 100644 --- a/src/Responses/BuyOffers.php +++ b/src/Responses/BuyOffers.php @@ -7,9 +7,11 @@ class BuyOffers implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/ClosedUserOffers.php b/src/Responses/ClosedUserOffers.php index 38e3df0..31a88f6 100644 --- a/src/Responses/ClosedUserOffers.php +++ b/src/Responses/ClosedUserOffers.php @@ -7,9 +7,11 @@ class ClosedUserOffers implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/ClosedUserTargets.php b/src/Responses/ClosedUserTargets.php index 3e723f5..95e5b4c 100644 --- a/src/Responses/ClosedUserTargets.php +++ b/src/Responses/ClosedUserTargets.php @@ -7,9 +7,11 @@ class ClosedUserTargets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/CreateUserOffers.php b/src/Responses/CreateUserOffers.php index 3089ea8..d75fa1c 100644 --- a/src/Responses/CreateUserOffers.php +++ b/src/Responses/CreateUserOffers.php @@ -7,9 +7,11 @@ class CreateUserOffers implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/CreateUserTargets.php b/src/Responses/CreateUserTargets.php index 6698ed9..2b0cc10 100644 --- a/src/Responses/CreateUserTargets.php +++ b/src/Responses/CreateUserTargets.php @@ -7,9 +7,11 @@ class CreateUserTargets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/CustomizedFees.php b/src/Responses/CustomizedFees.php index da14ea5..1fb1045 100644 --- a/src/Responses/CustomizedFees.php +++ b/src/Responses/CustomizedFees.php @@ -7,9 +7,11 @@ class CustomizedFees implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/DeleteOffers.php b/src/Responses/DeleteOffers.php index 6c8f072..280159a 100644 --- a/src/Responses/DeleteOffers.php +++ b/src/Responses/DeleteOffers.php @@ -7,9 +7,11 @@ class DeleteOffers implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/DeleteUserTargets.php b/src/Responses/DeleteUserTargets.php index b56a8f0..b6f691e 100644 --- a/src/Responses/DeleteUserTargets.php +++ b/src/Responses/DeleteUserTargets.php @@ -7,9 +7,11 @@ class DeleteUserTargets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/DepositAssets.php b/src/Responses/DepositAssets.php index 8b8b9d5..355158d 100644 --- a/src/Responses/DepositAssets.php +++ b/src/Responses/DepositAssets.php @@ -7,9 +7,11 @@ class DepositAssets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/DepositStatus.php b/src/Responses/DepositStatus.php index e8cc99c..50282a9 100644 --- a/src/Responses/DepositStatus.php +++ b/src/Responses/DepositStatus.php @@ -7,9 +7,11 @@ class DepositStatus implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/EditUserOffers.php b/src/Responses/EditUserOffers.php index eb400d1..82ebb44 100644 --- a/src/Responses/EditUserOffers.php +++ b/src/Responses/EditUserOffers.php @@ -7,9 +7,11 @@ class EditUserOffers implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/EditUserTargets.php b/src/Responses/EditUserTargets.php index f066c52..7462a24 100644 --- a/src/Responses/EditUserTargets.php +++ b/src/Responses/EditUserTargets.php @@ -7,9 +7,11 @@ class EditUserTargets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/LastSales.php b/src/Responses/LastSales.php index 1ca0b92..f1e1f5b 100644 --- a/src/Responses/LastSales.php +++ b/src/Responses/LastSales.php @@ -7,9 +7,11 @@ class LastSales implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/MarketItems.php b/src/Responses/MarketItems.php index 2fd3767..70f4d20 100644 --- a/src/Responses/MarketItems.php +++ b/src/Responses/MarketItems.php @@ -7,9 +7,11 @@ class MarketItems implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/OffersByTitle.php b/src/Responses/OffersByTitle.php index 7c92f32..70b806d 100644 --- a/src/Responses/OffersByTitle.php +++ b/src/Responses/OffersByTitle.php @@ -7,9 +7,11 @@ class OffersByTitle implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/SyncUserInventory.php b/src/Responses/SyncUserInventory.php index c940a01..2c8e9a8 100644 --- a/src/Responses/SyncUserInventory.php +++ b/src/Responses/SyncUserInventory.php @@ -7,9 +7,11 @@ class SyncUserInventory implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/TargetsByTitle.php b/src/Responses/TargetsByTitle.php new file mode 100644 index 0000000..bdc1f24 --- /dev/null +++ b/src/Responses/TargetsByTitle.php @@ -0,0 +1,45 @@ +detailed = $detailed; + $this->data = $this->decodeResponse($response); + } + + public function response() + { + return $this->data; + } + + private function decodeResponse($response) + { + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } + } +} \ No newline at end of file diff --git a/src/Responses/UserBalance.php b/src/Responses/UserBalance.php index 55f4997..c9a33a2 100644 --- a/src/Responses/UserBalance.php +++ b/src/Responses/UserBalance.php @@ -7,9 +7,11 @@ class UserBalance implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/UserInventory.php b/src/Responses/UserInventory.php index 1bc4f2e..de75c6e 100644 --- a/src/Responses/UserInventory.php +++ b/src/Responses/UserInventory.php @@ -7,9 +7,11 @@ class UserInventory implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/UserItems.php b/src/Responses/UserItems.php index de8bb86..8691262 100644 --- a/src/Responses/UserItems.php +++ b/src/Responses/UserItems.php @@ -7,9 +7,11 @@ class UserItems implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/UserOffers.php b/src/Responses/UserOffers.php index 5d8d2c1..004ebee 100644 --- a/src/Responses/UserOffers.php +++ b/src/Responses/UserOffers.php @@ -7,9 +7,11 @@ class UserOffers implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/UserProfile.php b/src/Responses/UserProfile.php index c31c9fd..90b396c 100644 --- a/src/Responses/UserProfile.php +++ b/src/Responses/UserProfile.php @@ -7,9 +7,11 @@ class UserProfile implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/UserTargets.php b/src/Responses/UserTargets.php index efbdbab..01b4a88 100644 --- a/src/Responses/UserTargets.php +++ b/src/Responses/UserTargets.php @@ -7,9 +7,11 @@ class UserTargets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file diff --git a/src/Responses/WithdrawAssets.php b/src/Responses/WithdrawAssets.php index ddb129b..7d721f2 100644 --- a/src/Responses/WithdrawAssets.php +++ b/src/Responses/WithdrawAssets.php @@ -7,9 +7,11 @@ class WithdrawAssets implements ResponseInterface { private $data; + private $detailed; - public function __construct($response) + public function __construct($response, bool $detailed = false) { + $this->detailed = $detailed; $this->data = $this->decodeResponse($response); } @@ -20,6 +22,24 @@ public function response() private function decodeResponse($response) { - return json_decode($response, true); + $returnData = $response; + + if ($this->detailed) { + $data = json_decode($returnData['response'], true); + + if (!$data) + $returnData['response'] = false; + else + $returnData['response'] = $data; + + return $returnData; + } else { + $data = json_decode($returnData, true); + + if (!$data) + return false; + + return $data; + } } } \ No newline at end of file