@@ -55,18 +55,18 @@ public static class TwitterConsumer {
5555 /// <summary>
5656 /// The URI to get a user's favorites.
5757 /// </summary>
58- private static readonly MessageReceivingEndpoint GetFavoritesEndpoint = new MessageReceivingEndpoint ( "http://twitter.com/favorites.xml" , HttpDeliveryMethods . GetRequest ) ;
58+ private static readonly Uri GetFavoritesEndpoint = new Uri ( "http://twitter.com/favorites.xml" ) ;
5959
6060 /// <summary>
6161 /// The URI to get the data on the user's home page.
6262 /// </summary>
63- private static readonly MessageReceivingEndpoint GetFriendTimelineStatusEndpoint = new MessageReceivingEndpoint ( "https://api.twitter.com/1.1/statuses/home_timeline.json" , HttpDeliveryMethods . GetRequest ) ;
63+ private static readonly Uri GetFriendTimelineStatusEndpoint = new Uri ( "https://api.twitter.com/1.1/statuses/home_timeline.json" ) ;
6464
65- private static readonly MessageReceivingEndpoint UpdateProfileBackgroundImageEndpoint = new MessageReceivingEndpoint ( "http://twitter.com/account/update_profile_background_image.xml" , HttpDeliveryMethods . PostRequest | HttpDeliveryMethods . AuthorizationHeaderRequest ) ;
65+ private static readonly Uri UpdateProfileBackgroundImageEndpoint = new Uri ( "http://twitter.com/account/update_profile_background_image.xml" ) ;
6666
67- private static readonly MessageReceivingEndpoint UpdateProfileImageEndpoint = new MessageReceivingEndpoint ( "http://twitter.com/account/update_profile_image.xml" , HttpDeliveryMethods . PostRequest | HttpDeliveryMethods . AuthorizationHeaderRequest ) ;
67+ private static readonly Uri UpdateProfileImageEndpoint = new Uri ( "http://twitter.com/account/update_profile_image.xml" ) ;
6868
69- private static readonly MessageReceivingEndpoint VerifyCredentialsEndpoint = new MessageReceivingEndpoint ( "http://api.twitter.com/1/account/verify_credentials.xml" , HttpDeliveryMethods . GetRequest | HttpDeliveryMethods . AuthorizationHeaderRequest ) ;
69+ private static readonly Uri VerifyCredentialsEndpoint = new Uri ( "http://api.twitter.com/1/account/verify_credentials.xml" ) ;
7070
7171 /// <summary>
7272 /// The consumer used for the Sign in to Twitter feature.
@@ -83,7 +83,7 @@ public static class TwitterConsumer {
8383 /// </summary>
8484 static TwitterConsumer ( ) {
8585 // Twitter can't handle the Expect 100 Continue HTTP header.
86- ServicePointManager . FindServicePoint ( GetFavoritesEndpoint . Location ) . Expect100Continue = false ;
86+ ServicePointManager . FindServicePoint ( GetFavoritesEndpoint ) . Expect100Continue = false ;
8787 }
8888
8989 /// <summary>
@@ -136,7 +136,7 @@ private static InMemoryTokenManager ShortTermUserSessionTokenManager {
136136 public static async Task < JArray > GetUpdatesAsync (
137137 ConsumerBase twitter , string accessToken , CancellationToken cancellationToken = default ( CancellationToken ) ) {
138138 using ( var httpClient = twitter . CreateHttpClient ( accessToken ) ) {
139- using ( var response = await httpClient . GetAsync ( GetFriendTimelineStatusEndpoint . Location , cancellationToken ) ) {
139+ using ( var response = await httpClient . GetAsync ( GetFriendTimelineStatusEndpoint , cancellationToken ) ) {
140140 response . EnsureSuccessStatusCode ( ) ;
141141 string jsonString = await response . Content . ReadAsStringAsync ( ) ;
142142 var json = JArray . Parse ( jsonString ) ;
@@ -146,9 +146,9 @@ public static async Task<JArray> GetUpdatesAsync(
146146 }
147147
148148 public static async Task < XDocument > GetFavorites ( ConsumerBase twitter , string accessToken , CancellationToken cancellationToken = default ( CancellationToken ) ) {
149- var request = await twitter . PrepareAuthorizedRequestAsync ( GetFavoritesEndpoint , accessToken , cancellationToken ) ;
150- using ( var httpClient = twitter . Channel . HostFactories . CreateHttpClient ( ) ) {
151- using ( HttpResponseMessage response = await httpClient . SendAsync ( request ) ) {
149+ using ( var httpClient = twitter . CreateHttpClient ( accessToken ) ) {
150+ using ( HttpResponseMessage response = await httpClient . GetAsync ( GetFavoritesEndpoint , cancellationToken ) ) {
151+ response . EnsureSuccessStatusCode ( ) ;
152152 return XDocument . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
153153 }
154154 }
@@ -157,14 +157,15 @@ public static async Task<JArray> GetUpdatesAsync(
157157 public static async Task < XDocument > UpdateProfileBackgroundImageAsync ( ConsumerBase twitter , string accessToken , string image , bool tile , CancellationToken cancellationToken ) {
158158 var imageAttachment = new StreamContent ( File . OpenRead ( image ) ) ;
159159 imageAttachment . Headers . ContentType = new MediaTypeHeaderValue ( "image/" + Path . GetExtension ( image ) . Substring ( 1 ) . ToLowerInvariant ( ) ) ;
160- var parts = new List < MultipartContentMember > {
161- new MultipartContentMember ( imageAttachment , "image" ) ,
162- new MultipartContentMember ( new StringContent ( tile . ToString ( ) . ToLowerInvariant ( ) ) , "tile" ) ,
163- } ;
164- HttpRequestMessage request = await twitter . PrepareAuthorizedRequestAsync ( UpdateProfileBackgroundImageEndpoint , accessToken , parts , cancellationToken ) ;
160+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , UpdateProfileBackgroundImageEndpoint ) ;
161+ var content = new MultipartFormDataContent ( ) ;
162+ content . Add ( imageAttachment , "image" ) ;
163+ content . Add ( new StringContent ( tile . ToString ( ) . ToLowerInvariant ( ) ) , "tile" ) ;
164+ request . Content = content ;
165165 request . Headers . ExpectContinue = false ;
166- using ( var httpClient = twitter . Channel . HostFactories . CreateHttpClient ( ) ) {
167- using ( HttpResponseMessage response = await httpClient . SendAsync ( request ) ) {
166+ using ( var httpClient = twitter . CreateHttpClient ( accessToken ) ) {
167+ using ( HttpResponseMessage response = await httpClient . SendAsync ( request , cancellationToken ) ) {
168+ response . EnsureSuccessStatusCode ( ) ;
168169 string responseString = await response . Content . ReadAsStringAsync ( ) ;
169170 return XDocument . Parse ( responseString ) ;
170171 }
@@ -179,23 +180,23 @@ public static async Task<XDocument> UpdateProfileBackgroundImageAsync(ConsumerBa
179180 public static async Task < XDocument > UpdateProfileImageAsync ( ConsumerBase twitter , string accessToken , Stream image , string contentType , CancellationToken cancellationToken = default ( CancellationToken ) ) {
180181 var imageAttachment = new StreamContent ( image ) ;
181182 imageAttachment . Headers . ContentType = new MediaTypeHeaderValue ( contentType ) ;
182- var parts = new List < MultipartContentMember > {
183- new MultipartContentMember ( imageAttachment , "image" , "twitterPhoto" ) ,
184- } ;
185-
186- HttpRequestMessage request = await twitter . PrepareAuthorizedRequestAsync ( UpdateProfileImageEndpoint , accessToken , parts , cancellationToken ) ;
187- using ( var httpClient = twitter . Channel . HostFactories . CreateHttpClient ( ) ) {
188- using ( HttpResponseMessage response = await httpClient . SendAsync ( request ) ) {
183+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , UpdateProfileImageEndpoint ) ;
184+ var content = new MultipartFormDataContent ( ) ;
185+ content . Add ( imageAttachment , "image" , "twitterPhoto" ) ;
186+ request . Content = content ;
187+ using ( var httpClient = twitter . CreateHttpClient ( accessToken ) ) {
188+ using ( HttpResponseMessage response = await httpClient . SendAsync ( request , cancellationToken ) ) {
189+ response . EnsureSuccessStatusCode ( ) ;
189190 string responseString = await response . Content . ReadAsStringAsync ( ) ;
190191 return XDocument . Parse ( responseString ) ;
191192 }
192193 }
193194 }
194195
195196 public static async Task < XDocument > VerifyCredentialsAsync ( ConsumerBase twitter , string accessToken , CancellationToken cancellationToken = default ( CancellationToken ) ) {
196- var request = await twitter . PrepareAuthorizedRequestAsync ( VerifyCredentialsEndpoint , accessToken , cancellationToken ) ;
197- using ( var httpClient = twitter . Channel . HostFactories . CreateHttpClient ( ) ) {
198- using ( var response = await httpClient . SendAsync ( request ) ) {
197+ using ( var httpClient = twitter . CreateHttpClient ( accessToken ) ) {
198+ using ( var response = await httpClient . GetAsync ( VerifyCredentialsEndpoint , cancellationToken ) ) {
199+ response . EnsureSuccessStatusCode ( ) ;
199200 using ( var stream = await response . Content . ReadAsStreamAsync ( ) ) {
200201 return XDocument . Load ( XmlReader . Create ( stream ) ) ;
201202 }
0 commit comments