Skip to content

Commit 2012250

Browse files
authored
OpenAPI implementation (#43)
* add: submodule * add: .openapi-generator-ignore * add: .gitignore * add: generator workspace * add: tools * update: .gitignore * add: openapi * run: cargo fix * run: cargo fmt * update: generator * add: Makefile * update: Cargo.toml * update: .gitignore * update: README.md * run: cargo new --bin sample * update: Cargo.toml * delete: openapi main.rs * update: message.rs * update: generator * update: sample * update: Makefile * update: Cargo * update: support * update: Cargo.toml * update: lib.rs * add: event.rs * update: Cargo * update: event.rs * update: webhook model * update sample * remove: r#type * add: message_content * update: tool source * update: webhook * update: event * update: generator * update: openapi * update: generator * update: message.rs * update: generator * update: message * add: callback_request_test.rs * update: sample * update: generator * update: generator * update: generator * update: .openapi-generator-ignore * update: sample * add: rocket support * delete: existing src * remove: openapi src * update: Cargo * update: Cargo * remove: test * update: examples * delete: sample * update: Cargo * add: .env.template * delete: sample cargo * update: Cargo * update: Makefile * update: test * add: rocket-sample * add: rocket support * update: rocket supprt * update: Cargo * update: Makefile * update: rocket support * update: generator * update: submodule * update: example * delete: toolchain * update: Cargo * update: .gitignore * update: generator * update: Cargo * delete: .gitignore * update: test * update: .openapi-generator-ignore * add: docs * delete: Cargo * update: .gitignore * delete: Makefile * replace: source * update: core * update: example * update: generator * update: generator * update: core * rename: examples * update: signature * add: rocket_example * rename: actix_web_example * update: example Cargo.toml * update: rust.yml * update: README.md * update: generator * update: lib * update: core * update: actix_web_example * update: validate_signature * update: actix_web_example * update: rocket_example * update: Cargo.toml * update: LICENSE * add: LICENSE code * update: LICENSE * update: tools/source * update: core * add: pkg-prefix * update: core * update: generator * fix: examples * update: Cargo.toml
1 parent 5e32bd3 commit 2012250

File tree

703 files changed

+30734
-3540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

703 files changed

+30734
-3540
lines changed

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LINE_CHANNEL_SECRET=
2+
LINE_CHANNEL_ACCESS_TOKEN=

.github/workflows/rust.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
name: Rust
22

3-
on: [pull_request, push]
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
push:
8+
branches:
9+
- develop
410

511
jobs:
612
build:
7-
runs-on: ubuntu-latest
13+
name: Rust ${{ matrix.os }} ${{ matrix.rust }}
14+
runs-on: ${{ matrix.os }}
15+
16+
strategy:
17+
matrix:
18+
rust:
19+
- stable
20+
- beta
21+
- nightly
22+
os: [ubuntu-latest, windows-latest, macos-latest]
23+
824
steps:
9-
- uses: actions/checkout@v1
10-
- name: Build
11-
run: cargo build --verbose
12-
- name: Run tests
13-
run: cargo test --verbose --tests
25+
- uses: actions/checkout@v2
26+
27+
- name: Setup Rust
28+
uses: actions-rs/toolchain@v1
29+
with:
30+
profile: minimal
31+
toolchain: ${{ matrix.rust }}
32+
override: true
33+
34+
- name: Build
35+
run: cargo build --verbose
36+
37+
- name: Run tests
38+
run: cargo test --verbose --tests
39+
continue-on-error: ${{ matrix.rust == 'nightly' }}

.gitignore

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# Generated by Cargo
2-
# will have compiled files and executables
3-
/target/
1+
# env
2+
.env
43

5-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
4+
# cargo
5+
target
76
Cargo.lock
87

9-
# These are backup files generated by rustfmt
10-
**/*.rs.bk
11-
12-
# enviroment value
13-
.env
8+
# openapi generator
9+
.openapi-generator
10+
/core/*/.openapi-generator-ignore
11+
/tools/openapi-generator-cli-*.jar

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "line-openapi"]
2+
path = line-openapi
3+
url = git@github.com:nanato12/line-openapi.git

