Skip to content

Commit

Permalink
OpenAPI implementation (#43)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nanato12 authored Dec 3, 2023
1 parent 5e32bd3 commit 2012250
Show file tree
Hide file tree
Showing 703 changed files with 30,734 additions and 3,540 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LINE_CHANNEL_SECRET=
LINE_CHANNEL_ACCESS_TOKEN=
40 changes: 33 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
name: Rust

on: [pull_request, push]
on:
pull_request:
branches:
- develop
push:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest
name: Rust ${{ matrix.os }} ${{ matrix.rust }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
rust:
- stable
- beta
- nightly
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v1
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose --tests
- uses: actions/checkout@v2

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose --tests
continue-on-error: ${{ matrix.rust == 'nightly' }}
18 changes: 8 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# env
.env

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

# These are backup files generated by rustfmt
**/*.rs.bk

# enviroment value
.env
# openapi generator
.openapi-generator
/core/*/.openapi-generator-ignore
/tools/openapi-generator-cli-*.jar
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "line-openapi"]
path = line-openapi
url = git@github.com:nanato12/line-openapi.git
66 changes: 15 additions & 51 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
[package]
name = "line-bot-sdk-rust"
version = "0.1.2"
authors = ["nanato12 <admin@nanato12.info>"]
edition = "2018"
description = "LINE Messaging API SDK for Rust"
readme = "README.md"
repository = "https://github.com/nanato12/line-bot-sdk-rust/"
license-file = "LICENSE"
keywords = ["line", "linebot", "line-bot-sdk", "line-messaging-api"]
categories = ["api-bindings"]

[features]
default = []
rocket_support = ["rocket"]
actix_support = ["actix-web"]

[dependencies]
actix-web = { version = "4.3.1", optional = true, default-features = false }
base64 = "0.21.0"
chrono = "0.4"
hmac = "0.12.1"
reqwest = { version = "0.11.14", features = ["blocking", "json"] }
rocket = { version = "0.4", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0.156"
serde_json = "1.0"
sha2 = "0.10.6"

[dev-dependencies]
bytes = "1.4.0"
dotenv = "0.15.0"
actix-web = "4.3.1"
actix-rt = "2.8.0"
rocket = "0.4"

[[example]]
name = "echobot_actix_web"
required-features = ["actix_support"]

[[example]]
name = "echobot_rocket"
required-features = ["rocket_support"]

[[example]]
name = "source_rocket"
required-features = ["rocket_support"]

[[example]]
name = "various_messages_rocket"
required-features = ["rocket_support"]
[workspace]
resolver = "2"
members = [
"generator",
"core/line_channel_access_token",
"core/line_insight",
"core/lib/",
"core/line_liff",
"core/line_manage_audience",
"core/line_messaging_api",
"core/line_module",
"core/line_module_attach",
"core/line_shop",
"core/line_webhook",
]
91 changes: 61 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,110 @@
# LINE Messaging API SDK for Rust

## Introduction

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.

## Documentation

See the official API documentation for more information.

- English: <https://developers.line.biz/en/docs/messaging-api/overview/>
- Japanese: <https://developers.line.biz/ja/docs/messaging-api/overview/>

## Requirements
This library requires Rust nightly.

This library requires stable/beta Rust.

## Installation
```

```toml
[dependencies]
line-bot-sdk-rust = "0.1"
line-bot-sdk-rust = "1.0.0"
```

If you use `rocket support`.

```toml
[dependencies.line-bot-sdk-rust]
version = "1.0.0"
features = ["rocket_support"]
```
[dependencies]
line-bot-sdk-rust = { version = "0.1", features = ["rocket_support"] }
```

If you use `actix_web support`.

```toml
[dependencies.line-bot-sdk-rust]
version = "1.0.0"
features = ["actix_support"]
```
[dependencies]
line-bot-sdk-rust = { version = "0.1", features = ["actix_support"] }
```

## Configuration
```

```rust
extern crate line_bot_sdk_rust as line;
use line::bot::LineBot;
use line::messaging_api::apis::configuration::Configuration;
use std::env;

fn main() {
let bot = LineBot::new("<channel secret>", "<channel access token>");
let access_token: &str =
&env::var("LINE_CHANNEL_ACCESS_TOKEN").expect("Failed getting LINE_CHANNEL_ACCESS_TOKEN");

let mut conf = Configuration::default();
conf.bearer_access_token = Some(access_token.to_string());
}
```

## How to use

The LINE Messaging API uses the JSON data format.
parse_event_request() will help you to parse the HttpRequest content and return a Result<[Events](`events::Events`) , &'static str> Object.
```
let result: Result<Events, &'static str> =
bot.parse_event_request(signature, body);
```

Parse body (`&str`) into Result<CallbackRequest, serde_json::Error>.

```rust
let request: Result<CallbackRequest, serde_json::Error> = serde_json::from_str(body);
```
match result {
Ok(events) => {
for event in events.events {
...

```rust
match request {
Err(err) => {
// error handling
},
Ok(req) => {
for e in req.events {
// Processing for various events
}
}
Err(msg) => {}
}
```

## EchoBot examples

**with Rocket framework**
### with Rocket framework

```bash
cargo run --example echobot_rocket --features=rocket_support
$ cd examples
$ cargo run --bin rocket
```

source: [rocket example](./examples/echobot_rocket.rs)
source: [rocket example](./examples/rocket/src/main.rs)

**with Actix_web framework**
### with actix_web framework

```bash
cargo run --example echobot_actix_web --features=actix_support
$ cd examples
$ cargo run --bin actix_web
```

source: [actix_web example](./examples/echobot_actix_web.rs)
source: [actix_web example](./examples/actix_web/src/main.rs)

## Contributing

Please make a contribution 😆

## License
```
Copyright 2021 nanato12

```plain
Copyright 2023 nanato12
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions core/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
69 changes: 69 additions & 0 deletions core/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[package]
name = "line-bot-sdk-rust"
version = "1.0.0"
authors = ["nanato12 <admin@okj.info>"]
edition = "2021"
description = "LINE Messaging API SDK for Rust"
readme = "../../README.md"
repository = "https://github.com/nanato12/line-bot-sdk-rust/"
license-file = "../../LICENSE"
keywords = ["line", "linebot", "line-bot-sdk", "line-messaging-api"]
categories = ["api-bindings"]

[features]
default = []
rocket_support = ["rocket"]
actix_support = ["actix-web"]

[dependencies]
base64 = "0.21.5"
hmac = "0.12.1"
sha2 = "0.10.8"
hyper = { version = "~0.14", features = ["full"] }
hyper-rustls = "0.24.2"

[dependencies.rocket]
version = "0.5.0"
optional = true
default-features = false

[dependencies.actix-web]
version = "4.4.0"
optional = true
default-features = false

[dependencies.line_channel_access_token]
version = "0.0.1"
path = "../line_channel_access_token"

[dependencies.line_insight]
version = "0.0.1"
path = "../line_insight"

[dependencies.line_liff]
version = "1.0.0"
path = "../line_liff"

[dependencies.line_manage_audience]
version = "0.0.1"
path = "../line_manage_audience"

[dependencies.line_messaging_api]
version = "0.0.1"
path = "../line_messaging_api"

[dependencies.line_module]
version = "0.0.1"
path = "../line_module"

[dependencies.line_module_attach]
version = "0.0.1"
path = "../line_module_attach"

[dependencies.line_shop]
version = "0.0.1"
path = "../line_shop"

[dependencies.line_webhook]
version = "1.0.0"
path = "../line_webhook"
Loading

0 comments on commit 2012250

Please sign in to comment.