Permalink
Browse files

Migrate to serde_json (fix #1)

  • Loading branch information...
Xion committed Jan 7, 2017
1 parent 10655c5 commit a0655a6a5b86c05df5665e3bc7f1512f2476c9e4
Showing with 44 additions and 15 deletions.
  1. +31 −1 Cargo.lock
  2. +1 −1 Cargo.toml
  3. +4 −4 README.md
  4. +4 −6 src/hosts/github/api.rs
  5. +1 −1 src/hosts/github/storage.rs
  6. +2 −1 src/hosts/github/util.rs
  7. +1 −1 src/main.rs
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -24,7 +24,7 @@ lazy_static = "*"
log = "0.3"
maplit = "0.1"
regex = "0.1"
rustc-serialize = "0.3"
serde_json = "0.8.4"
shlex = "0.1.1"
slog = "*"
slog-envlogger = "0.5"
View
@@ -15,26 +15,26 @@ Magic!
## Usage
gisht [OPTIONS] [SUBCOMMAND]
OPTIONS:
-c, --cached Operate only on gists available locally
-f, --fetch Always fetch the gist from a remote host
-v, --verbose Increase logging verbosity
-q, --quiet Decrease logging verbosity
-H, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
run Run the specified gist [aliases: exec]
which Output the path to gist's binary
print Print the source code of gist's binary [aliases: cat]
open Open the gist's webpage [aliases: show]
info Display summary information about the gist [aliases: stat]
help Prints this message or the help of the given subcommand(s)
Hint: `gisht run GIST` can be shortened to just `gisht GIST`.
If you want to pass arguments, put them after `--` (two dashes), like this:
gisht Octocat/greet -- "Hello world" --cheerful
## Installation
View
@@ -5,7 +5,7 @@ use std::io;
use hyper::client::{Client, Response};
use hyper::header::UserAgent;
use rustc_serialize::json::Json;
use serde_json::Value as Json;
use url::Url;
use ::USER_AGENT;
@@ -146,7 +146,7 @@ impl<'o> GistsIterator<'o> {
/// Convert a JSON representation of the gist into a Gist object.
fn gist_from_json(&self, gist: &Json) -> Option<Gist> {
let id = gist["id"].as_string().unwrap();
let id = gist.pointer("id").and_then(Json::as_str).unwrap();
let name = match gist_name_from_info(&gist) {
Some(name) => name,
None => {
@@ -201,7 +201,7 @@ pub fn build_gist_info(info: &Json, data: &[Datum]) -> gist::Info {
let mut result = gist::InfoBuilder::new();
for datum in data {
if let Some(field) = INFO_FIELDS.get(&datum) {
match info.find(field).and_then(|f| f.as_string()) {
match info.find(field).and_then(Json::as_str) {
Some(value) => { result.set(datum, value); },
None => { warn!("Missing info key '{}' in gist JSON", field); },
}
@@ -237,9 +237,7 @@ pub fn gist_name_from_info(info: &Json) -> Option<&str> {
/// Retrieve gist owner from the parsed JSON of gist info.
/// This may be an anonymous name.
pub fn gist_owner_from_info(info: &Json) -> &str {
info.find_path(&["owner", "login"])
.and_then(|l| l.as_string())
.unwrap_or(ANONYMOUS)
info.find_path(&["owner", "login"]).and_then(Json::as_str).unwrap_or(ANONYMOUS)
}
@@ -111,7 +111,7 @@ pub fn clone_gist<G: AsRef<Gist>>(gist: G) -> io::Result<()> {
None => {
trace!("Need to get clone URL from GitHub for gist {}", gist.uri);
let info = try!(api::get_gist_info(&gist.id.as_ref().unwrap()));
let url = match info.find("git_pull_url").and_then(|u| u.as_string()) {
let url = match info.find("git_pull_url").and_then(|u| u.as_str()) {
Some(url) => url.to_owned(),
None => {
error!("Gist info for {} doesn't contain git_pull_url", gist.uri);
View
@@ -1,10 +1,11 @@
//! Utility functions shared by multiple other modules.
use std::io::Read;
use std::str::FromStr;
use hyper::client::Response;
use hyper::header::ContentLength;
use rustc_serialize::json::Json;
use serde_json::Value as Json;
/// Read HTTP response from hyper and parse it as JSON.
View
@@ -14,7 +14,7 @@
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate maplit;
extern crate regex;
extern crate rustc_serialize;
extern crate serde_json;
extern crate shlex;
extern crate slog_envlogger;
extern crate slog_stdlog;

0 comments on commit a0655a6

Please sign in to comment.