Created
June 1, 2010 21:45
-
-
Save orjan/421553 to your computer and use it in GitHub Desktop.
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
public class GoogleSpreadsheetRowReader | |
{ | |
private readonly SpreadsheetsService service; | |
public GoogleSpreadsheetRowReader(string username, string password) | |
{ | |
service = new SpreadsheetsService("google-spreadsheet-reader"); | |
service.setUserCredentials(username, password); | |
} | |
public IEnumerable<Row> GetRows(string url) | |
{ | |
ListFeed feed = service.Query(new ListQuery(url)); | |
foreach (ListEntry worksheetRow in feed.Entries) | |
{ | |
var elements = worksheetRow.Elements; | |
var row = new Row(); | |
foreach (ListEntry.Custom element in elements) | |
{ | |
row.Add(element.LocalName, element.Value); | |
} | |
yield return row; | |
} | |
} | |
} | |
public class Row | |
{ | |
private readonly IDictionary<string, string> map = new Dictionary<string, string>(); | |
public string this[string key] | |
{ | |
get { return map.ContainsKey(key) ? map[key] : null; } | |
} | |
public void Add(string key, string value) | |
{ | |
map.Add(key, value); | |
} | |
} | |
public static class ListEntryExtensions | |
{ | |
public static IDictionary<string, string> Row(this ListEntry.CustomElementCollection elements) | |
{ | |
var dictionary = new Dictionary<string, string>(); | |
foreach (ListEntry.Custom element in elements) | |
{ | |
dictionary.Add(element.LocalName, element.Value); | |
} | |
return dictionary; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment