Skip to content

Commit

Permalink
change docs, update version
Browse files Browse the repository at this point in the history
  • Loading branch information
gdwrd committed Apr 15, 2017
1 parent 50add19 commit a7eb26d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "knock"
version = "0.1.0"
version = "0.1.1"
authors = ["Nazarii Sheremet <[email protected]>"]

description = "Knock is a simple HTTP Client for Rust"
Expand Down
135 changes: 61 additions & 74 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod err;
mod consts;
mod response;

#[derive(Debug)]
pub struct HTTP {
pub response: Response,
pub url: url::Url,
Expand All @@ -35,20 +34,19 @@ pub struct HTTP {
response_str: String,
}

#[derive(Debug)]
pub enum Data {
File(String),
String(String),
}

impl HTTP {

/// Create New HTTP
///
/// Params: url &str
///
/// Response: Result<HTTP, HttpError>
///
// Create New HTTP
//
// Params: url &str
//
// Response: Result<HTTP, HttpError>
//
pub fn new(url: &str) -> Result<HTTP, HttpError> {
let response = Response {
status: 0,
Expand All @@ -75,97 +73,89 @@ impl HTTP {
})
}

/// GET request
///
/// Params: &mut self (HTTP)
///
/// Response: &mut self (HTTP)
///
// GET request
//
// Params: &mut self (HTTP)
//
// Response: &mut self (HTTP)
//
pub fn get(&mut self) -> &mut Self {
self.method = "GET".to_string();
self
}

/// POST request
///
/// Params: &mut self (HTTP)
///
/// Response: &mut self (HTTP)
///
// POST request
//
// Params: &mut self (HTTP)
//
// Response: &mut self (HTTP)
//
pub fn post(&mut self) -> &mut Self {
self.method = "POST".to_string();
self
}

/// PUT request
///
/// Params: &mut self (HTTP)
///
/// Response: &mut self (HTTP)
///
// PUT request
//
// Params: &mut self (HTTP)
//
// Response: &mut self (HTTP)
//
pub fn put(&mut self) -> &mut Self {
self.method = "PUT".to_string();
self
}

/// DELETE request
///
/// Params: &mut self (HTTP)
///
/// Response: &mut self (HTTP)
///
// DELETE request
//
// Params: &mut self (HTTP)
//
// Response: &mut self (HTTP)
//
pub fn delete(&mut self) -> &mut Self {
self.method = "DELETE".to_string();
self
}

/// REQEUST request
///
/// Params: &mut self (HTTP), method &str
///
/// Response: &mut self (HTTP)
///
// REQEUST request
//
// Params: &mut self (HTTP), method &str
//
// Response: &mut self (HTTP)
//
pub fn request(&mut self, method: &str) -> &mut Self {
self.method = method.to_string();
self
}

/// Set Body to self.body
///
/// Params: &mut self (HTTP), data HashMap<String, Data>
///
/// Response: &mut self (HTTP)
///
// Set Body to self.body
//
// Params: &mut self (HTTP), data HashMap<String, Data>
//
// Response: &mut self (HTTP)
//
pub fn body(&mut self, data: HashMap<String, Data>) -> &mut Self {
self.body = data;
self
}

/// Set Headers to self.header
///
/// Params: &mut self (HTTP), data HashMap<String, String>
///
/// Response: &mut self (HTTP)
///
// Set Headers to self.header
//
// Params: &mut self (HTTP), data HashMap<String, String>
//
// Response: &mut self (HTTP)
//
pub fn header(&mut self, data: HashMap<String, String>) -> &mut Self {
self.header = data;
self
}

/// Create request, and send
///
/// Params: &mut self (HTTP)
///
/// Response: Result<Response, HttpError>
///
// Create request, and send
//
// Params: &mut self (HTTP)
//
// Response: Result<Response, HttpError>
//
pub fn send(&mut self) -> Result<Response, HttpError> {
self.boundary = rand::thread_rng()
.gen_ascii_chars()
Expand Down Expand Up @@ -205,13 +195,12 @@ impl HTTP {
Ok(resp)
}

/// Create Reqeust String
///
/// Params: &mut self (HTTP)
///
/// Response: Result<String, HttpError>
///
// Create Reqeust String
//
// Params: &mut self (HTTP)
//
// Response: Result<String, HttpError>
//
fn create_request(&self) -> Result<String, HttpError> {
let (mut header, c_type) = organize_header(&self.header, self.host.clone());
let body = try!(create_body(&c_type, &self.body, header.clone(), &self.boundary));
Expand Down Expand Up @@ -242,13 +231,12 @@ impl HTTP {
}
}

/// Create Body for request
///
/// Params: c_type: &str, body: &HashMap<String, Data>, mut header: HashMap<String, String>, b: &str
///
/// Response: Result<String, HttpError>
///
// Create Body for request
//
// Params: c_type: &str, body: &HashMap<String, Data>, mut header: HashMap<String, String>, b: &str
//
// Response: Result<String, HttpError>
//
fn create_body(c_type: &str,
body: &HashMap<String, Data>,
mut header: HashMap<String, String>,
Expand Down Expand Up @@ -309,13 +297,12 @@ fn create_body(c_type: &str,
Ok(res)
}

/// Update Header
///
/// Params: mut header: HashMap<String, String>, host: String
///
/// Response: (Result<String, HttpError>, String)
///
// Update Header
//
// Params: mut header: HashMap<String, String>, host: String
//
// Response: (Result<String, HttpError>, String)
//
fn organize_header(header: &HashMap<String, String>,
host: String)
-> (HashMap<String, String>, String) {
Expand Down

0 comments on commit a7eb26d

Please sign in to comment.