Skip to content

Commit

Permalink
Rewrite with openapi-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
moririnson committed May 1, 2023
1 parent 698db59 commit de798e5
Show file tree
Hide file tree
Showing 915 changed files with 217,537 additions and 21,542 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ vendor/
/.phpdoc/
phpDocumentor.phar
.phpunit.result.cache

## Generated by OpenAPI
src/clients/channel-access-token/*
!src/clients/channel-access-token/lib/
!src/clients/channel-access-token/test/
src/clients/insight/*
!src/clients/insight/lib/
!src/clients/insight/test/
src/clients/liff/*
!src/clients/liff/lib/
!src/clients/liff/test/
src/clients/manage-audience/*
!src/clients/manage-audience/lib/
!src/clients/manage-audience/test/
src/clients/messaging-api/*
!src/clients/messaging-api/lib/
!src/clients/messaging-api/test/
src/webhook/*
!src/webhook/lib/
!src/webhook/test/
31 changes: 0 additions & 31 deletions Makefile

This file was deleted.

7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ See the official API documentation for more information.

## Requirements

- PHP 7.2 or later
- PHP 8.1 or later


## Installation
Expand Down Expand Up @@ -188,11 +188,6 @@ Please refer [CurlHTTPClient](/src/LINEBot/HTTPClient/CurlHTTPClient.php) that i
See also
--

### [line-bot-sdk-tiny](./line-bot-sdk-tiny)

A very simple SDK (subset) for the LINE Messaging API for PHP.
line-bot-sdk-tiny provides a simple interface and functions which makes it a good way to learn how to use the LINE Messaging API.

### Laravel Support
Easy to use from Laravel.
After installed, add `LINE_BOT_CHANNEL_ACCESS_TOKEN` and `LINE_BOT_CHANNEL_SECRET` to `.env`
Expand Down
30 changes: 23 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
}
],
"require": {
"php": ">=7.2",
"ext-curl": "*",
"ext-json": "*",
"ext-sockets": "*"
"php": ">=8.1",
"guzzlehttp/guzzle": "^7.3",
"guzzlehttp/psr7": "^1.7 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7||^8||^9",
Expand All @@ -46,12 +45,25 @@
},
"autoload": {
"psr-4": {
"LINE\\": "src/"
"LINE\\Clients\\ChannelAccessToken\\": "src/clients/channel-access-token/lib/",
"LINE\\Clients\\Insight\\": "src/clients/insight/lib/",
"LINE\\Clients\\Liff\\": "src/clients/liff/lib/",
"LINE\\Clients\\ManageAudience\\": "src/clients/manage-audience/lib/",
"LINE\\Clients\\MessagingApi\\": "src/clients/messaging-api/lib/",
"LINE\\Constants\\": "src/constants/",
"LINE\\Laravel\\": "src/laravel/lib/",
"LINE\\Parser\\": "src/parser/lib/",
"LINE\\Webhook\\": "src/webhook/lib/"
}
},
"autoload-dev": {
"psr-4": {
"LINE\\Tests\\": "tests/"
"LINE\\Clients\\ChannelAccessToken\\Tests\\": "src/clients/channel-access-token/tests/",
"LINE\\Clients\\Insight\\Tests\\": "src/clients/insight/tests/",
"LINE\\Clients\\Liff\\Tests\\": "src/clients/liff/tests/",
"LINE\\Clients\\ManageAudience\\Tests\\": "src/clients/manage-audience/tests/",
"LINE\\Parser\\Tests\\": "src/parser/tests/",
"LINE\\Webhook\\Tests\\": "src/webhook/tests/"
}
},
"scripts": {
Expand All @@ -66,7 +78,11 @@
"LINE\\Laravel\\LINEBotServiceProvider"
],
"aliases": {
"LINEBot": "LINE\\Laravel\\Facade\\LINEBot"
"LINEChannelAccessTokenApi": "LINE\\Laravel\\Facade\\LINEChannelAccessTokenApi",
"LINEInsightApi": "LINE\\Laravel\\Facade\\LINEInsightApi",
"LINELiffApi": "LINE\\Laravel\\Facade\\LINELiffApi",
"LINEManageAudienceApi": "LINE\\Laravel\\Facade\\LINEManageAudienceApi",
"LINEMessagingApi": "LINE\\Laravel\\Facade\\LINEMessagingApi"
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions examples/EchoBot/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@
{
"name": "moznion",
"email": "[email protected]",
"role": "Retired"
"role": "Retired"
},
{
"name": "Satoru Yoshihara",
"email": "[email protected]",
"role": "Maintainer"
"role": "Retired"
},
{
"name": "Satoshi Shibuya",
"email": "[email protected]",
"role": "Maintainer"
"role": "Maintainer"
}
],
"require": {
"php": ">=5.6",
"slim/slim": "^4.0.0",
"php": ">=8.1",
"slim/slim": "^4.11",
"slim/psr7": "^1.6",
"slim/http": "^1.3",
"monolog/monolog": "^3.0.0",
"linecorp/line-bot-sdk": "1.6.0"
"guzzlehttp/guzzle": "^7.5",
"guzzlehttp/psr7": "^2.5",
"php-di/slim-bridge": "^3.3"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 7 additions & 0 deletions examples/EchoBot/openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.5.0"
}
}
6 changes: 3 additions & 3 deletions examples/EchoBot/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

require_once __DIR__ . '/../vendor/autoload.php';

$setting = Setting::getSetting();
$app = new Slim\App($setting);
$container = new \DI\Container();
(new Dependency())->register($container);

(new Dependency())->register($app);
$app = \Slim\Factory\AppFactory::createFromContainer($container);
(new Route())->register($app);

$app->run();
33 changes: 18 additions & 15 deletions examples/EchoBot/src/LINEBot/EchoBot/Dependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,36 @@

namespace LINE\LINEBot\EchoBot;

use LINE\LINEBot;
use LINE\LINEBot\HTTPClient\CurlHTTPClient;
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
use LINE\Clients\MessagingApi\Configuration;

class Dependency
{
public function register(\Slim\App $app)
public function register(\DI\Container $container)
{
$container = $app->getContainer();
$container->set('settings', function ($c) {
return Setting::getSetting()['settings'];
});

$container['logger'] = function ($c) {
$container->set(\Psr\Log\LoggerInterface::class, function ($c) {
$settings = $c->get('settings')['logger'];
$logger = new \Monolog\Logger($settings['name']);
$logger->pushProcessor(new \Monolog\Processor\UidProcessor());
$logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['path'], \Monolog\Logger::DEBUG));
$logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Level::Debug));
$logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['path'], \Monolog\Level::Debug));
return $logger;
};
});

$container['bot'] = function ($c) {
$container->set('botMessagingApi', function ($c) {
$settings = $c->get('settings');
$channelSecret = $settings['bot']['channelSecret'];
$channelToken = $settings['bot']['channelToken'];
$apiEndpointBase = $settings['apiEndpointBase'];
$bot = new LINEBot(new CurlHTTPClient($channelToken), [
'channelSecret' => $channelSecret,
'endpointBase' => $apiEndpointBase, // <= Normally, you can omit this
]);
$config = new Configuration();
$config->setAccessToken($channelToken);
$bot = new MessagingApiApi(
client: new \GuzzleHttp\Client(),
config: $config,
);
return $bot;
};
});
}
}
40 changes: 24 additions & 16 deletions examples/EchoBot/src/LINEBot/EchoBot/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@

namespace LINE\LINEBot\EchoBot;

use LINE\LINEBot\Constant\HTTPHeader;
use LINE\LINEBot\Event\MessageEvent;
use LINE\LINEBot\Event\MessageEvent\TextMessage;
use LINE\LINEBot\Exception\InvalidEventRequestException;
use LINE\LINEBot\Exception\InvalidSignatureException;
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
use LINE\Clients\MessagingApi\Model\TextMessage;
use LINE\Constants\HTTPHeader;
use LINE\Parser\EventRequestParser;
use LINE\Webhook\Model\MessageEvent;
use LINE\Parser\Exception\InvalidEventRequestException;
use LINE\Parser\Exception\InvalidSignatureException;
use LINE\Webhook\Model\TextMessageContent;

class Route
{
public function register(\Slim\App $app)
{
$app->post('/callback', function (\Slim\Http\Request $req, \Slim\Http\Response $res) {
/** @var \LINE\LINEBot $bot */
$bot = $this->bot;
/** @var \Monolog\Logger $logger */
$logger = $this->logger;
$app->post('/callback', function (\Psr\Http\Message\RequestInterface $req, \Psr\Http\Message\ResponseInterface $res) {
/** @var \LINE\Clients\MessagingApi\Api\MessagingApiApi $bot */
$bot = $this->get('botMessagingApi');
$logger = $this->get(\Psr\Log\LoggerInterface::class);

$signature = $req->getHeader(HTTPHeader::LINE_SIGNATURE);
if (empty($signature)) {
Expand All @@ -41,7 +43,8 @@ public function register(\Slim\App $app)

// Check request with signature and parse request
try {
$events = $bot->parseEventRequest($req->getBody(), $signature[0]);
$secret = $this->get('settings')['bot']['channelSecret'];
$events = EventRequestParser::parseEventRequest($req->getBody(), $secret, $signature[0]);
} catch (InvalidSignatureException $e) {
return $res->withStatus(400, 'Invalid signature');
} catch (InvalidEventRequestException $e) {
Expand All @@ -54,18 +57,23 @@ public function register(\Slim\App $app)
continue;
}

if (!($event instanceof TextMessage)) {
$message = $event->getMessage();
if (!($message instanceof TextMessageContent)) {
$logger->info('Non text message has come');
continue;
}

$replyText = $event->getText();
$replyText = $message->getText();
$logger->info('Reply text: ' . $replyText);
$resp = $bot->replyText($event->getReplyToken(), $replyText);
$logger->info($resp->getHTTPStatus() . ': ' . $resp->getRawBody());
$bot->replyMessage(new ReplyMessageRequest([
'replyToken' => $event->getReplyToken(),
'messages' => [
(new TextMessage(['text' => $replyText]))->setType('text'),
],
]));
}

$res->write('OK');
$res->withStatus(200, 'OK');
return $res;
});
}
Expand Down
23 changes: 23 additions & 0 deletions examples/KitchenSink/.github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches:
- main

