summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-01-17 21:44:30 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2010-01-17 21:44:30 -0800
commita16b9b9222da75b43a44cfde9de912bba4c09670 (patch)
tree5429e7a464fa77bf61ce111efe686183745e3537 /samples/DotNetOpenAuth.ApplicationBlock
parent9a77154c54439bacd06938e2c0624c69d4e48c69 (diff)
parentcdb850c6cf90381e6db75365272b7d65ef5fe359 (diff)
downloadDotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.zip
DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.tar.gz
DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.tar.bz2
Merge branch 'master' into master-Dev10
Conflicts: build.proj lib/DotNetOpenAuth.BuildTasks.dll lib/DotNetOpenAuth.BuildTasks.pdb src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs src/DotNetOpenAuth.sln src/DotNetOpenAuth.vsmdi src/DotNetOpenAuth/OAuth/OAuthStrings.Designer.cs
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
index 2a98ffe..29973c2 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
@@ -8,6 +8,7 @@ namespace DotNetOpenAuth.ApplicationBlock {
using System;
using System.Collections.Generic;
using System.IO;
+ using System.Net;
using System.Xml;
using System.Xml.Linq;
using DotNetOpenAuth.Messaging;
@@ -38,6 +39,18 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// </summary>
private static readonly MessageReceivingEndpoint GetFriendTimelineStatusEndpoint = new MessageReceivingEndpoint("http://twitter.com/statuses/friends_timeline.xml", HttpDeliveryMethods.GetRequest);
+ private static readonly MessageReceivingEndpoint UpdateProfileBackgroundImageEndpoint = new MessageReceivingEndpoint("http://twitter.com/account/update_profile_background_image.xml", HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);
+
+ private static readonly MessageReceivingEndpoint UpdateProfileImageEndpoint = new MessageReceivingEndpoint("http://twitter.com/account/update_profile_image.xml", HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);
+
+ /// <summary>
+ /// Initializes static members of the <see cref="TwitterConsumer"/> class.
+ /// </summary>
+ static TwitterConsumer() {
+ // Twitter can't handle the Expect 100 Continue HTTP header.
+ ServicePointManager.FindServicePoint(GetFavoritesEndpoint.Location).Expect100Continue = false;
+ }
+
public static XDocument GetUpdates(ConsumerBase twitter, string accessToken) {
IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFriendTimelineStatusEndpoint, accessToken);
return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
@@ -47,5 +60,32 @@ namespace DotNetOpenAuth.ApplicationBlock {
IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFavoritesEndpoint, accessToken);
return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
}
+
+ public static XDocument UpdateProfileBackgroundImage(ConsumerBase twitter, string accessToken, string image, bool tile) {
+ var parts = new[] {
+ MultipartPostPart.CreateFormFilePart("image", image, "image/" + Path.GetExtension(image).Substring(1).ToLowerInvariant()),
+ MultipartPostPart.CreateFormPart("tile", tile.ToString().ToLowerInvariant()),
+ };
+ HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateProfileBackgroundImageEndpoint, accessToken, parts);
+ request.ServicePoint.Expect100Continue = false;
+ IncomingWebResponse response = twitter.Channel.WebRequestHandler.GetResponse(request);
+ string responseString = response.GetResponseReader().ReadToEnd();
+ return XDocument.Parse(responseString);
+ }
+
+ public static XDocument UpdateProfileImage(ConsumerBase twitter, string accessToken, string pathToImage) {
+ string contentType = "image/" + Path.GetExtension(pathToImage).Substring(1).ToLowerInvariant();
+ return UpdateProfileImage(twitter, accessToken, File.OpenRead(pathToImage), contentType);
+ }
+
+ public static XDocument UpdateProfileImage(ConsumerBase twitter, string accessToken, Stream image, string contentType) {
+ var parts = new[] {
+ MultipartPostPart.CreateFormFilePart("image", "twitterPhoto", contentType, image),
+ };
+ HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateProfileImageEndpoint, accessToken, parts);
+ IncomingWebResponse response = twitter.Channel.WebRequestHandler.GetResponse(request);
+ string responseString = response.GetResponseReader().ReadToEnd();
+ return XDocument.Parse(responseString);
+ }
}
}