update guzzle
Showing
7 changed files
with
209 additions
and
9 deletions
.vscode/launch.json
0 → 100644
| 1 | { | ||
| 2 | // Use IntelliSense to learn about possible attributes. | ||
| 3 | // Hover to view descriptions of existing attributes. | ||
| 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| 5 | "version": "0.2.0", | ||
| 6 | "configurations": [ | ||
| 7 | { | ||
| 8 | "name": "Listen for Xdebug", | ||
| 9 | "type": "php", | ||
| 10 | "request": "launch", | ||
| 11 | "port": 9003 | ||
| 12 | }, | ||
| 13 | { | ||
| 14 | "name": "Launch currently open script", | ||
| 15 | "type": "php", | ||
| 16 | "request": "launch", | ||
| 17 | "program": "${file}", | ||
| 18 | "cwd": "./vendor/bin/phpunit", | ||
| 19 | "port": 0, | ||
| 20 | "runtimeArgs": [ | ||
| 21 | // "-dxdebug.start_with_request=yes", | ||
| 22 | "tests", | ||
| 23 | ], | ||
| 24 | "env": { | ||
| 25 | "XDEBUG_MODE": "debug,develop", | ||
| 26 | "XDEBUG_CONFIG": "client_port=${port}" | ||
| 27 | } | ||
| 28 | }, | ||
| 29 | { | ||
| 30 | "name": "Launch Built-in web server", | ||
| 31 | "type": "php", | ||
| 32 | "request": "launch", | ||
| 33 | "runtimeArgs": [ | ||
| 34 | "-dxdebug.mode=debug", | ||
| 35 | "-dxdebug.start_with_request=yes", | ||
| 36 | "-S", | ||
| 37 | "localhost:0" | ||
| 38 | ], | ||
| 39 | "program": "", | ||
| 40 | "cwd": "${workspaceRoot}", | ||
| 41 | "port": 9003, | ||
| 42 | "serverReadyAction": { | ||
| 43 | "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started", | ||
| 44 | "uriFormat": "http://localhost:%s", | ||
| 45 | "action": "openExternally" | ||
| 46 | } | ||
| 47 | } | ||
| 48 | ] | ||
| 49 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
codeception.yml
0 → 100644
| 1 | namespace: Tests | ||
| 2 | support_namespace: Support | ||
| 3 | # suite config | ||
| 4 | suites: | ||
| 5 | api: | ||
| 6 | actor: ApiTester | ||
| 7 | path: . | ||
| 8 | modules: | ||
| 9 | enabled: | ||
| 10 | - REST: | ||
| 11 | url: http://localhost/api | ||
| 12 | depends: PhpBrowser | ||
| 13 | step_decorators: | ||
| 14 | - \Codeception\Step\AsJson | ||
| 15 | |||
| 16 | paths: | ||
| 17 | tests: tests | ||
| 18 | output: tests/_output | ||
| 19 | data: tests/Support/Data | ||
| 20 | support: tests/Support | ||
| 21 | |||
| 22 | settings: | ||
| 23 | shuffle: false | ||
| 24 | lint: true | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -9,14 +9,17 @@ | ... | @@ -9,14 +9,17 @@ |
| 9 | } | 9 | } |
| 10 | ], | 10 | ], |
| 11 | "require": { | 11 | "require": { |
| 12 | "guzzlehttp/guzzle-services": "^1.1", | 12 | "guzzlehttp/guzzle-services": "^1.3", |
| 13 | "guzzlehttp/oauth-subscriber": "^0.3.0", | 13 | "guzzlehttp/oauth-subscriber": "^0.6.0", |
| 14 | "guzzlehttp/guzzle": "^6.3" | 14 | "guzzlehttp/guzzle": "^7.4" |
| 15 | }, | 15 | }, |
| 16 | "license": "MIT", | 16 | "license": "MIT", |
| 17 | "autoload": { | 17 | "autoload": { |
| 18 | "psr-4": { | 18 | "psr-4": { |
| 19 | "fehrlich\\ImmoScoutAPI\\": "src/" | 19 | "fehrlich\\ImmoScoutAPI\\": "src/" |
| 20 | } | 20 | } |
| 21 | }, | ||
| 22 | "require-dev": { | ||
| 23 | "phpunit/phpunit": "^9.5" | ||
| 21 | } | 24 | } |
| 22 | } | 25 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff could not be displayed because it is too large.
| ... | @@ -127,13 +127,20 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -127,13 +127,20 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 127 | * | 127 | * |
| 128 | * @return static | 128 | * @return static |
| 129 | */ | 129 | */ |
| 130 | public static function createClient($key, $secret, $authorized = true) | 130 | public static function createClient( |
| 131 | { | 131 | $key, |
| 132 | $secret, | ||
| 133 | $authorized = true, | ||
| 134 | callable $commandToRequestTransformer = null, | ||
| 135 | callable $responseToResultTransformer = null, | ||
| 136 | HandlerStack $commandHandlerStack = null, | ||
| 137 | array $config = []) { | ||
| 138 | |||
| 132 | $token = ''; | 139 | $token = ''; |
| 133 | $token_secret = ''; | 140 | $token_secret = ''; |
| 134 | if ($authorized) { | 141 | if ($authorized) { |
| 135 | $tokenArray = static::restoreAccessToken(); | 142 | $tokenArray = static::restoreAccessToken(); |
| 136 | if($tokenArray && is_array($tokenArray)){ | 143 | if ($tokenArray && is_array($tokenArray)) { |
| 137 | $token = $tokenArray[0]; | 144 | $token = $tokenArray[0]; |
| 138 | $token_secret = $tokenArray[1]; | 145 | $token_secret = $tokenArray[1]; |
| 139 | } | 146 | } |
| ... | @@ -156,7 +163,13 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -156,7 +163,13 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 156 | 'auth' => 'oauth', | 163 | 'auth' => 'oauth', |
| 157 | ]); | 164 | ]); |
| 158 | 165 | ||
| 159 | $newGuzzleClient = new static($client, new Description([])); | 166 | $newGuzzleClient = new static( |
| 167 | $client, new Description([]), | ||
| 168 | $commandToRequestTransformer, | ||
| 169 | $responseToResultTransformer, | ||
| 170 | $commandHandlerStack, | ||
| 171 | $config | ||
| 172 | ); | ||
| 160 | $newGuzzleClient->client = $client; | 173 | $newGuzzleClient->client = $client; |
| 161 | $newGuzzleClient->oAuth = $oAuth; | 174 | $newGuzzleClient->oAuth = $oAuth; |
| 162 | $newGuzzleClient->consumerKey = $key; | 175 | $newGuzzleClient->consumerKey = $key; |
| ... | @@ -551,7 +564,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -551,7 +564,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 551 | { | 564 | { |
| 552 | try { | 565 | try { |
| 553 | return json_decode((string) $res->getBody(), true); | 566 | return json_decode((string) $res->getBody(), true); |
| 554 | } catch (\Exception $ex) { | 567 | } catch (\Exception$ex) { |
| 555 | throw new InvalidResponse('invalid json response'); | 568 | throw new InvalidResponse('invalid json response'); |
| 556 | } | 569 | } |
| 557 | } | 570 | } |
| ... | @@ -724,7 +737,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -724,7 +737,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 724 | * | 737 | * |
| 725 | * @param string $reId realestate id used by is24 * | 738 | * @param string $reId realestate id used by is24 * |
| 726 | */ | 739 | */ |
| 727 | public function delete($reId) | 740 | public function deleteRealestate($reId) |
| 728 | { | 741 | { |
| 729 | $res = $this->callUserMethod('realestate/' . $reId, 'DELETE'); | 742 | $res = $this->callUserMethod('realestate/' . $reId, 'DELETE'); |
| 730 | 743 | ... | ... |
tests/APITest.php
0 → 100644
| 1 | <?php | ||
| 2 | |||
| 3 | use fehrlich\ImmoScoutAPI\ImmoScoutAPI; | ||
| 4 | use GuzzleHttp\Client; | ||
| 5 | use GuzzleHttp\Exception\RequestException; | ||
| 6 | use GuzzleHttp\HandlerStack; | ||
| 7 | use GuzzleHttp\Handler\MockHandler; | ||
| 8 | use GuzzleHttp\Middleware; | ||
| 9 | use GuzzleHttp\Psr7\Request; | ||
| 10 | use GuzzleHttp\Psr7\Response; | ||
| 11 | use PHPUnit\Framework\TestCase; | ||
| 12 | |||
| 13 | class TestScoutAPI extends ImmoScoutAPI | ||
| 14 | { | ||
| 15 | public $token; | ||
| 16 | public $secret; | ||
| 17 | protected static $stack = null; | ||
| 18 | |||
| 19 | public static $accessToken; | ||
| 20 | public static $accessSecret; | ||
| 21 | |||
| 22 | public static function setStack($stack) | ||
| 23 | { | ||
| 24 | TestScoutAPI::$stack = $stack; | ||
| 25 | } | ||
| 26 | |||
| 27 | public function saveRequestToken($token, $secret) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | public function restoreRequestToken() | ||
| 31 | { | ||
| 32 | return [ | ||
| 33 | "myToken", | ||
| 34 | "mySecret", | ||
| 35 | ]; | ||
| 36 | } | ||
| 37 | |||
| 38 | public function saveAccessToken($token, $secret) | ||
| 39 | { | ||
| 40 | } | ||
| 41 | public static function restoreAccessToken() | ||
| 42 | { | ||
| 43 | return [ | ||
| 44 | "myAaccessToken", | ||
| 45 | "myAccessSecret", | ||
| 46 | ]; | ||
| 47 | } | ||
| 48 | |||
| 49 | // public static function createClient($key, | ||
| 50 | // $secret, | ||
| 51 | // $authorized = true, | ||
| 52 | // callable $commandToRequestTransformer = null, | ||
| 53 | // callable $responseToResultTransformer = null, | ||
| 54 | // HandlerStack $commandHandlerStack = null, | ||
| 55 | // array $config = []) { | ||
| 56 | // return new Client(['handler' => self::$stack]); | ||
| 57 | // } | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | final class APITest extends TestCase | ||
| 62 | { | ||
| 63 | public function setUp(): void | ||
| 64 | { | ||
| 65 | parent::setUp(); | ||
| 66 | |||
| 67 | $mock = new MockHandler([ | ||
| 68 | new Response(200, ['X-Foo' => 'Bar'], 'Hello, World'), | ||
| 69 | new Response(202, ['Content-Length' => 0]), | ||
| 70 | new RequestException('Error Communicating with Server', new Request('GET', 'test')), | ||
| 71 | ]); | ||
| 72 | |||
| 73 | $handlerStack = HandlerStack::create($mock); | ||
| 74 | $container = []; | ||
| 75 | $history = Middleware::history($container); | ||
| 76 | $handlerStack->push($history); | ||
| 77 | |||
| 78 | $this->client = TestScoutAPI::createClient("myKey", "mySecret"); | ||
| 79 | $this->client->client = new Client([ | ||
| 80 | 'base_uri' => "http://localhost", | ||
| 81 | 'handler' => $handlerStack, | ||
| 82 | 'verify' => false, | ||
| 83 | ]); | ||
| 84 | } | ||
| 85 | |||
| 86 | public function testDefaultDomain() | ||
| 87 | { | ||
| 88 | self::assertEquals($this->client->getDomain(), "sandbox-immobilienscout24.de"); | ||
| 89 | } | ||
| 90 | |||
| 91 | public function testSwichingSandbox() | ||
| 92 | { | ||
| 93 | $this->client->useSandbox(); | ||
| 94 | self::assertEquals($this->client->getDomain(), "sandbox-immobilienscout24.de"); | ||
| 95 | $this->client->dontUseSandbox(); | ||
| 96 | self::assertEquals($this->client->getDomain(), "immobilienscout24.de"); | ||
| 97 | } | ||
| 98 | |||
| 99 | // public function testSetUser() | ||
| 100 | // { | ||
| 101 | // $this->client->setUser("test"); | ||
| 102 | // self::assertEquals($this->client->user, "test"); | ||
| 103 | |||
| 104 | // } | ||
| 105 | // public function testVerifyApplication() | ||
| 106 | // { | ||
| 107 | // $this->client->verifyApplication("myUrl"); | ||
| 108 | // } | ||
| 109 | |||
| 110 | } |
-
Please register or sign in to post a comment