Skip to content

Commit

Permalink
Merge pull request #20 from notfoundsam/develop
Browse files Browse the repository at this point in the history
Release v1.2.1
  • Loading branch information
notfoundsam authored Aug 2, 2020
2 parents 5acc47d + d9c747d commit e00d2ff
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 35 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand All @@ -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.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"homepage": "https://github.com/notfoundsam"
}
],
"version": "1.2.0",
"version": "1.2.1",
"license": "MIT",
"require": {
"ext-simplexml": "*",
Expand Down
14 changes: 10 additions & 4 deletions examples/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 */
Expand All @@ -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"));
Expand All @@ -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";
Expand Down
47 changes: 25 additions & 22 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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/';
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -240,20 +242,21 @@ 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)
{
$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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions src/Exceptions/AuctionEndedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Yahooauc\Exceptions;

class AuctionEndedException extends \Exception
{
public function __construct()
{
parent::__construct('Auction has ended');
}
}
11 changes: 11 additions & 0 deletions src/Exceptions/LoggedOffException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Yahooauc\Exceptions;

class LoggedOffException extends \Exception
{
public function __construct()
{
parent::__construct('Logged off');
}
}

0 comments on commit e00d2ff

Please sign in to comment.