name: deploy

jobs:
devflow:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: context
uses: okteto/context@latest
with:
token: ${{ secrets.OKTETO_TOKEN }}

- name: "Build"
uses: okteto/build@latest
with:
file: okteto.yml
26 changes: 20 additions & 6 deletions examples/KitchenSink/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,38 @@
{
"name": "moznion",
"email": "[email protected]",
"role": "Retired"
"role": "Retired"
},
{
"name": "Satoru Yoshihara",
"email": "[email protected]",
"role": "Maintainer"
"role": "Retired"
},
{
"name": "Satoshi Shibuya",
"email": "[email protected]",
"role": "Maintainer"
"role": "Maintainer"
}
],
"repositories": [
{
"type": "path",
"url": "../../",
"options": {
"symlink": false
}
}
],
"require": {
"php": ">=5.6",
"slim/slim": "^4.0.0",
"php": ">=8.1",
"slim/slim": "^4.11",
"slim/psr7": "^1.6",
"slim/http": "^1.3",
"monolog/monolog": "^3.0.0",
"linecorp/line-bot-sdk": "3.15.0"
"guzzlehttp/guzzle": "^7.5",
"guzzlehttp/psr7": "^2.5",
"php-di/slim-bridge": "^3.3",
"linecorp/line-bot-sdk": "dev-open-api"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit de798e5

Please sign in to comment.