Permalink
Browse files

fix search api

  • Loading branch information...
1 parent 13b5059 commit 37cff6fe89535dab2216be5d8e52b4447ec43240 @bling committed Sep 28, 2011
@@ -147,7 +147,10 @@ public IObservable<Tweet> GetUserTimeline(string screenName, ulong? sinceId = nu
public IObservable<Tweet> GetSearch(string query, ulong? sinceId = null, int count = RequestCount)
{
var options = new object[] { new { include_entities = "1" }, new { q = query }, new { count }, new { since_id = sinceId } };
- return GetSnapshot(SearchAuthority, "/search.json", options).SelectTweets(_tweets);
+ return GetContents(SearchAuthority, "/search.json", options)
+ .Select(ToJson)
+ .SelectMany(x => (JsonArray)x["results"])
+ .SelectTweets(_tweets);
}
public IObservable<Tweet> GetStreamingHomeline()
@@ -16,6 +16,11 @@ public static class JsonHelper
return null;
}
+ public static DateTime GetSearchDateTime(this JsonValue json, string key)
+ {
+ return DateTime.Parse(json[key], CultureInfo.InvariantCulture);
+ }
+
public static DateTime GetDateTime(this JsonValue json, string key)
{
return DateTime.ParseExact(json[key],
@@ -24,7 +29,7 @@ public static DateTime GetDateTime(this JsonValue json, string key)
public static Tweet ToTweet(JsonObject value)
{
- if (value.ContainsKey("text") && value.ContainsKey("user"))
+ if (value.ContainsKey("text"))
return Activate(() => new Tweet(value));
return null;
@@ -9,20 +9,34 @@ public class Tweet : PropertyChangedBase
{
public Tweet(JsonObject json)
{
- Id = json["id"];
Text = json["text"]; // explicit conversion will unescape json
Text = Text.UnescapeXml(); // unescape again for & escapes
Source = json["source"];
- IsRetweet = json["retweeted"];
- InReplyToStatusId = json["in_reply_to_status_id_str"];
- InReplyToScreenName = json["in_reply_to_screen_name"];
- CreatedAt = json.GetDateTime("created_at");
-
- JsonValue entities;
- if (json.TryGetValue("entities", out entities))
- Entities = new Entities(entities);
- User = new User(json["user"]);
+ if (json.ContainsKey("from_user")) // search api
+ {
+ CreatedAt = json.GetSearchDateTime("created_at");
+ User = new User
+ {
+ Id = json["from_user_id"],
+ ScreenName = json["from_user"],
+ ProfileImageUrl = json["profile_image_url"]
+ };
+ }
+ else
+ {
+ Id = json["id"];
+ IsRetweet = json["retweeted"];
+ InReplyToStatusId = json["in_reply_to_status_id_str"];
+ InReplyToScreenName = json["in_reply_to_screen_name"];
+ CreatedAt = json.GetDateTime("created_at");
+
+ JsonValue entities;
+ if (json.TryGetValue("entities", out entities))
+ Entities = new Entities(entities);
+
+ User = new User(json["user"]);
+ }
}
public ulong Id { get; private set; }
@@ -19,7 +19,7 @@ public User(JsonValue json)
IsFollowing = json.GetBool("following");
}
- protected User()
+ public User()
{
}

0 comments on commit 37cff6f

Please sign in to comment.