Skip to content

Commit

Permalink
Merge pull request #148 from ChimeraCoder/ahamidi-include-quoted-fields
Browse files Browse the repository at this point in the history
Include quoted tweet fields
  • Loading branch information
ChimeraCoder committed Jun 4, 2016
2 parents c414dff + 873c098 commit 00ecb7b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions json/statuses/show.json?id=738567564641599489
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"created_at":"Fri Jun 03 03:06:43 +0000 2016","id":738567564641599489,"id_str":"738567564641599489","text":"Well, this has certainly come a long way! https:\/\/t.co\/QomzRzwcti","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"https:\/\/t.co\/QomzRzwcti","expanded_url":"https:\/\/twitter.com\/chimeracoder\/status\/284377451625340928","display_url":"twitter.com\/chimeracoder\/s\u2026","indices":[42,65]}]},"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":182675886,"id_str":"182675886","name":"Aditya Mukerjee","screen_name":"chimeracoder","location":"New York, NY","description":"Risk engineer at @stripe. Linux dev, statistician. Writing lots of Go. Alum of @recursecenter, @cornell_tech, @columbia","url":"https:\/\/t.co\/6PwvHXBN5Y","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/6PwvHXBN5Y","expanded_url":"https:\/\/adityamukerjee.net","display_url":"adityamukerjee.net","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":3061,"friends_count":914,"listed_count":172,"created_at":"Wed Aug 25 03:49:41 +0000 2010","favourites_count":5193,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":9559,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"quoted_status_id":284377451625340928,"quoted_status_id_str":"284377451625340928","quoted_status":{"created_at":"Thu Dec 27 19:17:22 +0000 2012","id":284377451625340928,"id_str":"284377451625340928","text":"Just created gojson - a simple tool for turning JSON data into Go structs! http:\/\/t.co\/QM6k9AUV #golang","truncated":false,"entities":{"hashtags":[{"text":"golang","indices":[96,103]}],"symbols":[],"user_mentions":[],"urls":[{"url":"http:\/\/t.co\/QM6k9AUV","expanded_url":"http:\/\/bit.ly\/UbfXOC","display_url":"bit.ly\/UbfXOC","indices":[75,95]}]},"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":182675886,"id_str":"182675886","name":"Aditya Mukerjee","screen_name":"chimeracoder","location":"New York, NY","description":"Risk engineer at @stripe. Linux dev, statistician. Writing lots of Go. Alum of @recursecenter, @cornell_tech, @columbia","url":"https:\/\/t.co\/6PwvHXBN5Y","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/6PwvHXBN5Y","expanded_url":"https:\/\/adityamukerjee.net","display_url":"adityamukerjee.net","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":3061,"friends_count":914,"listed_count":172,"created_at":"Wed Aug 25 03:49:41 +0000 2010","favourites_count":5193,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":9559,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":2,"favorited":false,"retweeted":false,"possibly_sensitive":false,"possibly_sensitive_appealable":false,"lang":"en"},"is_quote_status":true,"retweet_count":0,"favorite_count":1,"favorited":false,"retweeted":false,"possibly_sensitive":false,"possibly_sensitive_appealable":false,"lang":"en"}
3 changes: 3 additions & 0 deletions tweet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Tweet struct {
InReplyToUserIdStr string `json:"in_reply_to_user_id_str"`
Lang string `json:"lang"`
Place Place `json:"place"`
QuotedStatusID int64 `json:"quoted_status_id"`
QuotedStatusIdStr string `json:"quoted_status_id_str"`
QuotedStatus *Tweet `json:"quoted_status"`
PossiblySensitive bool `json:"possibly_sensitive"`
RetweetCount int `json:"retweet_count"`
Retweeted bool `json:"retweeted"`
Expand Down
39 changes: 35 additions & 4 deletions twitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"reflect"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -62,11 +63,14 @@ func init() {
// if one filename is the prefix of another, the prefix will always match
// check if there is a more specific filename that matches this request

// create local variable to avoid closing over `filename`
sourceFilename := filename

r.ParseForm()
specific := filename + "?" + r.Form.Encode()
specific := sourceFilename + "?" + r.Form.Encode()
_, err := os.Stat(specific)
if err == nil {
filename = specific
sourceFilename = specific

} else {
if err != nil && !os.IsNotExist(err) {
Expand All @@ -75,7 +79,7 @@ func init() {
}
}

f, err := os.Open(filename)
f, err := os.Open(sourceFilename)
if err != nil {
// either the file does not exist
// or something is seriously wrong with the testing environment
Expand All @@ -84,7 +88,7 @@ func init() {
defer f.Close()

// TODO not a hack
if filename == "json/statuses/show.json?id=404409873170841600" {
if sourceFilename == "json/statuses/show.json?id=404409873170841600" {
bts, err := ioutil.ReadAll(f)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -241,7 +245,34 @@ func Test_GetTweet(t *testing.T) {
if !reflect.DeepEqual(tweet.Entities, expectedEntities) {
t.Fatalf("Tweet entities differ")
}
}

func Test_GetQuotedTweet(t *testing.T) {
const tweetId = 738567564641599489
const tweetText = `Well, this has certainly come a long way! https://t.co/QomzRzwcti`
const quotedID = 284377451625340928
const quotedText = `Just created gojson - a simple tool for turning JSON data into Go structs! http://t.co/QM6k9AUV #golang`

tweet, err := api.GetTweet(tweetId, nil)
if err != nil {
t.Fatalf("GetTweet returned error: %s", err.Error())
}

if tweet.Text != tweetText {
t.Fatalf("Tweet %d contained incorrect text. Received: %s", tweetId, tweet.Text)
}

if tweet.QuotedStatusID != quotedID {
t.Fatalf("Expected quoted status %d, received %d", quotedID, tweet.QuotedStatusID)
}

if tweet.QuotedStatusIdStr != strconv.Itoa(quotedID) {
t.Fatalf("Expected quoted status %d (as string), received %s", quotedID, tweet.QuotedStatusIdStr)
}

if tweet.QuotedStatus.Text != quotedText {
t.Fatalf("Expected quoted status text %#v, received $#v", quotedText, tweet.QuotedStatus.Text)
}
}

// This assumes that the current user has at least two pages' worth of followers
Expand Down

0 comments on commit 00ecb7b

Please sign in to comment.