take the whole http response and not only the last part

This commit is contained in:
Sebastian Hugentobler 2017-03-22 14:11:57 +01:00
parent e58fdd3024
commit bcb95f3c28
4 changed files with 17 additions and 9 deletions

2
Cargo.lock generated
View File

@ -1,6 +1,6 @@
[root]
name = "gog-sync"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.21.1 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -325,12 +325,15 @@ impl<'a> Gog<'a> {
language_filters: &Vec<String>)
-> Result<Game, GogError> {
let game_uri = self.game_uri(game_id);
debug!("looking for information at {}...", &game_uri);
let response = self.http_client.get(game_uri.as_str())?;
let game_raw: Value = serde_json::from_str(response.as_str())?;
debug!("found {:?}", &game_raw);
let mut game: Game = serde_json::from_str(&response)?;
let game_raw: Value = serde_json::from_str(response.as_str())?;
let downloads = &game_raw["downloads"];
if game_raw.is_object() && !game_raw.as_object().unwrap().contains_key("forumLink") {
@ -344,6 +347,7 @@ impl<'a> Gog<'a> {
game.is_movie = is_movie;
debug!("processing installer fields: {:?}", &downloads);
for languages in downloads.as_array() {
for language in languages {
if !language.is_array() || language.as_array().unwrap().len() < 2 {

View File

@ -92,20 +92,22 @@ impl Http {
/// http_client.get("https://discworld.com/");
/// ```
pub fn get(&mut self, uri: &str) -> Result<String, HttpError> {
let mut response_body = String::new();
let mut data = Vec::new();
self.curl.url(uri)?;
{
let mut transfer = self.curl.transfer();
transfer.write_function(|data| {
response_body = String::from(str::from_utf8(data).unwrap());
Ok(data.len())
transfer.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})?;
transfer.perform()?;
}
Ok(response_body)
match str::from_utf8(data.as_slice()) {
Ok(value) => Ok(value.to_owned()),
Err(error) => Err(HttpError::Utf8Error(error)),
}
}
/// Add a header to all future requests.

View File

@ -11,9 +11,11 @@
//! OPTIONS:
//! -l, --language <FILTER> Only sync files for this comma seperated list of languages.
//! -o, --os <FILTER> Only sync files for this comma seperated list of operating systems.
//! Valid values are 'linux', 'mac' and 'windows'.
//! Valid values are linux, mac and windows.
//! -s, --storage <FOLDER> Sets the download folder (defaults to the working directory).
//! ```
//!
//! An incomplete list of languages on gog: `english, český, deutsch, español, français, magyar, polski, русский, 中文`
extern crate chrono;
extern crate clap;