Browse Source

include in-reply-to URL for tweets

pull/64/head v1.4.19
Aaron Parecki 6 years ago
parent
commit
c27f228314
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 251 additions and 0 deletions
  1. +7
    -0
      lib/XRay/Formats/Twitter.php
  2. +14
    -0
      tests/TwitterTest.php
  3. +120
    -0
      tests/data/api.twitter.com/967046438822674432.json
  4. +110
    -0
      tests/data/api.twitter.com/streaming-tweet-reply.json

+ 7
- 0
lib/XRay/Formats/Twitter.php View File

@ -108,6 +108,13 @@ class Twitter extends Format {
} }
} }
// In-Reply-To
if(property_exists($tweet, 'in_reply_to_status_id_str') && $tweet->in_reply_to_status_id_str) {
$entry['in-reply-to'] = [
'https://twitter.com/'.$tweet->in_reply_to_screen_name.'/status/'.$tweet->in_reply_to_status_id_str
];
}
// Don't include the RT'd photo or video in the main object. // Don't include the RT'd photo or video in the main object.
// They get included in the reposted object instead. // They get included in the reposted object instead.
if(!property_exists($tweet, 'retweeted_status')) { if(!property_exists($tweet, 'retweeted_status')) {

+ 14
- 0
tests/TwitterTest.php View File

@ -244,4 +244,18 @@ Feel like I could (maybe) rewrite previous open code to do some of this :)', $da
Woke up this morning feeling compelled to run to Corona… http://tantek.com/2018/049/t3/rainbow-at-sunrise", $data['data']['content']['text']); Woke up this morning feeling compelled to run to Corona… http://tantek.com/2018/049/t3/rainbow-at-sunrise", $data['data']['content']['text']);
} }
public function testStreamingTweetReply() {
list($url, $json) = $this->loadTweet('streaming-tweet-reply');
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('https://twitter.com/anomalily/status/967024586423386112', $data['data']['in-reply-to'][0]);
}
public function testTweetReply() {
list($url, $json) = $this->loadTweet('967046438822674432');
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('https://twitter.com/anomalily/status/967024586423386112', $data['data']['in-reply-to'][0]);
}
} }

+ 120
- 0
tests/data/api.twitter.com/967046438822674432.json View File

@ -0,0 +1,120 @@
{
"created_at": "Fri Feb 23 14:40:12 +0000 2018",
"id": 967046438822674432,
"id_str": "967046438822674432",
"full_text": "@anomalily @i_stan4u @borrowtheair It’d be SO BORING if they just skated until they did big jumps and there was no artistry.",
"truncated": false,
"display_text_range": [
35,
124
],
"entities": {
"hashtags": [
],
"symbols": [
],
"user_mentions": [
{
"screen_name": "anomalily",
"name": "Lillian Karabaic (book out 4/17!)",
"id": 46416755,
"id_str": "46416755",
"indices": [
0,
10
]
},
{
"screen_name": "i_stan4u",
"name": "iStan",
"id": 947754749964591104,
"id_str": "947754749964591104",
"indices": [
11,
20
]
},
{
"screen_name": "borrowtheair",
"name": "to be honest",
"id": 932418774384254977,
"id_str": "932418774384254977",
"indices": [
21,
34
]
}
],
"urls": [
]
},
"source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
"in_reply_to_status_id": 967024586423386112,
"in_reply_to_status_id_str": "967024586423386112",
"in_reply_to_user_id": 46416755,
"in_reply_to_user_id_str": "46416755",
"in_reply_to_screen_name": "anomalily",
"user": {
"id": 349298514,
"id_str": "349298514",
"name": "Maggie Williams",
"screen_name": "pdxmaggie",
"location": "Portland, OR",
"description": "Prodigal daughter returns to Portland to find she's now constantly overdressed for her hometown.",
"url": null,
"entities": {
"description": {
"urls": [
]
}
},
"protected": false,
"followers_count": 441,
"friends_count": 309,
"listed_count": 18,
"created_at": "Fri Aug 05 21:54:05 +0000 2011",
"favourites_count": 2761,
"utc_offset": -18000,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"verified": false,
"statuses_count": 7256,
"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/875413860257103872/mz3WUmK3_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/875413860257103872/mz3WUmK3_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/349298514/1449637782",
"profile_link_color": "1DA1F2",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"has_extended_profile": true,
"default_profile": true,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 1,
"favorited": false,
"retweeted": false,
"lang": "en"
}

+ 110
- 0
tests/data/api.twitter.com/streaming-tweet-reply.json View File

@ -0,0 +1,110 @@
{
"created_at": "Fri Feb 23 14:40:12 +0000 2018",
"id": 967046438822674432,
"id_str": "967046438822674432",
"text": "@anomalily @i_stan4u @borrowtheair It\u2019d be SO BORING if they just skated until they did big jumps and there was no artistry.",
"display_text_range": [
35,
124
],
"source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
"truncated": false,
"in_reply_to_status_id": 967024586423386112,
"in_reply_to_status_id_str": "967024586423386112",
"in_reply_to_user_id": 46416755,
"in_reply_to_user_id_str": "46416755",
"in_reply_to_screen_name": "anomalily",
"user": {
"id": 349298514,
"id_str": "349298514",
"name": "Maggie Williams",
"screen_name": "pdxmaggie",
"location": "Portland, OR",
"url": null,
"description": "Prodigal daughter returns to Portland to find she's now constantly overdressed for her hometown.",
"translator_type": "none",
"protected": false,
"verified": false,
"followers_count": 441,
"friends_count": 309,
"listed_count": 18,
"favourites_count": 2758,
"statuses_count": 7249,
"created_at": "Fri Aug 05 21:54:05 +0000 2011",
"utc_offset": -18000,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"lang": "en",
"contributors_enabled": false,
"is_translator": 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_link_color": "1DA1F2",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"profile_image_url": "http://pbs.twimg.com/profile_images/875413860257103872/mz3WUmK3_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/875413860257103872/mz3WUmK3_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/349298514/1449637782",
"default_profile": true,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"quote_count": 0,
"reply_count": 0,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [],
"urls": [],
"user_mentions": [
{
"screen_name": "anomalily",
"name": "Lillian Karabaic (book out 4/17!)",
"id": 46416755,
"id_str": "46416755",
"indices": [
0,
10
]
},
{
"screen_name": "i_stan4u",
"name": "iStan",
"id": 947754749964591104,
"id_str": "947754749964591104",
"indices": [
11,
20
]
},
{
"screen_name": "borrowtheair",
"name": "to be honest",
"id": 932418774384254977,
"id_str": "932418774384254977",
"indices": [
21,
34
]
}
],
"symbols": []
},
"favorited": false,
"retweeted": false,
"filter_level": "low",
"lang": "en",
"timestamp_ms": "1519396812526"
}

Loading…
Cancel
Save