Skip to content
Browse files

Support feed subscription in GoogleReader.API

  • Loading branch information...
1 parent 6e85404 commit be5e3ff1eb7c1878ce8b3b0359f0e29150c19b95 @igstan committed Oct 25, 2010
View
20 GoogleReader.API.Tests/GoogleReaderTest.cs
@@ -14,6 +14,7 @@ public class GoogleReaderTest
{
SubscriptionList = "subscriptions-url",
SubscriptionItems = "subscription-items-url",
+ AddSubscription = "add-subscription",
};
[Test]
@@ -94,6 +95,19 @@ public void CanParseRssBasedSubscriptionItems()
Assert.AreEqual("Dummy Content", reader.ItemsForSubscription(subscription).ElementAt(0).Content);
}
+ [Test]
+ public void CanAddNewSubscription()
+ {
+ var httpClient = new StubHttpClient()
+ {
+ ExpectedUrl = endpointUrls.AddSubscription,
+ ExpectedResponse = "",
+ };
+
+ var reader = new ReaderAccount(httpClient, endpointUrls);
+ reader.AddSubscription("http://feeds.feedburner.com/ajaxian");
+ }
+
class StubHttpClient : HttpClient
{
public string ExpectedUrl { get; set; }
@@ -111,6 +125,12 @@ public string GET(string url, IDictionary<string, string> args)
Assert.AreEqual(ExpectedUrl, url);
return ExpectedResponse;
}
+
+ public string POST(string url, IDictionary<string, string> args)
+ {
+ Assert.AreEqual(ExpectedUrl, url);
+ return ExpectedResponse;
+ }
}
}
}
View
14 GoogleReader.API/AuthorizedHttpClient.cs
@@ -31,6 +31,16 @@ public override string GET(string url, IDictionary<string, string> args, IDictio
return base.GET(url, args, headers);
}
+ public override string POST(string url, IDictionary<string, string> args, IDictionary<string, string> headers)
+ {
+ if (NotAuthorized()) Authorize();
+
+ args.Add("T", readerToken);
+ headers.Add("Authorization", String.Format("GoogleLogin auth={0}", authToken));
+
+ return base.POST(url, args, headers);
+ }
+
private bool NotAuthorized()
{
return authToken == null && readerToken == null;
@@ -44,13 +54,13 @@ private void Authorize()
private string Authenticate(string email, string password)
{
- var response = POST(LOGIN_URL, new Dictionary<string, string>()
+ var response = base.POST(LOGIN_URL, new Dictionary<string, string>()
{
{"Email", email},
{"Passwd", password},
{"source", "cli-script"},
{"service", "reader"},
- });
+ }, new Dictionary<string, string>() { });
return response.Split('\n')[2].Split('=')[1];
}
View
1 GoogleReader.API/HttpClient.cs
@@ -9,5 +9,6 @@ public interface HttpClient
{
string GET(string url);
string GET(string url, IDictionary<string, string> args);
+ string POST(string url, IDictionary<string, string> args);
}
}
View
10 GoogleReader.API/ReaderAccount.cs
@@ -100,5 +100,15 @@ private SubscriptionItem CreateSubscriptionItem(JsonSubscriptionItem item)
SourceUrl = sourceUrl,
};
}
+
+ public void AddSubscription(string subscriptionUrl)
+ {
+ var args = new Dictionary<string, string>()
+ {
+ {"quickadd", subscriptionUrl},
+ };
+
+ httpClient.POST(urls.AddSubscription, args);
+ }
}
}
View
1 GoogleReader.API/ReaderUrls.cs
@@ -9,5 +9,6 @@ public class ReaderUrls
{
public string SubscriptionList = "https://www.google.com/reader/api/0/subscription/list";
public string SubscriptionItems = "https://www.google.com/reader/api/0/stream/contents/";
+ public string AddSubscription = "http://www.google.com/reader/api/0/subscription/quickadd";
}
}

0 comments on commit be5e3ff

Please sign in to comment.
Something went wrong with that request. Please try again.