Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Migrate to serde_json (fix #1)
  • Loading branch information
Xion committed Jan 7, 2017
1 parent 10655c5 commit a0655a6
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
32 changes: 31 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/hosts/github/api.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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); },
}
Expand Down Expand Up @@ -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)
}


Expand Down
2 changes: 1 addition & 1 deletion src/hosts/github/storage.rs
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/hosts/github/util.rs
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Expand Up @@ -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;
Expand Down

0 comments on commit a0655a6

Please sign in to comment.