Skip to content

Instantly share code, notes, and snippets.

@preslavrachev
Created February 24, 2011 09:15
Show Gist options
  • Save preslavrachev/841951 to your computer and use it in GitHub Desktop.
Save preslavrachev/841951 to your computer and use it in GitHub Desktop.
A simple console utility for browsing and searching Github's Gist ... not fully finished, due to limitations in the API
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;
namespace gist
{
public class GistManager
{
protected List<String> repos;
StringBuilder jsonString = new StringBuilder();
public GistManager(String username)
{
byte[] buffer = new byte[8192];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://gist.github.com/api/v1/json/gists/"+username);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
int count = 0;
String tempString;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
tempString = Encoding.ASCII.GetString(buffer, 0, count);
jsonString.Append(tempString);
} while (count > 0);
repos = getRepos(jsonString.ToString());
}
public List<String> getRepos(String jsonString)
{
JObject o = JObject.Parse(jsonString);
List<String> results = o.SelectToken("gists").Select(m => (String)m.SelectToken("repo")).ToList();
return results;
}
public void Search(String searchPhrase)
{
//to be implemented
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment