Skip to content

Commit

Permalink
Merge pull request #24 from notfoundsam/fixes/api-fix
Browse files Browse the repository at this point in the history
Release v1.3.0
  • Loading branch information
notfoundsam authored Aug 29, 2021
2 parents 5d1041d + 3610c4c commit 55e33b0
Show file tree
Hide file tree
Showing 16 changed files with 632 additions and 456 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
*.cache
/composer.lock
/.idea
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ RUN mkdir /.config && chmod 777 /.config
RUN mkdir /.composer && chmod 777 /.composer
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# Xdebug settings
RUN echo "xdebug.mode=develop,debug,trace,profile" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
RUN echo "xdebug.start_with_request=trigger" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
RUN echo "xdebug.profiler_output_name=cachegrind.%t" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
RUN echo "xdebug.output_dir=/app/tests" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"

WORKDIR /app
58 changes: 18 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ use Yahooauc\Browser as Browser;
$userName = "your_yahoo_user";
$userPass = "your_yahoo_pass";
$appId = "your_app_id";
/* Get saved cookie */
$cookie = file_get_contents('cookie.cache');
$cookieJar = $cookie !== false ? unserialize($cookie) : [];
$browser = new Browser($userName, $userPass, $appId, $cookieJar);
$browser = new Browser($userName, $userPass, null, $cookieJar);
```
If you don't have cookies yet try to login into Yahoo.
It throws `LoginException` or `CaptchaException` if something wrong.
Expand Down Expand Up @@ -79,86 +78,65 @@ Replace `test_user` with something else to throw `LoginException`. It means the
```
$userName = "not_test_user";
$userPass = "secret_password";
$appId = "app_id_random_hash";
$browser = new Browser($userName, $userPass, $appId, []);
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
```
Replace `app_id_random_hash` with something else to throw `ApiException`.
Pass something other than the following format `x000000000` to throw `ApiException`. It means the auction ID is invalid.
Pass something in the following format `x000000000` like `x000000001` to throw `ApiException`. It means the auction not found.
```
Pass the following id `n000000000` to throw `PageNotfoundException`. It means the auction not found.
```
$userName = "test_user";
$userPass = "secret_password";
$appId = "not_app_id_random_hash";
$browser = new Browser($userName, $userPass, $appId, []);
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->getAuctionInfoAsXml("xxxxxxx01");
$browser->getAuctionInfoAsXml("x000000001");
$browser->getAuctionInfoAsXml("n000000000");
```
Get an array of fake data from the first bidding page.
```
$userName = "test_user";
$userPass = "secret_password";
$appId = "app_id_random_hash";
$browser = new Browser($userName, $userPass, $appId, []);
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->getBiddingLots(1);
```
Get an array of fake IDs from the first won page.
```
$userName = "test_user";
$userPass = "secret_password";
$appId = "app_id_random_hash";
$browser = new Browser($userName, $userPass, $appId, []);
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->getWonIds(1);
```
Bid on the following lot `e000000000` to throw `BrowserException`. This auction has already ended.
Bid on the following lot `e000000000` to throw `AuctionEndedException`. 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 has rose, and the bid failed.
Bid on the following lot `x000000000` with price more than `999` for a successful bid.
```
$userName = "test_user";
$userPass = "secret_password";
$appId = "app_id_random_hash";
$browser = new Browser($userName, $userPass, $appId, []);
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->bid("e000000000", 1000); // Has already ended
$browser->bid("x000000000", 100); // Not enough
$browser->bid("x000000000", 500); // Rebid page, bid failed
$browser->bid("x000000000", 1000); // Success
```

## About v1.2.x
## About v1.3.x

### Features
- 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.
- Fixed checking login.
- Added xdebug to docker container.

### 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
- Updated the composer.json file
- Other refactoring of a code.
- Yahoo auction API was removed because Yahoo fully closed their API.
- If the page or lot not found it will throw `PageNotfoundException`.

### Notes
- Replaced `rmccue/requests` with `guzzlehttp/guzzle`
- Field `$appId` don't need anymore, pass null instead to the `Browser` constructor.
- Method `$browser->getAuctionInfoAsXml("...")` returns shorted version of API result. Currently, available fields: `Title`, `Seller->Id`, `Img`, `Price`, `TaxinPrice`, `StartTime`, `EndTime`, `Status`.

