marmozist / steam-gifts
PHP client for SteamGifts
1.1.0
2020-04-18 12:11 UTC
Requires
- php: ^7.4
- ext-curl: *
- ext-dom: 20031129
- ext-json: ^7.4
- ext-mbstring: ^7.4
- myclabs/php-enum: ^1.7
- php-http/httplug: ^2.1
- php-http/message: ^1.8
- php-http/message-factory: ^1.0
- webmozart/assert: ^1.7
Requires (Dev)
- codeception/verify: ^1.3
- codeclimate/php-test-reporter: ^0.4.4
- jangregor/phpstan-prophecy: ^0.6.2
- kriswallsmith/buzz: ^1.1
- laminas/laminas-diactoros: ^2.2
- php-coveralls/php-coveralls: ^2.2
- php-http/curl-client: ^2.1
- php-http/guzzle6-adapter: ^2.0
- php-http/mock-client: ^1.3
- php-http/vcr-plugin: ^1.0
- phpstan/phpstan: ^0.12.14
- phpstan/phpstan-phpunit: ^0.12.6
- phpstan/phpstan-strict-rules: ^0.12.2
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-11-15 22:09:39 UTC
README
Installation
Installation via Composer:
composer require marmozist/steam-gifts
Usage
Use factory to create client
use Marmozist\SteamGifts\Application\ClientFactory; use Marmozist\SteamGifts\Application\UserProvider\Factory\HttpUserProviderFactory; use Marmozist\SteamGifts\Application\GiveawayProvider\Factory\HttpGiveawayProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\UserProvider\HttpUserProcessor\Factory\CompositeUserProcessorFactory; use Marmozist\SteamGifts\Application\GiveawayProvider\HttpGiveawayProcessor\Factory\CompositeGiveawayProcessorFactory; use Marmozist\SteamGifts\UseCase\GetUser; $userProvider = HttpUserProviderFactory::createProvider( HttpClientType::Curl(), CompositeUserProcessorFactory::createProcessor() ); $giveawayProvider = HttpGiveawayProviderFactory::createProvider( HttpClientType::Curl(), CompositeGiveawayProcessorFactory::createProcessor(new GetUser\Interactor($userProvider)) ); $client = ClientFactory::createClient($userProvider, $giveawayProvider);
You can to implement UserProvider
/GiveawayProvider
interfaces.
UserProvider implementations
HttpUserProvider
HttpUserProvider
implements UserProvider
via HTTPlug.
using via Curl
composer require php-http/curl-client
use Marmozist\SteamGifts\Application\UserProvider\Factory\HttpUserProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\UserProvider\HttpUserProcessor\Factory\CompositeUserProcessorFactory; $userProvider = HttpUserProviderFactory::createProvider( HttpClientType::Curl(), CompositeUserProcessorFactory::createProcessor() );
using via Guzzle
composer require php-http/guzzle6-adapter
use Marmozist\SteamGifts\Application\UserProvider\Factory\HttpUserProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\UserProvider\HttpUserProcessor\Factory\CompositeUserProcessorFactory; $userProvider = HttpUserProviderFactory::createProvider( HttpClientType::Guzzle(), CompositeUserProcessorFactory::createProcessor() );
using via Buzz
composer require kriswallsmith/buzz
use Marmozist\SteamGifts\Application\UserProvider\Factory\HttpUserProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\UserProvider\HttpUserProcessor\Factory\CompositeUserProcessorFactory; $userProvider = HttpUserProviderFactory::createProvider( HttpClientType::Buzz(), CompositeUserProcessorFactory::createProcessor() );
using via your implementation
use Marmozist\SteamGifts\Application\UserProvider\Factory\HttpUserProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\UserProvider\HttpUserProcessor\Factory\CompositeUserProcessorFactory; use Http\Client\HttpClient; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\RequestInterface; /** * @method static self Custom() */ class ExtendedHttpClientType extends HttpClientType { const Custom = 'Custom'; } class CustomHttpClient implements HttpClient { public function sendRequest(RequestInterface $request): ResponseInterface { // your logic of processing request } } class ExtendedHttpUserProviderFactory extends HttpUserProviderFactory { protected static function getClient(HttpClientType $type): HttpClient { if ($type->equals(ExtendedHttpClientType::Custom())) { return new CustomHttpClient(); } return parent::getClient($type); } } $userProvider = ExtendedHttpUserProviderFactory::createProvider( ExtendedHttpClientType::Custom(), CompositeUserProcessorFactory::createProcessor() );
GiveawayProvider implementations
HttpGiveawayProvider
HttpGiveawayProvider
implements GiveawayProvider
via HTTPlug.
using via Curl
composer require php-http/curl-client
use Marmozist\SteamGifts\Application\GiveawayProvider\Factory\HttpGiveawayProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\GiveawayProvider\HttpGiveawayProcessor\Factory\CompositeGiveawayProcessorFactory; use Marmozist\SteamGifts\UseCase\GetUser; $giveawayProvider = HttpGiveawayProviderFactory::createProvider( HttpClientType::Curl(), CompositeGiveawayProcessorFactory::createProcessor(new GetUser\Interactor($userProvider)) );
using via Guzzle
composer require php-http/guzzle6-adapter
use Marmozist\SteamGifts\Application\GiveawayProvider\Factory\HttpGiveawayProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\GiveawayProvider\HttpGiveawayProcessor\Factory\CompositeGiveawayProcessorFactory; use Marmozist\SteamGifts\UseCase\GetUser; $giveawayProvider = HttpGiveawayProviderFactory::createProvider( HttpClientType::Guzzle(), CompositeGiveawayProcessorFactory::createProcessor(new GetUser\Interactor($userProvider)) );
using via Buzz
composer require kriswallsmith/buzz
use Marmozist\SteamGifts\Application\GiveawayProvider\Factory\HttpGiveawayProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\GiveawayProvider\HttpGiveawayProcessor\Factory\CompositeGiveawayProcessorFactory; use Marmozist\SteamGifts\UseCase\GetUser; $giveawayProvider = HttpGiveawayProviderFactory::createProvider( HttpClientType::Buzz(), CompositeGiveawayProcessorFactory::createProcessor(new GetUser\Interactor($userProvider)) );
using via your implementation
use Marmozist\SteamGifts\Application\GiveawayProvider\Factory\HttpGiveawayProviderFactory; use Marmozist\SteamGifts\Application\Utils\Http\HttpClientType; use Marmozist\SteamGifts\Application\GiveawayProvider\HttpGiveawayProcessor\Factory\CompositeGiveawayProcessorFactory; use Http\Client\HttpClient; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\RequestInterface; use Marmozist\SteamGifts\UseCase\GetUser; /** * @method static self Custom() */ class ExtendedHttpClientType extends HttpClientType { const Custom = 'Custom'; } class CustomHttpClient implements HttpClient { public function sendRequest(RequestInterface $request): ResponseInterface { // your logic of processing request } } class ExtendedHttpGiveawayProviderFactory extends HttpGiveawayProviderFactory { protected static function getClient(HttpClientType $type): HttpClient { if ($type->equals(ExtendedHttpClientType::Custom())) { return new CustomHttpClient(); } return parent::getClient($type); } } $giveawayProvider = ExtendedHttpGiveawayProviderFactory::createProvider( ExtendedHttpClientType::Custom(), CompositeGiveawayProcessorFactory::createProcessor(new GetUser\Interactor($userProvider)) );
Client methods
GetUser
e.g. https://www.steamgifts.com/user/Gotman
$user = $client->getUser('Gotman'); if (!$user) { throw new \Exception('User not found'); } echo 'Name: '.$user->getName().PHP_EOL; echo 'Role: '.$user->getRole()->getValue().PHP_EOL; echo 'Last Online: '.$user->getLastOnlineAt()->format('Y-m-d H:i:s').PHP_EOL; echo 'Registered: '.$user->getRegisteredAt()->format('Y-m-d H:i:s').PHP_EOL; echo 'Avatar: '.$user->getAvatarUrl().PHP_EOL; echo 'Steam: '.$user->getSteamLink().PHP_EOL; echo 'Comments: '.$user->getComments().PHP_EOL; echo 'Entered: '.$user->getEnteredGiveaways().PHP_EOL; echo 'Gifts Won: '.$user->getGiftsWon().PHP_EOL; echo 'Gifts Sent: '.$user->getGiftsSent().PHP_EOL; echo 'Contributor Level: '.$user->getContributorLevel().PHP_EOL;
GetUserList
$userList = $client->getUserList(['Gotman', 'Batman']); $user = $userList->findUser('Gotman'); echo 'Entered Giveaways: '.$user->getEnteredGiveaways().PHP_EOL;
GetGiveaway
e.g. https://www.steamgifts.com/giveaway/O8NIm/
$giveaway = $client->getGiveaway('O8NIm'); if (!$giveaway) { throw new \Exception('Giveaway not found'); } echo 'Id: '.$giveaway->getId().PHP_EOL; echo 'Name: '.$giveaway->getName().PHP_EOL; echo 'Creator: '.$giveaway->getCreator()->getName().PHP_EOL; echo 'Created at: '.$giveaway->getCreatedAt()->format('Y-m-d H:i:s').PHP_EOL; echo 'Finished at: '.$giveaway->getFinishedAt()->format('Y-m-d H:i:s').PHP_EOL; echo 'Steam: '.$giveaway->getSteamLink().PHP_EOL; echo 'Cost: '.$giveaway->getCost().PHP_EOL; echo 'Copies: '.$giveaway->getCopies().PHP_EOL; echo 'Level: '.$giveaway->getLevel().PHP_EOL; echo 'Entries: '.$giveaway->getEntries().PHP_EOL; echo 'Comments: '.$giveaway->getComments().PHP_EOL; echo 'Region restricted: '.(int)$giveaway->isRegionRestricted().PHP_EOL; echo 'Group: '.(int)$giveaway->isGroup().PHP_EOL; echo 'Invite only: '.(int)$giveaway->isInviteOnly().PHP_EOL; echo 'Whitelist: '.(int)$giveaway->isWhitelist().PHP_EOL;
GetGiveawayList
$giveawayList = $client->getGiveawayList(['O8NIm', '1BWVk']); $giveaway = $giveawayList->findGiveaway('O8NIm'); echo 'Name: '.$giveaway->getName().PHP_EOL;