mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-15 07:58:40 +00:00
Implement rest getJson
This commit is contained in:
parent
45b22c780a
commit
b6f5e801a8
|
|
@ -463,11 +463,11 @@ final class Request extends RequestAbstract
|
||||||
/**
|
/**
|
||||||
* Perform rest request
|
* Perform rest request
|
||||||
*
|
*
|
||||||
* @return string
|
* @return Response
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function rest() : string
|
public function rest() : Response
|
||||||
{
|
{
|
||||||
return Rest::request($this);
|
return Rest::request($this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,14 @@ final class Response extends ResponseAbstract implements RenderableInterface
|
||||||
return $this->render();
|
return $this->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getJson() : array
|
||||||
|
{
|
||||||
|
return \json_decode($this->render(), true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate response based on header.
|
* Generate response based on header.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,10 @@ class Currency
|
||||||
$request = new Request(new Http('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
|
$request = new Request(new Http('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
|
||||||
$request->setMethod(RequestMethod::GET);
|
$request->setMethod(RequestMethod::GET);
|
||||||
|
|
||||||
$xml = new \SimpleXMLElement(Rest::request($request));
|
$xml = new \SimpleXMLElement(Rest::request($request)->getBody());
|
||||||
|
|
||||||
if (!isset($xml->Cube)) {
|
if (!isset($xml->Cube)) {
|
||||||
throw new \Exception('Invalid xml path');
|
throw new \Exception('Invalid xml path');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$node = $xml->Cube->Cube->Cube;
|
$node = $xml->Cube->Cube->Cube;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class RestTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
"The OMS License 1.0\n\nCopyright (c) <Dennis Eichhorn> All Rights Reserved\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
|
"The OMS License 1.0\n\nCopyright (c) <Dennis Eichhorn> All Rights Reserved\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
|
||||||
Rest::request($request)
|
Rest::request($request)->getBody()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ class RestTest extends \PHPUnit\Framework\TestCase
|
||||||
$request = new Request(new Http('http://httpbin.org/post'));
|
$request = new Request(new Http('http://httpbin.org/post'));
|
||||||
$request->setMethod(RequestMethod::POST);
|
$request->setMethod(RequestMethod::POST);
|
||||||
self::assertTrue($request->setData('pdata', 'abc'));
|
self::assertTrue($request->setData('pdata', 'abc'));
|
||||||
self::assertEquals('abc', \json_decode(REST::request($request), true)['form']['pdata']);
|
self::assertEquals('abc', REST::request($request)->getJson()['form']['pdata']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPut() : void
|
public function testPut() : void
|
||||||
|
|
@ -48,7 +48,7 @@ class RestTest extends \PHPUnit\Framework\TestCase
|
||||||
$request = new Request(new Http('http://httpbin.org/put'));
|
$request = new Request(new Http('http://httpbin.org/put'));
|
||||||
$request->setMethod(RequestMethod::PUT);
|
$request->setMethod(RequestMethod::PUT);
|
||||||
self::assertTrue($request->setData('pdata', 'abc'));
|
self::assertTrue($request->setData('pdata', 'abc'));
|
||||||
self::assertEquals('abc', \json_decode(REST::request($request), true)['form']['pdata']);
|
self::assertEquals('abc', REST::request($request)->getJson()['form']['pdata']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDelete() : void
|
public function testDelete() : void
|
||||||
|
|
@ -56,7 +56,7 @@ class RestTest extends \PHPUnit\Framework\TestCase
|
||||||
$request = new Request(new Http('http://httpbin.org/delete'));
|
$request = new Request(new Http('http://httpbin.org/delete'));
|
||||||
$request->setMethod(RequestMethod::DELETE);
|
$request->setMethod(RequestMethod::DELETE);
|
||||||
self::assertTrue($request->setData('ddata', 'abc'));
|
self::assertTrue($request->setData('ddata', 'abc'));
|
||||||
self::assertEquals('abc', \json_decode(REST::request($request), true)['form']['ddata']);
|
self::assertEquals('abc', REST::request($request)->getJson()['form']['ddata']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGet() : void
|
public function testGet() : void
|
||||||
|
|
@ -64,6 +64,6 @@ class RestTest extends \PHPUnit\Framework\TestCase
|
||||||
$request = new Request(new Http('http://httpbin.org/get'));
|
$request = new Request(new Http('http://httpbin.org/get'));
|
||||||
$request->setMethod(RequestMethod::GET);
|
$request->setMethod(RequestMethod::GET);
|
||||||
self::assertTrue($request->setData('gdata', 'abc'));
|
self::assertTrue($request->setData('gdata', 'abc'));
|
||||||
self::assertEquals('abc', \json_decode(REST::request($request), true)['args']['gdata']);
|
self::assertEquals('abc', REST::request($request)->getJson()['args']['gdata']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user