Skip to content

Commit 0e01478

Browse files
authored
Merge pull request #13 from nanato12/feature/doc
Create documentation
2 parents d754fd3 + 57a69d5 commit 0e01478

File tree

12 files changed

+436
-26
lines changed

12 files changed

+436
-26
lines changed

src/bot.rs

Lines changed: 290 additions & 21 deletions
Large diffs are not rendered by default.

src/client.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! HTTP Client
2+
13
use reqwest::blocking::{Client, Response};
24
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE};
35
use reqwest::Error;
@@ -14,6 +16,11 @@ pub struct HttpClient {
1416
}
1517

1618
impl HttpClient {
19+
/// # Note
20+
/// Instantiate a HttpClient.
21+
/// ```
22+
/// let http_client = HttpClient::new("<channel secret>");
23+
/// ```
1724
pub fn new(channel_token: &str) -> HttpClient {
1825
let mut headers = HeaderMap::new();
1926
headers.insert(
@@ -28,6 +35,11 @@ impl HttpClient {
2835
}
2936
}
3037

38+
/// # Note
39+
/// `GET` request
40+
/// ```
41+
/// let res: Result<Response, Error> = http_client.get("https://example.com");
42+
/// ```
3143
pub fn get(
3244
&self,
3345
endpoint: &str,
@@ -43,6 +55,11 @@ impl HttpClient {
4355
.send()
4456
}
4557

58+
/// # Note
59+
/// `POST` request
60+
/// ```
61+
/// let res: Result<Response, Error> = http_client.post("https://example.com");
62+
/// ```
4663
pub fn post(&self, endpoint: &str, data: Value) -> Result<Response, Error> {
4764
let uri = Url::parse(&format!("{}{}", self.endpoint_base, endpoint)).unwrap();
4865
self.client
@@ -52,6 +69,11 @@ impl HttpClient {
5269
.send()
5370
}
5471

72+
/// # Note
73+
/// `PUT` request
74+
/// ```
75+
/// let res: Result<Response, Error> = http_client.put("https://example.com");
76+
/// ```
5577
pub fn put(&self, endpoint: &str, data: Value) -> Result<Response, Error> {
5678
let uri = Url::parse(&format!("{}{}", self.endpoint_base, endpoint)).unwrap();
5779
self.client
@@ -61,6 +83,11 @@ impl HttpClient {
6183
.send()
6284
}
6385

86+
/// # Note
87+
/// `DELETE` request
88+
/// ```
89+
/// let res: Result<Response, Error> = http_client.delete("https://example.com");
90+
/// ```
6491
pub fn delete(&self, endpoint: &str, data: Value) -> Result<Response, Error> {
6592
let uri = Url::parse(&format!("{}{}", self.endpoint_base, endpoint)).unwrap();
6693
self.client

src/events/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Request events
2+
13
pub mod account_link;
24
pub mod beacon;
35
pub mod follow;

src/lib.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1+
//! # Introduction
2+
//! 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.
3+
//! # Documentation
4+
//! See the official API documentation for more information.
5+
//! - English: <https://developers.line.biz/en/docs/messaging-api/overview/>
6+
//! - Japanese: <https://developers.line.biz/ja/docs/messaging-api/overview/>
7+
//! # Requirements
8+
//! This library requires Rust nightly.
9+
//! # Installation
10+
//! ```
11+
//! [dependencies]
12+
//! line-bot-sdk-rust = "0.1"
13+
//! ```
14+
//! # Configuration
15+
//! ```
16+
//! extern crate line_bot_sdk_rust as line;
17+
//! use line::bot::LineBot;
18+
//!
19+
//! fn main() {
20+
//! let bot = LineBot::new("<channel secret>", "<channel access token>");
21+
//! }
22+
//! ```
23+
//! # How to use
24+
//! The LINE Messaging API uses the JSON data format.
25+
//! parse_event_request() will help you to parse the HttpRequest content and return a Result<[Events](`events::Events`) , &'static str> Object.
26+
//! ```
27+
//! let result: Result<Events, &'static str> =
28+
//! bot.parse_event_request(signature, body);
29+
//! ```
30+
//!
31+
//! ```
32+
//! match result {
33+
//! Ok(events) => {
34+
//! for event in events.events {
35+
//! ...
36+
//! }
37+
//! }
38+
//! Err(msg) => {}
39+
//! }
40+
//! ```
41+
//!
42+
//! # Contributing
43+
//! Please make a contribution 😆
44+
//! <https://github.com/nanato12/line-bot-sdk-rust>
45+
//!
46+
//! # License
47+
//! ```
48+
//! Copyright 2021 nanato12
49+
//!
50+
//! Licensed under the Apache License, Version 2.0 (the "License");
51+
//! you may not use this file except in compliance with the License.
52+
//! You may obtain a copy of the License at
53+
//!
54+
//! http://www.apache.org/licenses/LICENSE-2.0
55+
//!
56+
//! Unless required by applicable law or agreed to in writing, software
57+
//! distributed under the License is distributed on an "AS IS" BASIS,
58+
//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59+
//! See the License for the specific language governing permissions and
60+
//! limitations under the License.
61+
//! ```
62+
163
pub mod bot;
264
pub mod client;
365
pub mod events;

src/messages/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! SendMessage Instances
2+
13
pub mod audio_message;
24
pub mod flex_message;
35
pub mod image_map_message;

src/objects/action.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
//! Action objects
2+
//! # Note
3+
//! These are types of actions for your bot to take when a user taps a button or an image in a message.
4+
//! <https://developers.line.biz/en/reference/messaging-api/#action-objects>
15
use serde_derive::Serialize;
26

7+
/// Action object
8+
/// # Note
39
#[derive(Serialize, Debug)]
410
pub struct Action {
511
#[serde(flatten)]
@@ -8,6 +14,7 @@ pub struct Action {
814
pub label: Option<String>,
915
}
1016

17+
/// Action object types
1118
#[derive(Serialize, Debug)]
1219
#[serde(tag = "type")]
1320
pub enum ActionType {
@@ -46,6 +53,9 @@ pub enum ActionType {
4653
Location {},
4754
}
4855

56+
/// Alt uri object
57+
/// # Note
58+
/// URI opened on LINE for macOS and Windows when the action is performed.
4959
#[derive(Serialize, Debug)]
5060
pub struct AltUri {
5161
pub desktop: String,

src/objects/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various objects needed when sending message
2+
13
pub mod action;
24
pub mod narrowcast;
35
pub mod profile;

src/objects/narrowcast/filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde_derive::Serialize;
22

3+
/// # Details
34
/// Please read.
4-
/// https://developers.line.biz/ja/reference/messaging-api/#narrowcast-demographic-filter
5-
5+
/// <https://developers.line.biz/ja/reference/messaging-api/#narrowcast-demographic-filter>
66
#[derive(Serialize, Debug)]
77
pub struct Filter {
88
pub demographic: Demographic,

src/objects/narrowcast/recipient.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde_derive::Serialize;
22

3+
/// # Details
34
/// Please read.
4-
/// https://developers.line.biz/ja/reference/messaging-api/#narrowcast-recipient
5-
5+
/// <https://developers.line.biz/ja/reference/messaging-api/#narrowcast-recipient>
66
#[derive(Serialize, Debug)]
77
pub struct Recipient {
88
#[serde(flatten)]

src/support/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
//! Support for framework
2+
13
pub mod rocket_support;

0 commit comments

Comments
 (0)