Cargo.toml

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
1-
[package]
2-
name = "line-bot-sdk-rust"
3-
version = "0.1.2"
4-
authors = ["nanato12 <admin@nanato12.info>"]
5-
edition = "2018"
6-
description = "LINE Messaging API SDK for Rust"
7-
readme = "README.md"
8-
repository = "https://github.com/nanato12/line-bot-sdk-rust/"
9-
license-file = "LICENSE"
10-
keywords = ["line", "linebot", "line-bot-sdk", "line-messaging-api"]
11-
categories = ["api-bindings"]
12-
13-
[features]
14-
default = []
15-
rocket_support = ["rocket"]
16-
actix_support = ["actix-web"]
17-
18-
[dependencies]
19-
actix-web = { version = "4.3.1", optional = true, default-features = false }
20-
base64 = "0.21.0"
21-
chrono = "0.4"
22-
hmac = "0.12.1"
23-
reqwest = { version = "0.11.14", features = ["blocking", "json"] }
24-
rocket = { version = "0.4", optional = true }
25-
serde = { version = "1.0", features = ["derive"] }
26-
serde_derive = "1.0.156"
27-
serde_json = "1.0"
28-
sha2 = "0.10.6"
29-
30-
[dev-dependencies]
31-
bytes = "1.4.0"
32-
dotenv = "0.15.0"
33-
actix-web = "4.3.1"
34-
actix-rt = "2.8.0"
35-
rocket = "0.4"
36-
37-
[[example]]
38-
name = "echobot_actix_web"
39-
required-features = ["actix_support"]
40-
41-
[[example]]
42-
name = "echobot_rocket"
43-
required-features = ["rocket_support"]
44-
45-
[[example]]
46-
name = "source_rocket"
47-
required-features = ["rocket_support"]
48-
49-
[[example]]
50-
name = "various_messages_rocket"
51-
required-features = ["rocket_support"]
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"generator",
5+
"core/line_channel_access_token",
6+
"core/line_insight",
7+
"core/lib/",
8+
"core/line_liff",
9+
"core/line_manage_audience",
10+
"core/line_messaging_api",
11+
"core/line_module",
12+
"core/line_module_attach",
13+
"core/line_shop",
14+
"core/line_webhook",
15+
]

README.md

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,110 @@
11
# LINE Messaging API SDK for Rust
2+
23
## Introduction
4+
35
The LINE Messaging API SDK for Rust makes it easy to develop bots using LINE Messaging API, and you can create a sample bot within minutes.
6+
47
## Documentation
8+
59
See the official API documentation for more information.
10+
611
- English: <https://developers.line.biz/en/docs/messaging-api/overview/>
712
- Japanese: <https://developers.line.biz/ja/docs/messaging-api/overview/>
13+
814
## Requirements
9-
This library requires Rust nightly.
15+
16+
This library requires stable/beta Rust.
17+
1018
## Installation
11-
```
19+
20+
```toml
1221
[dependencies]
13-
line-bot-sdk-rust = "0.1"
22+
line-bot-sdk-rust = "1.0.0"
1423
```
24+
1525
If you use `rocket support`.
26+
27+
```toml
28+
[dependencies.line-bot-sdk-rust]
29+
version = "1.0.0"
30+
features = ["rocket_support"]
1631
```
17-
[dependencies]
18-
line-bot-sdk-rust = { version = "0.1", features = ["rocket_support"] }
19-
```
32+
2033
If you use `actix_web support`.
34+
35+
```toml
36+
[dependencies.line-bot-sdk-rust]
37+
version = "1.0.0"
38+
features = ["actix_support"]
2139
```
22-
[dependencies]
23-
line-bot-sdk-rust = { version = "0.1", features = ["actix_support"] }
24-
```
40+
2541
## Configuration
26-
```
42+
43+
```rust
2744
extern crate line_bot_sdk_rust as line;
28-
use line::bot::LineBot;
45+
use line::messaging_api::apis::configuration::Configuration;
46+
use std::env;
2947

3048
fn main() {
31-
let bot = LineBot::new("<channel secret>", "<channel access token>");
49+
let access_token: &str =
50+
&env::var("LINE_CHANNEL_ACCESS_TOKEN").expect("Failed getting LINE_CHANNEL_ACCESS_TOKEN");
51+
52+
let mut conf = Configuration::default();
53+
conf.bearer_access_token = Some(access_token.to_string());
3254
}
3355
```
56+
3457
## How to use
58+
3559
The LINE Messaging API uses the JSON data format.
36-
parse_event_request() will help you to parse the HttpRequest content and return a Result<[Events](`events::Events`) , &'static str> Object.
37-
```
38-
let result: Result<Events, &'static str> =
39-
bot.parse_event_request(signature, body);
40-
```
4160

