Created
February 24, 2011 09:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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