This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "slacker" | |
version = "0.1.0" | |
authors = ["Allen George <[email protected]>"] | |
build = "build.rs" | |
[build-dependencies] | |
serde_codegen = "0.8" | |
[dependencies] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error: failed to run custom build command for `slacker v0.1.0 (file:///Users/allen/src/rust_projects/slacker)` | |
process didn't exit successfully: `/Users/allen/src/rust_projects/slacker/target/debug/build/slacker-cec1aec60a958a13/build-script-build` (exit code: 101) | |
--- stderr | |
error: couldn't read "src/serde_types.in2.rs": No such file or directory (os error 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
match self.client.get(url).send() { // send() returns a ::Result<Response> | |
Ok(response) => { parse_response(response) } | |
Err(e) => { parse_send_failure(e) } | |
} | |
fn parse_response(mut response: Response) -> ParseResult<Channel> { // how do I get this to take a reference? | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn channels_list(&mut self, exclude_archived: bool) -> ParseResult<Vec<Channel>> { | |
let method_url = format!("{}/{}", SLACK_BASE_API_URL, "channels.list"); | |
let mut url = Url::parse(&method_url).unwrap(); // FIXME | |
url.query_pairs_mut() | |
.append_pair("token", &self.access_token) | |
.append_pair("exclude_archived", &exclude_archived.to_string()); | |
let url = url; | |
match self.client.get(url).send() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allen@mrwiggles ~/s/r/slacker> cargo test | |
Compiling slacker v0.1.0 (file:///Users/allen/src/rust_projects/slacker) | |
src/errors.rs:65:38: 65:50 error: mismatched types [E0308] | |
src/errors.rs:65 _ => SlackError::Unknown(error_string) | |
^~~~~~~~~~~~ | |
src/errors.rs:65:38: 65:50 help: run `rustc --explain E0308` to see a detailed explanation | |
src/errors.rs:65:38: 65:50 note: expected type `std::string::String` | |
src/errors.rs:65:38: 65:50 note: found type `&std::string::String` | |
src/errors.rs:65:38: 65:50 error: mismatched types [E0308] | |
src/errors.rs:65 _ => SlackError::Unknown(error_string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod base { | |
pub struct Foo { | |
} | |
impl Foo { | |
pub fn new() -> Foo { | |
Foo {} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn deserialize<T>(response: &mut Response) -> SlackResult<T> where T: serde::Deserialize { | |
let mut body = String::with_capacity(INITIAL_RESPONSE_BODY_SIZE); | |
try!(response.read_to_string(&mut body)); | |
print!(">>> {:?}", body); | |
let deserialized = try!(serde_json::from_str::<T>(&body)); | |
Ok(deserialized) // FIXME: return from above directly | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Serialize, Deserialize, Debug)] | |
pub struct ChatPostMessageResponse { | |
/// `true` if the request was successful, `false` otherwise. | |
pub ok: bool, | |
/// Only populated if there is an error. | |
#[serde(default)] | |
pub error: String, | |
/// Only populated if there is a warning. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let request = self.client.post(api_url); // interesting. I can't build a request without a URL. seems odd | |
let serialized = try!(serde_json::to_string(message_params)); | |
let request = request.body(&serialized); | |
X--- error message follows | |
error: `serialized` does not live long enough | |
--> src/client.rs:76:37 | |
|> | |
76 |> let request = request.body(&serialized); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn build_post_body(message: &Message) -> Body { | |
let mut encoded = form_urlencoded::Serializer::new(String::new()); | |
message.text.as_ref().map(|t| { encoded.append_pair("text", t)}); | |
let query_string = encoded.finish(); | |
let query_string_bytes = query_string.to_owned().as_bytes(); | |
Body::BufBody(query_string_bytes, query_string_bytes.len()) | |
} | |
/* |