Skip to content

Commit a0655a6

Browse files
committed
Migrate to serde_json (fix #1)
1 parent 10655c5 commit a0655a6

File tree

7 files changed

+44
-15
lines changed

7 files changed

+44
-15
lines changed

Cargo.lock

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ lazy_static = "*"
2424
log = "0.3"
2525
maplit = "0.1"
2626
regex = "0.1"
27-
rustc-serialize = "0.3"
27+
serde_json = "0.8.4"
2828
shlex = "0.1.1"
2929
slog = "*"
3030
slog-envlogger = "0.5"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ Magic!
1515
## Usage
1616

1717
gisht [OPTIONS] [SUBCOMMAND]
18-
18+
1919
OPTIONS:
2020
-c, --cached Operate only on gists available locally
2121
-f, --fetch Always fetch the gist from a remote host
2222
-v, --verbose Increase logging verbosity
2323
-q, --quiet Decrease logging verbosity
2424
-H, --help Prints help information
2525
-V, --version Prints version information
26-
26+
2727
SUBCOMMANDS:
2828
run Run the specified gist [aliases: exec]
2929
which Output the path to gist's binary
3030
print Print the source code of gist's binary [aliases: cat]
3131
open Open the gist's webpage [aliases: show]
3232
info Display summary information about the gist [aliases: stat]
3333
help Prints this message or the help of the given subcommand(s)
34-
34+
3535
Hint: `gisht run GIST` can be shortened to just `gisht GIST`.
3636
If you want to pass arguments, put them after `--` (two dashes), like this:
37-
37+
3838
gisht Octocat/greet -- "Hello world" --cheerful
3939

4040
## Installation

src/hosts/github/api.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io;
55

66
use hyper::client::{Client, Response};
77
use hyper::header::UserAgent;
8-
use rustc_serialize::json::Json;
8+
use serde_json::Value as Json;
99
use url::Url;
1010

1111
use ::USER_AGENT;
@@ -146,7 +146,7 @@ impl<'o> GistsIterator<'o> {
146146

147147
/// Convert a JSON representation of the gist into a Gist object.
148148
fn gist_from_json(&self, gist: &Json) -> Option<Gist> {
149-
let id = gist["id"].as_string().unwrap();
149+
let id = gist.pointer("id").and_then(Json::as_str).unwrap();
150150
let name = match gist_name_from_info(&gist) {
151151
Some(name) => name,
152152
None => {
@@ -201,7 +201,7 @@ pub fn build_gist_info(info: &Json, data: &[Datum]) -> gist::Info {
201201
let mut result = gist::InfoBuilder::new();
202202
for datum in data {
203203
if let Some(field) = INFO_FIELDS.get(&datum) {
204-
match info.find(field).and_then(|f| f.as_string()) {
204+
match info.find(field).and_then(Json::as_str) {
205205
Some(value) => { result.set(datum, value); },
206206
None => { warn!("Missing info key '{}' in gist JSON", field); },
207207
}
@@ -237,9 +237,7 @@ pub fn gist_name_from_info(info: &Json) -> Option<&str> {
237237
/// Retrieve gist owner from the parsed JSON of gist info.
238238
/// This may be an anonymous name.
239239
pub fn gist_owner_from_info(info: &Json) -> &str {
240-
info.find_path(&["owner", "login"])
241-
.and_then(|l| l.as_string())
242-
.unwrap_or(ANONYMOUS)
240+
info.find_path(&["owner", "login"]).and_then(Json::as_str).unwrap_or(ANONYMOUS)
243241
}
244242

245243

src/hosts/github/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn clone_gist<G: AsRef<Gist>>(gist: G) -> io::Result<()> {
111111
None => {
112112
trace!("Need to get clone URL from GitHub for gist {}", gist.uri);
113113
let info = try!(api::get_gist_info(&gist.id.as_ref().unwrap()));
114-
let url = match info.find("git_pull_url").and_then(|u| u.as_string()) {
114+
let url = match info.find("git_pull_url").and_then(|u| u.as_str()) {
115115
Some(url) => url.to_owned(),
116116
None => {
117117
error!("Gist info for {} doesn't contain git_pull_url", gist.uri);

src/hosts/github/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Utility functions shared by multiple other modules.
22
33
use std::io::Read;
4+
use std::str::FromStr;
45

56
use hyper::client::Response;
67
use hyper::header::ContentLength;
7-
use rustc_serialize::json::Json;
8+
use serde_json::Value as Json;
89

910

1011
/// Read HTTP response from hyper and parse it as JSON.

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#[macro_use] extern crate lazy_static;
1515
#[macro_use] extern crate maplit;
1616
extern crate regex;
17-
extern crate rustc_serialize;
17+
extern crate serde_json;
1818
extern crate shlex;
1919
extern crate slog_envlogger;
2020
extern crate slog_stdlog;

0 commit comments

Comments
 (0)