61+
Parse body (`&str`) into Result<CallbackRequest, serde_json::Error>.
62+
63+
```rust
64+
let request: Result<CallbackRequest, serde_json::Error> = serde_json::from_str(body);
4265
```
43-
match result {
44-
Ok(events) => {
45-
for event in events.events {
46-
...
66+
67+
```rust
68+
match request {
69+
Err(err) => {
70+
// error handling
71+
},
72+
Ok(req) => {
73+
for e in req.events {
74+
// Processing for various events
4775
}
4876
}
49-
Err(msg) => {}
5077
}
5178
```
5279

5380
## EchoBot examples
5481

55-
**with Rocket framework**
82+
### with Rocket framework
5683

5784
```bash
58-
cargo run --example echobot_rocket --features=rocket_support
85+
$ cd examples
86+
$ cargo run --bin rocket
5987
```
6088

61-
source: [rocket example](./examples/echobot_rocket.rs)
89+
source: [rocket example](./examples/rocket/src/main.rs)
6290

63-
**with Actix_web framework**
91+
### with actix_web framework
6492

6593
```bash
66-
cargo run --example echobot_actix_web --features=actix_support
94+
$ cd examples
95+
$ cargo run --bin actix_web
6796
```
6897

69-
source: [actix_web example](./examples/echobot_actix_web.rs)
98+
source: [actix_web example](./examples/actix_web/src/main.rs)
7099

71100
## Contributing
101+
72102
Please make a contribution 😆
73103

74104
## License
75-
```
76-
Copyright 2021 nanato12
105+
106+
```plain
107+
Copyright 2023 nanato12
77108
78109
Licensed under the Apache License, Version 2.0 (the "License");
79110
you may not use this file except in compliance with the License.

core/lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

core/lib/Cargo.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[package]
2+
name = "line-bot-sdk-rust"
3+
version = "1.0.0"
4+
authors = ["nanato12 <admin@okj.info>"]
5+
edition = "2021"
6+
description = "LINE Messaging API SDK for Rust"
7+
readme = "../../README.md"
8+
repository = "https://github.com/nanato12/line-bot-sdk-rust/"
9+
license-file = "../../LICENSE"
10+
keywords = ["line", "linebot", "line-bot-sdk", "line-messaging-api"]
11+
categories = ["api-bindings"]
12+
13+
[features]
14+
default = []
15+
rocket_support = ["rocket"]
16+
actix_support = ["actix-web"]
17+
18+
[dependencies]
19+
base64 = "0.21.5"
20+
hmac = "0.12.1"
21+
sha2 = "0.10.8"
22+
hyper = { version = "~0.14", features = ["full"] }
23+
hyper-rustls = "0.24.2"
24+
25+
[dependencies.rocket]
26+
version = "0.5.0"
27+
optional = true
28+
default-features = false
29+
30+
[dependencies.actix-web]
31+
version = "4.4.0"
32+
optional = true
33+
default-features = false
34+
35+
[dependencies.line_channel_access_token]
36+
version = "0.0.1"
37+
path = "../line_channel_access_token"
38+
39+
[dependencies.line_insight]
40+
version = "0.0.1"
41+
path = "../line_insight"
42+
43+
[dependencies.line_liff]
44+
version = "1.0.0"
45+
path = "../line_liff"
46+
47+
[dependencies.line_manage_audience]
48+
version = "0.0.1"
49+
path = "../line_manage_audience"
50+
51+
[dependencies.line_messaging_api]
52+
version = "0.0.1"
53+
path = "../line_messaging_api"
54+
55+
[dependencies.line_module]
56+
version = "0.0.1"
57+
path = "../line_module"
58+
59+
[dependencies.line_module_attach]
60+
version = "0.0.1"
61+
path = "../line_module_attach"
62+
63+
[dependencies.line_shop]
64+
version = "0.0.1"
65+
path = "../line_shop"
66+
67+
[dependencies.line_webhook]
68+
version = "1.0.0"
69+
path = "../line_webhook"

0 commit comments

Comments
 (0)