From d9c747d00d45e7c1d3c58bfae9d93b572722b50f Mon Sep 17 00:00:00 2001 From: notfoundsam Date: Sun, 2 Aug 2020 10:22:10 +0900 Subject: [PATCH] Release v1.2.1 --- README.md | 25 +++++++++---- composer.json | 2 +- examples/main.php | 14 +++++-- src/Browser.php | 47 +++++++++++++----------- src/Exceptions/AuctionEndedException.php | 11 ++++++ src/Exceptions/LoggedOffException.php | 11 ++++++ 6 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 src/Exceptions/AuctionEndedException.php create mode 100644 src/Exceptions/LoggedOffException.php diff --git a/README.md b/README.md index d765c55..f552894 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ $cookieJar = $cookie !== false ? unserialize($cookie) : []; $browser = new Browser($userName, $userPass, $appId, $cookieJar); ``` If you don't have cookies yet try to login into Yahoo. -It trows `LoginException` or `CaptchaException` if something wrong. +It throws `LoginException` or `CaptchaException` if something wrong. ``` /* Try to login into Yahoo */ var_dump($browser->login()); @@ -75,7 +75,7 @@ $browser->debug($debug = true); $browser->debug($debug = true, $testPath = 'your_folder_with_test_pages'); ``` ### How to use the debugging mode -Replace `test_user` with something else to throw `BrowserLoginException`. It means the login failed. +Replace `test_user` with something else to throw `LoginException`. It means the login failed. ``` $userName = "not_test_user"; $userPass = "secret_password"; @@ -117,9 +117,9 @@ $browser = new Browser($userName, $userPass, $appId, []); $browser->debug($debug = true); $browser->getWonIds(1); ``` -Bid on the following lot `e000000000` to throw `BrowserException`. This auction has alredy ended. +Bid on the following lot `e000000000` to throw `BrowserException`. This auction has already ended. Bid on the following lot `x000000000` with price under `220` to throw `BrowserException`. It means your price is lower than the current price. -Bid on the following lot `x000000000` with price between `220` and `999` to throw `RebidException`. It means the price of the lot rose higher and the bid failed. +Bid on the following lot `x000000000` with price between `220` and `999` to throw `RebidException`. It means the price of the lot has rose, and the bid failed. Bid on the following lot `x000000000` with price more than `999` for a successful bid. ``` $userName = "test_user"; @@ -134,20 +134,29 @@ $browser->bid("x000000000", 500); // Rebid page, bid failed $browser->bid("x000000000", 1000); // Success ``` -## About v1.1.0 +## About v1.2.1 ### Features -- Added the debugging mode. +- Detect a page with a captcha. If you send a lot of requests to login. +- Detect a page with ban. If you send too many requests to login. +- Added method to check login. `checkLogin()` +- The `getBiddingLots()` method and `getWonIds()` now throw `LoggedOffException` +- The `login()` method throws `LoginException` and `CaptchaException` +- The `bid($auc_id, $price)` method now throws `ApiException`, `BrowserException`, `RebidException`, `AuctionEndedException` +- You can emulate very many attempts to login in debugging mode. +- You can emulate too many attempts to login and get ban in debugging mode. ### Bugfixes - Fixed Yahoo login. ### Updates -- Refactoring of code. +- Login to Yahoo has moved to a separated method from the constructor of the class. +- The `ParserException` won't throw anymore, instead `BrowserException` will be thrown +- Other refactoring of a code. ### Notes - Replaced `rmccue/requests` with `guzzlehttp/guzzle` ### Migration from v1.1.x - You need call `$browser->login()` manually after creating the `Browser` class - +- Also, try to learn from code. diff --git a/composer.json b/composer.json index 5cfaf48..e0defc6 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "homepage": "https://github.com/notfoundsam" } ], - "version": "1.2.0", + "version": "1.2.1", "license": "MIT", "require": { "ext-simplexml": "*", diff --git a/examples/main.php b/examples/main.php index 0470d82..fe6e119 100644 --- a/examples/main.php +++ b/examples/main.php @@ -3,7 +3,9 @@ require __DIR__ . '/../vendor/autoload.php'; use Yahooauc\Browser as Browser; +use Yahooauc\Exceptions\AuctionEndedException; use Yahooauc\Exceptions\CaptchaException; +use Yahooauc\Exceptions\LoggedOffException; use Yahooauc\Exceptions\LoginException; $userName = "test_user"; @@ -20,12 +22,12 @@ $browser = new Browser($userName, $userPass, $appId, $cookieJar); /* Set the debug mode */ -// $browser->debug(true); +$browser->debug(true); -/* Emulate very much attempts to login */ +/* Emulate very many attempts to login */ $browser->debugShowCaptcha(true); -/* Emulate too much attempts to login and get ban */ +/* Emulate too many attempts to login and get ban */ $browser->debugYahooBlocked(true); /* Check is logged in */ @@ -36,7 +38,7 @@ var_dump($browser->login()); /* Try to login into Yahoo (Doesn't support yet) */ - var_dump($browser->loginWithCaptcha($captchaId, $captchaAnswer)); + // var_dump($browser->loginWithCaptcha($captchaId, $captchaAnswer)); /* Get information about lot */ var_dump($browser->getAuctionInfoAsXml("lotId")); @@ -56,6 +58,10 @@ file_put_contents('cookie.cache', $cookie); } catch (LoginException $e) { echo trim($e->getMessage())."\n"; +} catch (LoggedOffException $e) { + echo trim($e->getMessage())."\n"; +} catch (AuctionEndedException $e) { + echo trim($e->getMessage())."\n"; } catch (CaptchaException $e) { echo $e->getMessage()."\n"; echo $browser->getCaptchaId()."\n"; diff --git a/src/Browser.php b/src/Browser.php index 1a41c61..ed26f07 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -7,6 +7,8 @@ use SimpleXMLElement; use Yahooauc\Exceptions\ApiException; use Yahooauc\Exceptions\CaptchaException; +use Yahooauc\Exceptions\AuctionEndedException; +use Yahooauc\Exceptions\LoggedOffException; use Yahooauc\Exceptions\LoginException; use Yahooauc\Exceptions\BrowserException; use Yahooauc\Exceptions\ParserException; @@ -31,14 +33,14 @@ class Browser private $requestOptions; private $client; - private $auctionInfo = null; - private $captchaId = null; - private $loginWithCaptcha = false; + private $auctionInfo = null; + private $captchaId = null; + private $loginWithCaptcha = false; - private $debug = false; - private $debugShowCaptcha = false; - private $debugYahooBlocked = false; - private $testsPath = null; + private $debug = false; + private $debugShowCaptcha = false; + private $debugYahooBlocked = false; + private $testsPath = null; private static $AUCTION_URL = 'http://auctions.yahoo.co.jp/'; private static $LOGIN_CHECK_URL = 'https://auctions.yahoo.co.jp/'; @@ -198,11 +200,11 @@ public function getStoredAuctionInfoAsXml() * * @param int $page Number of page with won lots * @return array Return array with only won auction IDs - * @throws BrowserException + * @throws LoggedOffException */ public function getWonIds($page = 1) { - if (!$this->checkLogin()) throw new BrowserException('Logged off'); + if (!$this->checkLogin()) throw new LoggedOffException; $query = [ 'select' => 'won', @@ -220,11 +222,11 @@ public function getWonIds($page = 1) * * @param int $page Number of bidding page * @return array Return array with lot information and bidding pages if they exist - * @throws BrowserException + * @throws LoggedOffException */ public function getBiddingLots($page = 1) { - if (!$this->checkLogin()) throw new BrowserException('Logged off'); + if (!$this->checkLogin()) throw new LoggedOffException; $query = [ 'select' => 'bidding', @@ -240,12 +242,13 @@ public function getBiddingLots($page = 1) /** * Bid on yahoo lot * - * @param string $auc_id auction ID - * @param int $price Price to bid - * @return bool Return true if bid was successful - * @throws ApiException Throw exception if has API error - * @throws BrowserException Throw exception if something wrong - * @throws RebidException Throw exception if price of bid under then current price + * @param string $auc_id auction ID + * @param int $price Price to bid + * @return bool Return true if bid was successful + * @throws ApiException Throw exception if has API error + * @throws BrowserException Throw exception if something wrong + * @throws RebidException Throw exception if price of bid under then current price + * @throws AuctionEndedException Throw exception if auction has already closed * */ public function bid($auc_id, $price = 0) @@ -253,7 +256,7 @@ public function bid($auc_id, $price = 0) $info = $this->getAuctionInfoAsXml($auc_id); if ( (string) $info->Result->Status != 'open' ) { - throw new BrowserException('Auction has ended', 10); + throw new AuctionEndedException; } $auc_url = (string) $info->Result->AuctionItemUrl; @@ -262,7 +265,7 @@ public function bid($auc_id, $price = 0) try { $inputs = Parser::getHiddenInputs($body); } catch (ParserException $e) { - throw new BrowserException($e->getMessage()); + throw new BrowserException($e->getMessage(), $e->getCode()); } $options = $this->createBidRequestOptions($inputs, $price); @@ -271,7 +274,7 @@ public function bid($auc_id, $price = 0) try { $inputs = Parser::getHiddenInputs($body); } catch (ParserException $e) { - throw new BrowserException($e->getMessage()); + throw new BrowserException($e->getMessage(), $e->getCode()); } $options = $this->createBidRequestOptions($inputs, $price); @@ -280,7 +283,7 @@ public function bid($auc_id, $price = 0) try { $result = Parser::getResult($body); } catch (ParserException $e) { - throw new BrowserException($e->getMessage()); + throw new BrowserException($e->getMessage(), $e->getCode()); } return $result; @@ -314,7 +317,7 @@ public function login() try { $inputs = Parser::getHiddenInputs($body); } catch (ParserException $e) { - throw new LoginException($e->getMessage()); + throw new LoginException($e->getMessage(), $e->getCode()); } $options = $this->createLoginOptions($inputs, $ak); diff --git a/src/Exceptions/AuctionEndedException.php b/src/Exceptions/AuctionEndedException.php new file mode 100644 index 0000000..726d7ba --- /dev/null +++ b/src/Exceptions/AuctionEndedException.php @@ -0,0 +1,11 @@ +