using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
string json = GetJson(new Uri("https://api.bitbucket.org/1.0/repositories/linn_fedor/virtualprinter/branches"), "NotMyUsername", "NotMyPassword_;)");
JObject jobj = (JObject)JsonConvert.DeserializeObject(json);
var branches = new List<Branch>();
foreach (var property in jobj.Properties())
branches.Add(JsonConvert.DeserializeObject<Branch>(property.Value.ToString()));
Console.WriteLine("Branch: " + branches[2].Name);
Console.WriteLine("Revision: " + branches[2].Revision);
Console.WriteLine("Author: " + branches[2].Author);
Console.WriteLine("Commit: " + branches[2].Message);
Console.WriteLine("Files: " + branches[2].Files.Count());
Console.WriteLine("File {0}: " + branches[2].Files[0].Name + " (" + branches[2].Files[0].Type + ")");
Console.WriteLine("File {1}: " + branches[2].Files[1].Name + " (" + branches[2].Files[1].Type +")");
public static string GetJson(Uri request, string user, string password)
string autorization = string.Concat(user, ":", password);
byte[] binaryAuthorization = System.Text.Encoding.UTF8.GetBytes(autorization);
autorization = Convert.ToBase64String(binaryAuthorization);
autorization = "Basic " + autorization;
var webRequest = (HttpWebRequest)WebRequest.Create(request);
webRequest.Method = "GET";
webRequest.ContentType = "application/json";
webRequest.ContentLength = 0;
webRequest.Headers.Add("AUTHORIZATION", autorization);
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK)
Console.WriteLine("{0}", webResponse.Headers);
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
json = reader.ReadToEnd();
public string Node { get; set; }
public List<File> Files = new List<File>();
[JsonProperty("raw_author")]
public string RawAuthor { get; set; }
public string UtcTimestamp { get; set; }
public string Author { get; set; }
public string Timestamp { get; set; }
[JsonProperty("raw_node")]
public string RawNode { get; set; }
public List<string> parents = new List<string>();
public string Name { get; set; }
public string Message { get; set; }
public int Revision { get; set; }
public int Size { get; set; }
public string Type { get; set; }
public string Name { get; set; }