-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d0f64ec
Showing
6 changed files
with
5,045 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Alexander Korelskiy | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# PHP JSON-RPC 2.0 Client example for zenrpc | ||
|
||
PHP JSON-RPC 2.0 Client usage example for [vmkteam/zenrpc](https://github.com/vmkteam/zenrpc). | ||
|
||
--- | ||
RPC client: | ||
- generated by [rpcgen](https://github.com/vmkteam/rpcgen) using public [MyShows](https://myshows.me) API SMD scheme | ||
- included in composer autoloading with `ClassMap loader`: | ||
```json | ||
{ | ||
"classmap": [ | ||
"src/MyShowsRpc/RpcClient.php" | ||
] | ||
} | ||
``` | ||
|
||
|
||
Just check `index.php` for example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "sas1024/php-rpc-client-example", | ||
"description": "Example usage of eazy-jsonrpc with generated rpc client by rpcgen", | ||
"authors": [ | ||
{ | ||
"name": "Alexander Korelskiy", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload":{ | ||
"classmap":[ | ||
"src/MyShowsRpc/RpcClient.php" | ||
], | ||
"psr-4": { | ||
"App\\": "src/App" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=7.2", | ||
"sergeyfast/eazy-jsonrpc": "v3.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use MyShowsRpc\ApiNews; | ||
use MyShowsRpc\RpcClient; | ||
use App\News\NewsManager; | ||
|
||
include_once 'vendor/autoload.php'; | ||
|
||
|
||
$rpcClient = RpcClient::GetInstance( 'https://api.myshows.me/v3/rpc/' ); | ||
$newsManager = new NewsManager( $rpcClient ); | ||
|
||
$title = $newsManager->GetNewsTitleById( 1 ); | ||
echo $title ."\n"; // will be "Russian Doll. Жизни матрешки" | ||
|
||
$title = $newsManager->GetNewsTitleById( -1 ); | ||
echo $title ."\n"; // will be "News with newsId=-1 is not found", because we catch rpc error exception in our manager. | ||
|
||
/** @var ApiNews[] $news */ | ||
$news = $newsManager->GetLastThreeNews(); | ||
foreach ( $news as $item ) { | ||
echo $item->title ."\n"; // will output last 3 news titles. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\News; | ||
|
||
|
||
use EazyJsonRpc\BaseJsonRpcException; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use MyShowsRpc\RpcClient; | ||
|
||
class NewsManager { | ||
|
||
/** | ||
* RpcClient | ||
*/ | ||
private $rpcClient; | ||
|
||
|
||
public function __construct( RpcClient $rpcClient ) { | ||
$this->rpcClient = $rpcClient; | ||
} | ||
|
||
|
||
/** | ||
* @param int $id | ||
* @return string | ||
* @throws GuzzleException | ||
* @throws \JsonMapper_Exception | ||
*/ | ||
public function GetNewsTitleById( int $id ): string { | ||
try { | ||
$news = $this->rpcClient->news_GetById( $id ); | ||
$result = $news->title; | ||
} catch ( BaseJsonRpcException $e ) { | ||
$result = $e->getMessage(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
* @throws BaseJsonRpcException | ||
* @throws GuzzleException | ||
* @throws \JsonMapper_Exception | ||
*/ | ||
public function GetLastThreeNews(): array { | ||
return $this->rpcClient->news_Get(null, null, 3); | ||
} | ||
|
||
} |
Oops, something went wrong.