aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-06-14 11:24:43 -0500
committerZeyla Hellyer <[email protected]>2017-06-14 09:24:43 -0700
commit0d218e02e043c043d7274c7169607b11c9897a5a (patch)
treea983b9d961e6c8daa751a377c1b0ba820b059f32 /src
parentMake framework dynamic_prefix accept an &Message (diff)
downloadserenity-0d218e02e043c043d7274c7169607b11c9897a5a.tar.xz
serenity-0d218e02e043c043d7274c7169607b11c9897a5a.zip
Use HTTPS Connector with remaining HTTP functions
Diffstat (limited to 'src')
-rw-r--r--src/http/mod.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs
index 2b69831..90869d6 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -536,7 +536,8 @@ pub fn delete_webhook(webhook_id: u64) -> Result<()> {
///
/// [`Webhook`]: ../model/struct.Webhook.html
pub fn delete_webhook_with_token(webhook_id: u64, token: &str) -> Result<()> {
- let client = HyperClient::new();
+ let client = request_client!();
+
verify(204, retry(|| client
.delete(&format!(api!("/webhooks/{}/{}"), webhook_id, token)))
.map_err(Error::Hyper)?)
@@ -750,7 +751,8 @@ pub fn edit_webhook(webhook_id: u64, map: &Value) -> Result<Webhook> {
/// [`edit_webhook`]: fn.edit_webhook.html
pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: &JsonMap) -> Result<Webhook> {
let body = serde_json::to_string(map)?;
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = retry(|| client
.patch(&format!(api!("/webhooks/{}/{}"), webhook_id, token))
.body(&body))
@@ -815,7 +817,8 @@ pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: &JsonMap) -> R
/// [Discord docs]: https://discordapp.com/developers/docs/resources/webhook#querystring-params
pub fn execute_webhook(webhook_id: u64, token: &str, map: &JsonMap) -> Result<Message> {
let body = serde_json::to_string(map)?;
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = retry(|| client
.post(&format!(api!("/webhooks/{}/{}"), webhook_id, token))
.body(&body))
@@ -828,7 +831,8 @@ pub fn execute_webhook(webhook_id: u64, token: &str, map: &JsonMap) -> Result<Me
///
/// Does not require authentication.
pub fn get_active_maintenances() -> Result<Vec<Maintenance>> {
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = retry(|| client.get(
status!("/scheduled-maintenances/active.json")))?;
@@ -1197,7 +1201,8 @@ pub fn get_messages(channel_id: u64, query: &str)
let url = format!(api!("/channels/{}/messages{}"),
channel_id,
query);
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = request(Route::ChannelsIdMessages(channel_id),
|| client.get(&url))?;
@@ -1243,7 +1248,8 @@ pub fn get_reaction_users(channel_id: u64,
///
/// Does not require authentication.
pub fn get_unresolved_incidents() -> Result<Vec<Incident>> {
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = retry(|| client.get(
status!("/incidents/unresolved.json")))?;
@@ -1259,7 +1265,8 @@ pub fn get_unresolved_incidents() -> Result<Vec<Incident>> {
///
/// Does not require authentication.
pub fn get_upcoming_maintenances() -> Result<Vec<Maintenance>> {
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = retry(|| client.get(
status!("/scheduled-maintenances/upcoming.json")))?;
@@ -1333,7 +1340,8 @@ pub fn get_webhook(webhook_id: u64) -> Result<Webhook> {
/// .expect("Error getting webhook");
/// ```
pub fn get_webhook_with_token(webhook_id: u64, token: &str) -> Result<Webhook> {
- let client = HyperClient::new();
+ let client = request_client!();
+
let response = retry(|| client
.get(&format!(api!("/webhooks/{}/{}"), webhook_id, token)))
.map_err(Error::Hyper)?;
@@ -1392,7 +1400,10 @@ pub fn send_file<R: Read>(channel_id: u64, mut file: R, filename: &str, map: Jso
Err(_) => return Err(Error::Url(uri)),
};
- let mut request = Request::new(Method::Post, url)?;
+ let tc = NativeTlsClient::new()?;
+ let connector = HttpsConnector::new(tc);
+ let mut request = Request::with_connector(Method::Post, url, &connector)?;
+
request.headers_mut()
.set(header::Authorization(TOKEN.lock().unwrap().clone()));
request.headers_mut()