Skip to content

Commit

Permalink
Merge pull request #21 from notfoundsam/develop
Browse files Browse the repository at this point in the history
Release v1.2.2
  • Loading branch information
notfoundsam authored Aug 13, 2020
2 parents e00d2ff + 3025eb3 commit 1e660d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ $browser->bid("x000000000", 500); // Rebid page, bid failed
$browser->bid("x000000000", 1000); // Success
```

## About v1.2.1
## About v1.2.x

### Features
- Detect a page with a captcha. If you send a lot of requests to login.
Expand All @@ -148,10 +148,12 @@ $browser->bid("x000000000", 1000); // Success

### Bugfixes
- Fixed Yahoo login.
- Fixed checking login.

### Updates
- 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
- The `ParserException` won't throw anymore, instead `BrowserException` will be thrown
- Updated the composer.json file
- Other refactoring of a code.

### Notes
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"homepage": "https://github.com/notfoundsam"
}
],
"version": "1.2.1",
"version": "1.2.2",
"license": "MIT",
"require": {
"ext-simplexml": "*",
"php": ">=5.4.0",
"php": ">=5.6.0",
"kub-at/php-simple-html-dom-parser": "^1.9",
"guzzlehttp/guzzle": "^7.0"
"guzzlehttp/guzzle": "^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 8 additions & 7 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function getCookie()
* @param string $auc_id Auction ID
* @return SimpleXMLElement Return XML Object
* @throws ApiException Throw exception if auction id is invalid or not found etc.
* @throws \GuzzleHttp\Exception\GuzzleException
*
*/
public function getAuctionInfoAsXml($auc_id)
Expand Down Expand Up @@ -166,6 +167,7 @@ public function getAuctionInfoAsXml($auc_id)
* @param string $auc_id Auction ID
* @return array Return array with images url from stored auctionInfo
* @throws ApiException Throw exception if has API error
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getAuctionImgsUrl($auc_id = null)
{
Expand Down Expand Up @@ -201,6 +203,7 @@ public function getStoredAuctionInfoAsXml()
* @param int $page Number of page with won lots
* @return array Return array with only won auction IDs
* @throws LoggedOffException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getWonIds($page = 1)
{
Expand All @@ -223,6 +226,7 @@ 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 LoggedOffException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getBiddingLots($page = 1)
{
Expand Down Expand Up @@ -295,7 +299,7 @@ public function bid($auc_id, $price = 0)
* @return bool Return true if success
* @throws LoginException
* @throws CaptchaException
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function login()
{
Expand Down Expand Up @@ -331,16 +335,13 @@ public function login()
}

if ($this->isCaptchaRequired($body)) {
file_put_contents('captcha.html', $body);
throw new CaptchaException;
}

if (strpos($body, 'In order to prevent unauthorized access, your access to Yahoo! JAPAN has been restricted.') !== false) {
throw new LoginException('Yahoo blocked your account for a while');
}

file_put_contents('login_fail.html', $body);

throw new LoginException('Unexpected behavior');
}

Expand All @@ -353,14 +354,14 @@ public function login()
* @return bool Return true if success
* @throws LoginException
* @throws ParserException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function loginWithCaptcha($captchaId, $captchaAnswer)
{
$this->loginWithCaptcha = true;
$options = $this->createCaptchaOptions($captchaId, $captchaAnswer);
$body = $this->getBody(static::$LOGIN_URL, $options, 'POST');

file_put_contents('001.html', $body);
if (!$ak = $this->getAlbatrossKey($body)) {
throw new LoginException('Albatross key not found after captcha');
}
Expand All @@ -373,7 +374,6 @@ public function loginWithCaptcha($captchaId, $captchaAnswer)
if (!$this->debug) sleep(3);

$body = $this->getBody(static::$LOGIN_URL, $options, 'POST');
file_put_contents('002.html', $body);

if ($this->checkLogin($body)) {
return true;
Expand All @@ -385,6 +385,7 @@ public function loginWithCaptcha($captchaId, $captchaAnswer)
/**
* @param string $body Body of the document
* @return bool Return true if logged in
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function checkLogin(&$body = null)
{
Expand Down Expand Up @@ -509,7 +510,7 @@ private function createCaptchaOptions($captchaId, $captchaAnswer)
* @param array $options Query parameters if method is GET or data values if method is POST
* @param string $method Request method
* @return string Return body of HTML
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getBody($url, $options = [], $method = 'GET')
{
Expand Down
12 changes: 2 additions & 10 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,9 @@ class Parser
*/
public static function checkLogin(&$body, &$userName)
{
$html = static::getHtmlDom($body);

if ($p_result = $html->find('div[class=yjmthloginarea]', 0))
{
if ($userName == trim($p_result->find('strong', 0)->innertext))
{
return true;
}
}
preg_match('/ようこそ、.+('.$userName.').+さん/', $body, $matches);

return false;
return isset($matches[1]) && $matches[1] === $userName;
}

/**
Expand Down

0 comments on commit 1e660d4

Please sign in to comment.