Skip to content

Commit

Permalink
Merge pull request #31 from nanato12/update-0.1.2
Browse files Browse the repository at this point in the history
Update 0.1.2
  • Loading branch information
nanato12 authored Jun 9, 2021
2 parents a5ca302 + 3550f11 commit 8e91e37
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "line-bot-sdk-rust"
version = "0.1.1"
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 = "Apache-2.0"
license-file = "LICENSE"
keywords = ["line", "linebot", "line-bot-sdk", "line-messaging-api"]
categories = ["api-bindings"]
Expand Down
2 changes: 1 addition & 1 deletion src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl LineBot {
/// ```
pub fn get_content(&self, message_id: &str) -> Result<Response, Error> {
let endpoint = format!("/message/{messageId}/content", messageId = message_id);
self.http_client.get(&endpoint, vec![], json!({}))
self.http_client.get_data(&endpoint, vec![], json!({}))
}

/// # Note
Expand Down
23 changes: 23 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use reqwest::Url;
use serde_json::Value;

static BASE_URL: &str = "https://api.line.me/v2/bot";
static BASEDATA_URL: &str = "https://api-data.line.me/v2/bot";

#[derive(Debug)]
pub struct HttpClient {
client: Client,
headers: HeaderMap,
endpoint_base: String,
endpoint_base_data: String,
}

impl HttpClient {
Expand All @@ -33,6 +35,7 @@ impl HttpClient {
client: Client::new(),
headers: headers,
endpoint_base: String::from(BASE_URL),
endpoint_base_data: String::from(BASEDATA_URL),
}
}

Expand All @@ -56,6 +59,26 @@ impl HttpClient {
.send()
}

/// # Note
/// `GET` request
/// ```
/// let res: Result<Response, Error> = http_client.get_data("https://example.com");
/// ```
pub fn get_data(
&self,
endpoint: &str,
query: Vec<(&str, &str)>,
data: Value,
) -> Result<Response, Error> {
let uri = Url::parse(&format!("{}{}", self.endpoint_base_data, endpoint)).unwrap();
self.client
.get(uri)
.query(&query)
.headers(self.headers.clone())
.json(&data)
.send()
}

/// # Note
/// `POST` request
/// ```
Expand Down

0 comments on commit 8e91e37

Please sign in to comment.