Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
digitallyborn committed May 11, 2010
1 parent f54c4bd commit e7135a6
Show file tree
Hide file tree
Showing 57 changed files with 714 additions and 524 deletions.
7 changes: 7 additions & 0 deletions Json.NET.license.txt
@@ -0,0 +1,7 @@
Copyright (c) 2007 James Newton-King

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion Twitterizer-Desktop/MainForm.cs
Expand Up @@ -122,7 +122,7 @@ private void AuthorizeAndGetUser()
ConsumerSecret = ConfigurationManager.AppSettings["Twitterizer.Desktop.ConsumerSecret"]
};

ulong userId = ulong.Parse(ConfigurationManager.AppSettings["Twitterizer.Desktop.UserId"]);
decimal userId = decimal.Parse(ConfigurationManager.AppSettings["Twitterizer.Desktop.UserId"]);

try
{
Expand Down
4 changes: 2 additions & 2 deletions Twitterizer-Web/followers.aspx.cs
Expand Up @@ -44,8 +44,8 @@ protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ulong userId = 0;
if (!string.IsNullOrEmpty(Request.QueryString["userid"]) && ulong.TryParse(Request.QueryString["userid"], out userId))
decimal userId = 0;
if (!string.IsNullOrEmpty(Request.QueryString["userid"]) && decimal.TryParse(Request.QueryString["userid"], out userId))
{
this.FollowersCollection = TwitterFriendship.Followers(Master.Tokens, userId);
}
Expand Down
4 changes: 2 additions & 2 deletions Twitterizer-Web/friends.aspx.cs
Expand Up @@ -43,9 +43,9 @@ protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ulong userId = 0;
decimal userId = 0;

if (!string.IsNullOrEmpty(Request.QueryString["userid"]) && ulong.TryParse(Request.QueryString["userid"], out userId))
if (!string.IsNullOrEmpty(Request.QueryString["userid"]) && decimal.TryParse(Request.QueryString["userid"], out userId))
{
this.FriendsCollection = TwitterFriendship.Friends(Master.Tokens, userId);
}
Expand Down
4 changes: 2 additions & 2 deletions Twitterizer-Web/user.aspx.cs
Expand Up @@ -40,9 +40,9 @@ public partial class user : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ulong userId = 0;
decimal userId = 0;

if (string.IsNullOrEmpty(Request.QueryString["id"]) || !ulong.TryParse(Request.QueryString["id"], out userId))
if (string.IsNullOrEmpty(Request.QueryString["id"]) || !decimal.TryParse(Request.QueryString["id"], out userId))
{
Response.Redirect("~/", true);
}
Expand Down
13 changes: 13 additions & 0 deletions Twitterizer2/Core/CursorPagedCommand.cs
Expand Up @@ -50,11 +50,24 @@ internal abstract class CursorPagedCommand<T> : TwitterCommand<T>
/// <param name="method">The method.</param>
/// <param name="uri">The URI for the API method.</param>
/// <param name="tokens">The request tokens.</param>
[Obsolete]
protected CursorPagedCommand(string method, Uri uri, OAuthTokens tokens)
: base(method, uri, tokens)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CursorPagedCommand&lt;T&gt;"/> class.
/// </summary>
/// <param name="method">The method.</param>
/// <param name="endPoint">The end point.</param>
/// <param name="tokens">The tokens.</param>
/// <param name="options">The options.</param>
protected CursorPagedCommand(string method, string endPoint, OAuthTokens tokens, OptionalProperties options)
: base(method, endPoint, tokens, options)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CursorPagedCommand&lt;T&gt;"/> class.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Twitterizer2/Core/RequestStatus.cs
Expand Up @@ -217,7 +217,7 @@ public static bool UpdateRequestStatus(HttpWebResponse webResponse)

if (webResponse.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
{
LastRequestStatus.ErrorDetails = SerializationHelper<TwitterErrorDetails>.Deserialize(webResponse, Serializer.JSONdotNet, null);
LastRequestStatus.ErrorDetails = SerializationHelper<TwitterErrorDetails>.Deserialize(webResponse);
}
}
catch (System.Runtime.Serialization.SerializationException)
Expand Down
77 changes: 42 additions & 35 deletions Twitterizer2/Core/SerializationHelper.cs
Expand Up @@ -38,24 +38,8 @@ namespace Twitterizer.Core
using System.IO;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
using Newtonsoft.Json;

/// <summary>
/// Supported serialization schemes
/// </summary>
internal enum Serializer
{
/// <summary>
/// Utilizes the Newtonsoft.Json library for serialization
/// </summary>
JSONdotNet,

/// <summary>
/// Utilizes the AJAX JavaScript serialization classes for semi-manual JSON parsing.
/// </summary>
JavaScriptSerializer
}
using Newtonsoft.Json.Linq;

/// <summary>
/// The Serialization Helper class. Provides a simple interface for common serialization tasks.
Expand All @@ -69,16 +53,17 @@ internal static class SerializationHelper<T>
/// </summary>
/// <param name="value">Contains nested dictionary objects containing deserialized values for manual parsing.</param>
/// <returns>A strongly typed object representing the deserialized data of type <typeparamref name="T"/></returns>
public delegate T JavascriptConversionDelegate(object value);
public delegate T DeserializationHandler(JObject value);

/// <summary>
/// Deserializes the specified web response.
/// </summary>
/// <param name="webResponse">The web response.</param>
/// <param name="serializer">The serializer.</param>
/// <param name="javascriptConversionDeligate">The javascript conversion deligate.</param>
/// <returns>A strongly typed object representing the deserialized data of type <typeparamref name="T"/></returns>
public static T Deserialize(WebResponse webResponse, Serializer serializer, JavascriptConversionDelegate javascriptConversionDeligate)
/// <returns>
/// A strongly typed object representing the deserialized data of type <typeparamref name="T"/>
/// </returns>
public static T Deserialize(WebResponse webResponse, DeserializationHandler deserializationHandler)
{
try
{
Expand All @@ -95,7 +80,7 @@ public static T Deserialize(WebResponse webResponse, Serializer serializer, Java
#endif

// Deserialize the results.
resultObject = Deserialize(serializer, javascriptConversionDeligate, data);
resultObject = Deserialize(data, deserializationHandler);

responseStream.Close();

Expand All @@ -110,30 +95,52 @@ public static T Deserialize(WebResponse webResponse, Serializer serializer, Java
}
}

/// <summary>
/// Deserializes the specified web response.
/// </summary>
/// <param name="webResponse">The web response.</param>
/// <returns>
/// A strongly typed object representing the deserialized data of type <typeparamref name="T"/>
/// </returns>
public static T Deserialize(WebResponse webResponse)
{
return Deserialize(webResponse, null);
}

/// <summary>
/// Deserializes the specified serializer.
/// </summary>
/// <param name="serializer">The serializer.</param>
/// <param name="javascriptConversionDeligate">The javascript conversion deligate.</param>
/// <param name="data">The data to be deserialized.</param>
/// <returns>A strongly typed object representing the deserialized data of type <typeparamref name="T"/></returns>
public static T Deserialize(Serializer serializer, JavascriptConversionDelegate javascriptConversionDeligate, byte[] data)
/// <param name="javascriptConversionDeligate">The javascript conversion deligate.</param>
/// <returns>
/// A strongly typed object representing the deserialized data of type <typeparamref name="T"/>
/// </returns>
public static T Deserialize(byte[] data, DeserializationHandler javascriptConversionDeligate)
{
T resultObject = default(T);

switch (serializer)
if (javascriptConversionDeligate == null)
{
resultObject = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(data));
}
else
{
case Serializer.JavaScriptSerializer:
JavaScriptSerializer jss = new JavaScriptSerializer();
object result = jss.DeserializeObject(Encoding.UTF8.GetString(data));
resultObject = javascriptConversionDeligate(result);
break;
case Serializer.JSONdotNet:
resultObject = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(data));
break;
resultObject = javascriptConversionDeligate((JObject)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data)));
}