### Migration from v1.1.x
- You need call `$browser->login()` manually after creating the `Browser` class
- Also, try to learn from code.
### Migration from v1.2.x
- Check available fields for `$browser->getAuctionInfoAsXml("...")` in Notes.
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.3",
"version": "1.3.0",
"license": "MIT",
"require": {
"ext-simplexml": "*",
Expand Down
14 changes: 8 additions & 6 deletions examples/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Yahooauc\Browser as Browser;
use Yahooauc\Exceptions\AuctionEndedException;
use Yahooauc\Exceptions\BrowserException;
use Yahooauc\Exceptions\CaptchaException;
use Yahooauc\Exceptions\LoggedOffException;
use Yahooauc\Exceptions\LoginException;

$userName = "test_user";
$userPass = "secret_password";
$appId = "app_id_random_hash";
$appId = null;

$captchaId = "AgAAAIkBAAABAAAAAAAAAAABA";
$captchaAnswer = "くやひよかとむちひな";
Expand All @@ -25,10 +26,10 @@
$browser->debug(true);

/* Emulate very many attempts to login */
$browser->debugShowCaptcha(true);
// $browser->debugShowCaptcha(true);

/* Emulate too many attempts to login and get ban */
$browser->debugYahooBlocked(true);
// $browser->debugYahooBlocked(true);

/* Check is logged in */
var_dump($browser->checkLogin());
Expand All @@ -41,7 +42,7 @@
// var_dump($browser->loginWithCaptcha($captchaId, $captchaAnswer));

/* Get information about lot */
var_dump($browser->getAuctionInfoAsXml("lotId"));
var_dump($browser->getAuctionInfoAsXml("e000000000"));

/* Get list of lots from first bidding page */
var_dump($browser->getBiddingLots(1));
Expand All @@ -50,7 +51,7 @@
var_dump($browser->getWonIds(1));

/* Bid on lot */
var_dump($browser->bid("lotId", 100));
var_dump($browser->bid("x000000000", 100));

/* Save latest cookie */
$cookieJar = $browser->getCookie();
Expand All @@ -62,6 +63,8 @@
echo trim($e->getMessage())."\n";
} catch (AuctionEndedException $e) {
echo trim($e->getMessage())."\n";
} catch (BrowserException $e) {
echo trim($e->getMessage())."\n";
} catch (CaptchaException $e) {
echo $e->getMessage()."\n";
echo $browser->getCaptchaId()."\n";
Expand All @@ -74,4 +77,3 @@
} catch (Exception $e) {
echo trim($e->getMessage())."\n";
}

80 changes: 80 additions & 0 deletions src/AuctionXml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Yahooauc;

use SimpleXMLElement;

class AuctionXml
{
private $html;
private $xml;

public function __construct($body)
{
$this->html = Parser::getHtmlDom($body);
$this->xml = new SimpleXMLElement('<ResultSet><Result></Result></ResultSet>');

$this->addTitle();
$this->addSellerId();
$this->addImagesUrl();
$this->addPrice();
$this->addDetail();
$this->addStatus();
}

public function setAuctionId($auctionId)
{
$this->xml->Result->AuctionID = $auctionId;
}

public function setAuctionUrl($url)
{
$this->xml->Result->AuctionItemUrl = $url;
}

public function getXml()
{
return $this->xml;
}

private function addTitle()
{
$this->xml->Result->Title = Parser::getAuctionTitle($this->html);
}

private function addSellerId()
{
$this->xml->Result->Seller->Id = Parser::getAuctionSellerId($this->html);
}

public function addImagesUrl()
{
$this->xml->Result->addChild('Img');

foreach (Parser::getAuctionImagesUrl($this->html) as $key => $url) {
$childName = 'Image'.++$key;
$this->xml->Result->Img->$childName = $url;
}
}

public function addPrice()
{
$data = Parser::getAuctionPrice($this->html);

$this->xml->Result->Price = $data['price'];
$this->xml->Result->TaxinPrice = ($data['taxPrice'] > 0) ? $data['taxPrice'] : $data['price'];
}

public function addDetail()
{
$data = Parser::getAuctionDetail($this->html);

$this->xml->Result->StartTime = $data['start'];
$this->xml->Result->EndTime = $data['end'];
}

private function addStatus()
{
$this->xml->Result->Status = Parser::getAuctionStatus($this->html);
}
}
Loading

0 comments on commit 55e33b0

Please sign in to comment.