Skip to content

Commit

Permalink
Added support for connectors/http v7.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Aug 10, 2023
1 parent 84cb58b commit a798224
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 37 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"connectors/http": "^6",
"connectors/http": "^7",
"eloquent/enumeration": "^5|^6",
"phpseclib/phpseclib": "^2",
"psr/log": "^1",
Expand All @@ -22,8 +22,6 @@
"xpaw/steamid": "^2.0"
},
"require-dev": {
"amphp/http-client": "v5.0.0-beta.7",
"amphp/socket": "v2.0.0-beta.9",
"mockery/mockery": "^1.3.3",
"nikic/iter": "^2.2",
"nunomaduro/collision": "^6.3",
Expand Down
9 changes: 6 additions & 3 deletions src/Resource/Curator/CuratorList/DeleteCuratorList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorList;

use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\Form;
use ScriptFUSION\Porter\Connector\DataSource;
use ScriptFUSION\Porter\Net\Http\HttpDataSource;
use ScriptFUSION\Porter\Provider\Resource\SingleRecordResource;
Expand All @@ -24,11 +25,13 @@ public function __construct(CuratorSession $session, int $curatorId, string $lis

protected function getSource(): DataSource
{
$body = new FormBody;
$body->addFields([
$body = new Form;
foreach ([
'listid' => $this->listId,
'sessionid' => $this->session->getStoreSessionCookie()->getValue(),
]);
] as $name => $value) {
$body->addField($name, $value);
}

return (new HttpDataSource(
SteamProvider::buildStoreApiUrl("/curator/$this->curatorId/admin/ajaxdeletelist/")
Expand Down
9 changes: 6 additions & 3 deletions src/Resource/Curator/CuratorList/DeleteCuratorListApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorList;

use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\Form;
use ScriptFUSION\Porter\Connector\DataSource;
use ScriptFUSION\Porter\Net\Http\HttpDataSource;
use ScriptFUSION\Porter\Provider\Resource\SingleRecordResource;
Expand All @@ -24,12 +25,14 @@ public function __construct(

protected function getSource(): DataSource
{
$body = new FormBody;
$body->addFields([
$body = new Form;
foreach ([
'appid' => (string)$this->appId,
'listid' => $this->listId,
'sessionid' => $this->session->getStoreSessionCookie()->getValue(),
]);
] as $name => $value) {
$body->addField($name, $value);
}

return (new HttpDataSource(
SteamProvider::buildStoreApiUrl("/curator/$this->curatorId/admin/ajaxremovefromlist/")
Expand Down
12 changes: 7 additions & 5 deletions src/Resource/Curator/CuratorList/PatchCuratorListAppOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorList;

use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\Form;
use ScriptFUSION\Porter\Connector\DataSource;
use ScriptFUSION\Porter\Net\Http\HttpDataSource;
use ScriptFUSION\Porter\Provider\Resource\SingleRecordResource;
Expand All @@ -24,14 +24,16 @@ public function __construct(

protected function getSource(): DataSource
{
$body = new FormBody;
$body->addFields([
$body = new Form;
foreach ([
'listid' => $this->listId,
'sessionid' => $this->session->getStoreSessionCookie()->getValue(),
]);
] as $name => $value) {
$body->addField($name, $value);
}

foreach ($this->appIds as $appId) {
$body->addField('appids', (string)$appId);
$body->addField('appids[]', (string)$appId);
}

return (new HttpDataSource(
Expand Down
14 changes: 8 additions & 6 deletions src/Resource/Curator/CuratorList/PutCuratorList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorList;

use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\RequestBody;
use Amp\Http\Client\Form;
use Amp\Http\Client\HttpContent;
use ScriptFUSION\Porter\Connector\DataSource;
use ScriptFUSION\Porter\Net\Http\HttpDataSource;
use ScriptFUSION\Porter\Provider\Resource\SingleRecordResource;
Expand Down Expand Up @@ -36,11 +36,11 @@ protected function getSource(): DataSource
;
}

private function toFormBody(CuratorList $list): RequestBody
private function toFormBody(CuratorList $list): HttpContent
{
$body = new FormBody;
$body = new Form;

$body->addFields([
foreach ([
'blurb' => $list->getDescription(),
'listid' => $list->getListId(),
'order' => 'specified',
Expand All @@ -50,7 +50,9 @@ private function toFormBody(CuratorList $list): RequestBody
'title' => $list->getTitle(),
'title_blurb_locs' => '{}',
'type' => '2',
]);
] as $name => $value) {
$body->addField($name, $value);
}

return $body;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Resource/Curator/CuratorList/PutCuratorListApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorList;

use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\Form;
use ScriptFUSION\Porter\Connector\DataSource;
use ScriptFUSION\Porter\Net\Http\HttpDataSource;
use ScriptFUSION\Porter\Provider\Resource\SingleRecordResource;
Expand All @@ -27,12 +28,14 @@ public function __construct(CuratorSession $session, int $curatorId, string $lis

protected function getSource(): DataSource
{
$body = new FormBody;
$body->addFields([
$body = new Form;
foreach ([
'appid' => (string)$this->appId,
'listid' => $this->listId,
'sessionid' => $this->session->getStoreSessionCookie()->getValue(),
]);
] as $name => $value) {
$body->addField($name, $value);
}

return (new HttpDataSource(
SteamProvider::buildStoreApiUrl("/curator/$this->curatorId/admin/ajaxaddtolist/")
Expand Down
10 changes: 6 additions & 4 deletions src/Resource/Curator/PutCuratorReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ScriptFUSION\Porter\Provider\Steam\Resource\Curator;

use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\Form;
use ScriptFUSION\Porter\Connector\DataSource;
use ScriptFUSION\Porter\Net\Http\HttpDataSource;
use ScriptFUSION\Porter\Provider\Resource\SingleRecordResource;
Expand All @@ -25,14 +25,16 @@ public function __construct(CuratorSession $session, int $curatorId, CuratorRevi

protected function getSource(): DataSource
{
$body = new FormBody;
$body->addFields([
$body = new Form;
foreach ([
'appid' => (string)$this->review->getAppId(),
'blurb' => $this->review->getBody(),
'link_url' => $this->review->getUrl(),
'recommendation_state' => (string)$this->review->getRecommendationState()->toInt(),
'sessionid' => $this->session->getStoreSessionCookie()->getValue(),
]);
] as $name => $value) {
$body->addField($name, $value);
}

return (new HttpDataSource(
SteamProvider::buildStoreApiUrl("/curator/$this->curatorId/admin/ajaxcreatereview/")
Expand Down
18 changes: 9 additions & 9 deletions src/Resource/SteamLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ScriptFUSION\Porter\Provider\Steam\Resource;

use Amp\DeferredFuture;
use Amp\Http\Client\Body\FormBody;
use Amp\Http\Client\Form;
use phpseclib\Crypt\RSA;
use phpseclib\Math\BigInteger;
use ScriptFUSION\Porter\Connector\ImportConnector;
Expand Down Expand Up @@ -79,12 +79,10 @@ private function login(ImportConnector $connector): array
'e' => new BigInteger($json['response']['publickey_exp'], 16),
]);

$body = new FormBody();
$body->addFields([
'account_name' => $this->username,
'encrypted_password' => base64_encode($rsa->encrypt($this->password)),
'encryption_timestamp' => $json['response']['timestamp'],
]);
$body = new Form();
$body->addField('account_name', $this->username);
$body->addField('encrypted_password', base64_encode($rsa->encrypt($this->password)));
$body->addField('encryption_timestamp', $json['response']['timestamp']);

$json = json_decode(
(string)$response = $connector->fetch(
Expand All @@ -102,8 +100,10 @@ private function login(ImportConnector $connector): array
}
$sessionParams = $json['response'];

$body = new FormBody();
$body->addFields(array_intersect_key($sessionParams, ['client_id' => 1, 'request_id' => 1]));
$body = new Form();
foreach (['client_id', 'request_id'] as $field) {
$body->addField($field, $sessionParams[$field]);
}

$json = json_decode(
(string)$response = $connector->fetch(
Expand Down
2 changes: 1 addition & 1 deletion test/MockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function mockConnectorResponse(Connector|MockInterface $connector,
{
$connector->expects('fetch')->andReturn(new HttpResponse(new Response(
'1.0',
2,
200,
null,
[],
new ReadableBuffer($response),
Expand Down

0 comments on commit a798224

Please sign in to comment.