return resultObject;
}

/// <summary>
/// Deserializes the specified serializer.
/// </summary>
/// <param name="data">The data to be deserialized.</param>
/// <returns>
/// A strongly typed object representing the deserialized data of type <typeparamref name="T"/>
/// </returns>
public static T Deserialize(byte[] data)
{
return Deserialize(data, null);
}
}
}
25 changes: 7 additions & 18 deletions Twitterizer2/Core/TwitterCommand.cs
Expand Up @@ -104,12 +104,6 @@ protected TwitterCommand(string httpMethod, OAuthTokens tokens)
this.OptionalProperties = new OptionalProperties();
}

/// <summary>
/// Gets or sets the selected serializer.
/// </summary>
/// <value>The selected serializer.</value>
public Serializer SelectedSerializer { get; set; }

/// <summary>
/// Gets or sets the optional properties.
/// </summary>
Expand Down Expand Up @@ -140,6 +134,12 @@ protected TwitterCommand(string httpMethod, OAuthTokens tokens)
/// <value>The request parameters.</value>
public Dictionary<string, string> RequestParameters { get; set; }

/// <summary>
/// Gets or sets the serialization delegate.
/// </summary>
/// <value>The serialization delegate.</value>
public SerializationHelper<T>.DeserializationHandler DeserializationHandler { get; set; }

