<commit_before>
use self::super::Github;
use rustc_serialize::json;
use std::io::Result;
use rep::{Gist, GistFork, GistReq};

/// reference to gists associated with a github user
pub struct UserGists<'a> {
  github: &'a Github<'a>,
  owner: &'static str,
}

impl<'a> UserGists<'a> {

  pub fn new(github: &'a Github<'a>, owner: &'static str) -> UserGists<'a> {
    UserGists { github: github, owner: owner }
  }

  pub fn list(&self) -> Result<Vec<Gist>> {
    let body = try!(
      self.github.get(
        &format!("/users/{}/gists", self.owner)
      )
    );
    Ok(json::decode::<Vec<Gist>>(&body).unwrap())
  }
}

pub struct Gists<'a> {
  github: &'a Github<'a>
}

impl<'a> Gists<'a> {
  pub fn new(github: &'a Github<'a>) -> Gists<'a> {
    Gists { github: github }
  }

  fn path(&self, more: &str) -> String {
    format!("/gists{}", more)
  }

  pub fn star(&self, id: &'static str) -> Result<()> {
    let body = try!(
      self.github.put(
        &self.path(
          &format!("/{}/star", id)
        ),
        &[]
      )
    );
    Ok(())
  }

  pub fn unstar(&self, id: &'static str) -> Result<()> {
    let body = try!(
      self.github.delete(
        &self.path(
          &format!("/{}/star", id)
        )
      )
    );
    Ok(())
  }

  pub fn fork(&self, id: &'static str) -> Result<Gist> {
    let body = try!(
      self.github.post(
        &self.path(
          &format!("/{}/forks", id)
        ),
        &[]
      )
    );
    Ok(json::decode::<Gist>(&body).unwrap())
  }

  pub fn forks(&self, id: &'static str) -> Result<Vec<GistFork>> {
    let body = try!(
      self.github.get(
        &self.path(
          &format!("/{}/forks", id)
        )
      )
        );
    Ok(json::decode::<Vec<GistFork>>(&body).unwrap())
  }

  pub fn delete(&self, id: &'static str) -> Result<()> {
    let body = try!(
      self.github.delete(
        &self.path(
          &format!("/{}", id)
        )
      )
    );
    Ok(())
  }

  pub fn get(&self, id: &'static str) -> Result<Gist> {
    let body = try!(
      self.github.get(
        &self.path(
          &format!("/{}", id)
        )
      )
    );
    Ok(json::decode::<Gist>(&body).unwrap())
  }

  pub fn getrev(&self, id: &'static str, sha: &'static str) -> Result<Gist> {
    let body = try!(
      self.github.get(
        &self.path(
          &format!("/{}/{}", id, sha)
        )
      )
    );
    Ok(json::decode::<Gist>(&body).unwrap())
  }<commit_msg>simplify gists<commit_after>
use self::super::Github;
use rustc_serialize::json;
use std::io::Result;
use rep::{Gist, GistFork, GistReq};

/// reference to gists associated with a github user
pub struct UserGists<'a> {
  github: &'a Github<'a>,
  owner: &'static str,
}

impl<'a> UserGists<'a> {

  pub fn new(github: &'a Github<'a>, owner: &'static str) -> UserGists<'a> {
    UserGists { github: github, owner: owner }
  }

  pub fn list(&self) -> Result<Vec<Gist>> {
    let body = try!(
      self.github.get(
        &format!("/users/{}/gists", self.owner)
      )
    );
    Ok(json::decode::<Vec<Gist>>(&body).unwrap())
  }
}

pub struct Gists<'a> {
  github: &'a Github<'a>
}

impl<'a> Gists<'a> {
  pub fn new(github: &'a Github<'a>) -> Gists<'a> {
    Gists { github: github }
  }

  fn path(&self, more: &str) -> String {
    format!("/gists{}", more)
  }

  pub fn star(&self, id: &'static str) -> Result<()> {
    self.github.put(
      &self.path(
        &format!("/{}/star", id)
      ),
      &[]
    ).map(|_| ())
  }

  pub fn unstar(&self, id: &'static str) -> Result<()> {
    self.github.delete(
      &self.path(
        &format!("/{}/star", id)
      )
    ).map(|_| ())
  }

  pub fn fork(&self, id: &'static str) -> Result<Gist> {
    let body = try!(
      self.github.post(
        &self.path(
          &format!("/{}/forks", id)
        ),
        &[]
      )
    );
    Ok(json::decode::<Gist>(&body).unwrap())
  }

  pub fn forks(&self, id: &'static str) -> Result<Vec<GistFork>> {
    let body = try!(
      self.github.get(
        &self.path(
          &format!("/{}/forks", id)
        )
      )
        );
    Ok(json::decode::<Vec<GistFork>>(&body).unwrap())
  }

  pub fn delete(&self, id: &'static str) -> Result<()> {
    self.github.delete(
      &self.path(
        &format!("/{}", id)
      )
    ).map(|_| ())
  }

  pub fn get(&self, id: &'static str) -> Result<Gist> {
    let body = try!(
      self.github.get(
        &self.path(
          &format!("/{}", id)
        )
      )
    );
    Ok(json::decode::<Gist>(&body).unwrap())
  }

  pub fn getrev(&self, id: &'static str, sha: &'static str) -> Result<Gist> {
    let body = try!(
      self.github.get(
        &self.path(
          &format!("/{}/{}", id, sha)
        )
      )
    );
    Ok(json::decode::<Gist>(&body).unwrap())
  }
{'fraction_non_alphanumeric': 0.21938988717091518, 'fraction_numerical': 0.0, 'mean_word_length': 2.136959370904325, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1620143', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1843, 'n_words': 368}