/// <summary>
/// Gets the request tokens.
/// </summary>
Expand Down Expand Up @@ -248,8 +248,7 @@ public T ExecuteCommand()

resultObject = SerializationHelper<T>.Deserialize(
webResponse,
this.SelectedSerializer,
this.ConvertJavaScriptSerializedObject);
this.DeserializationHandler);

this.AddResultToCache(cacheKeyBuilder, cache, resultObject);

Expand Down Expand Up @@ -285,16 +284,6 @@ public T ExecuteCommand()
return resultObject;
}

/// <summary>
/// Converts a weakly typed deserialized javascript object to a strongly typed object.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>A strongly typed representation of the JSON data of type <typeparamref name="T"/></returns>
public virtual T ConvertJavaScriptSerializedObject(object value)
{
throw new NotImplementedException();
}

/// <summary>
/// Clones this instance.
/// </summary>
Expand Down
99 changes: 99 additions & 0 deletions Twitterizer2/Core/TwitterizerDateConverter.cs
@@ -0,0 +1,99 @@
//-----------------------------------------------------------------------
// <copyright file="TwitterizerDateConverter.cs" company="Patrick 'Ricky' Smith">
// This file is part of the Twitterizer library (http://code.google.com/p/twitterizer/)
//
// Copyright (c) 2010, Patrick "Ricky" Smith (ricky@digitally-born.com)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// - Neither the name of the Twitterizer nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// </copyright>
// <author>Ricky Smith</author>
// <summary>The date converter for Twitter API dates</summary>
//-----------------------------------------------------------------------

namespace Twitterizer
{
using System;
using System.Globalization;

/// <summary>
/// Converts date strings returned by the Twitter API into <see cref="System.DateTime"/>
/// </summary>
internal class TwitterizerDateConverter : Newtonsoft.Json.Converters.DateTimeConverterBase
{
/// <summary>
/// The date pattern for most dates returned by the API
/// </summary>
protected const string DateFormat = "ddd MMM dd HH:mm:ss zz00 yyyy";

/// <summary>
/// Reads the json.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="existingValue">The existing value.</param>
/// <param name="serializer">The serializer.</param>
/// <returns></returns>
public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
try
{
if (reader.Value == null || reader.Value.GetType() != typeof(string))
return new DateTime();

DateTime parsedDate;

if (DateTime.TryParseExact(
(string)reader.Value,
DateFormat,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out parsedDate))
{
return parsedDate;
}
else
{
return new DateTime();
}
}
catch (Exception)
{

throw;
}
}

/// <summary>
/// Writes the json.
/// </summary>
/// <param name="writer">The writer.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The serializer.</param>
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}
10 changes: 10 additions & 0 deletions Twitterizer2/Exceptions/TwitterErrorDetails.cs
Expand Up @@ -64,24 +64,34 @@ public class TwitterErrorDetails : ITwitterObject

#region ITwitterObject Members

/// <summary>
/// Gets or sets information about the user's rate usage.
/// </summary>
/// <value>The rate limiting object.</value>
public RateLimiting RateLimiting
{
get
{
throw new System.NotImplementedException();
}

set
{
throw new System.NotImplementedException();
}
}

/// <summary>
/// Gets or sets the oauth tokens.
/// </summary>
/// <value>The oauth tokens.</value>
public OAuthTokens Tokens
{
get
{
throw new System.NotImplementedException();
}

set
{
throw new System.NotImplementedException();
Expand Down

0 comments on commit e7135a6

Please sign in to comment.