Skip to content

Commit 68d4aa1

Browse files
Deprecate Faker::Twitter and update status to tweet
After working on the user generator, it made sense to also deprecate the `status` one. The API migration docs don't mention changing status to tweet, but after inspecting what `status` returns, I realized the new API calls is `tweet`. There were lots of changes for both user and tweet objects. Most notably, the shape of the response, additional fields, and removal of deprecated attributes. Used resources as references: - https://docs.x.com/x-api/migrate/data-format-migration#user-object - https://docs.x.com/x-api/fundamentals/data-dictionary#tweet - https://docs.x.com/x-api/migrate/data-format-migration#entities-and-expanded-entities-objects
1 parent a080fcc commit 68d4aa1

File tree

5 files changed

+436
-56
lines changed

5 files changed

+436
-56
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and it was the original impetus for the creation of this gem.
3434

3535
- [Faker](#faker)
3636
- [Quick links](#quick-links)
37+
- [In the media](#in-the-media)
3738
- [Table of Contents](#table-of-contents)
3839
- [Notes](#notes)
3940
- [Getting Started](#getting-started)
@@ -292,13 +293,13 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
292293
- [Faker::Team](doc/default/team.md)
293294
- [Faker::Theater](doc/default/theater.md)
294295
- [Faker::Time](doc/default/time.md)
295-
- [Faker::Twitter](doc/default/twitter.md)
296296
- [Faker::Types](doc/default/types.md)
297297
- [Faker::University](doc/default/university.md)
298298
- [Faker::Vehicle](doc/default/vehicle.md)
299299
- [Faker::Verbs](doc/default/verbs.md)
300300
- [Faker::VulnerabilityIdentifier](doc/default/vulnerability_identifier.md)
301301
- [Faker::WorldCup](doc/default/world_cup.md)
302+
- [Faker::X](doc/default/x.md)
302303
</details>
303304

304305
<details>

doc/default/twitter.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

doc/default/x.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
`Faker::Twitter` has been deprecated. While it's still maintained, its docs can be found at [Faker::Twitter](#fakertwitter).
2+
3+
# Faker::X
4+
5+
Generates approximate X (previous Twitter) user and tweet objects, based on X's API v2 responses.
6+
7+
The generators are not a comprehensive match of the API. However, they are enough to create a demo app using X’s user or tweet data, for example.
8+
9+
## Faker::X.user
10+
11+
Produces a random X user based on X's v2 API:
12+
13+
```ruby
14+
Faker::X.user => {
15+
data: [
16+
{
17+
author_id: "5688134805624042468",
18+
id: "2007502004337242257",
19+
text: "Qui sint magni vel."
20+
}
21+
],
22+
includes: {
23+
users: [
24+
{
25+
public_metrics: {
26+
followers_count: 1000,
27+
following_count: 77,
28+
tweet_count: 4642,
29+
listed_count: 704
30+
},
31+
username: "lilian",
32+
pinned_tweet_id: "1702549793917523469",
33+
entities: {
34+
url: {
35+
urls: [ { url: "https://t.co/0iz5wx1ysh", expanded_url: "http://example.com/stuart", display_url: "example.com/stuart" }]
36+
},
37+
description: { hashtags: [{tag: "Adipisci"}] }
38+
},
39+
description: "Est est laborum dolores.",
40+
name: "Kimberli Ullrich Jr.",
41+
verified: false,
42+
location: "104.82.135.3",
43+
id: "5688134805624042468",
44+
protected: false,
45+
url: "https://t.co/lqsqf67cx5",
46+
profile_image_url: "https://robohash.org/990174365255127568.png?size=48x48&set=set1",
47+
created_at: "2018-07-11T00:00:00+00:00"
48+
}
49+
]
50+
}
51+
}
52+
```
53+
54+
## Faker::X.tweet
55+
56+
Produces a random X tweet with default attributes. Available extensions can be returned with `include_media` and `include_user`:
57+
58+
```ruby
59+
# Keyword arguments: include_user, include_media
60+
Faker::Twitter.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",...
61+
Faker::Twitter.tweet(include_user: true) # Includes user attributes
62+
Faker::Twitter.tweet(include_media: true) # Includes media (photo) attributes
63+
```
64+
65+
Example outputs:
66+
67+
```ruby
68+
Faker::X.tweet =>
69+
{
70+
data: [
71+
{
72+
id: "7999525033982409544",
73+
text: "Molestias non possimus voluptatem.",
74+
lang: "VA",
75+
conversation_id: "7999525033982409544",
76+
created_at: "2011-03-16T00:00:00+00:00",
77+
public_metrics: {retweet_count: 69, reply_count: 17, like_count: 21, quote_count: 8},
78+
possibly_sensitive: false,
79+
entities: {
80+
url: { urls: [{url: "https://t.co/gz4z8dvybe", expanded_url: "http://example.com/salley.grant", display_url: "example.com/salley.grant"}] },
81+
description: { hashtags: [{tag: "Veritatis"}] }
82+
},
83+
in_reply_to_user_id: false
84+
}
85+
]
86+
}
87+
```
88+
89+
With additional fields:
90+
91+
```ruby
92+
Faker::X.tweet(include_media: true, include_user: true) =>
93+
94+
{
95+
data: [
96+
{
97+
id: "8194812886422142201",
98+
text: "Eos sed quibusdam aperiam.",
99+
lang: "AU",
100+
conversation_id: "8194812886422142201",
101+
created_at: "2017-10-24T00:00:00+00:00",
102+
public_metrics: {retweet_count: 87, reply_count: 19, like_count: 14, quote_count: 4},
103+
possibly_sensitive: false,
104+
entities: {
105+
url: { urls: [{url: "https://t.co/h9pi5f7q7j", expanded_url: "http://example.com/angelica_moore", display_url: "example.com/angelica_moore"}] },
106+
description: { hashtags: [{tag: "Saepe"}] }
107+
},
108+
in_reply_to_user_id: false},
109+
{ attachments: {media_keys: ["466995304449852781"]}
110+
}
111+
],
112+
includes: {
113+
media: [
114+
{
115+
type: "photo",
116+
indices: [103, 126],
117+
height: 446,
118+
media_key: "466995304449852781",
119+
preview_image_url: "https://loremflickr.com/1064/600",
120+
width: 1321,
121+
url: "https://t.co/s3j25etwdj",
122+
expanded_url: "https://loremflickr.com/1064/600",
123+
display_url: "loremflickr.com/1064/600",
124+
alt_text: "Et possimus repudiandae tenetur."
125+
}
126+
],
127+
users: [
128+
{
129+
public_metrics: {followers_count: 488, following_count: 180, tweet_count: 6368, listed_count: 209},
130+
username: "shante",
131+
pinned_tweet_id: "7350697183426089357",
132+
entities: {
133+
url: { urls: [{url: "https://t.co/cxwehs7i1z", expanded_url: "http://example.com/kirstie.reilly", display_url: "example.com/kirstie.reilly"}] },
134+
description: { hashtags: [{tag: "Rem"}] }
135+
},
136+
description: "Ipsa nihil velit adipisci.",
137+
name: "Jerome Heathcote III",
138+
verified: false,
139+
location: "222.70.154.120",
140+
id: "5679269981284870916",
141+
protected: false,
142+
url: "https://t.co/5xyjlv6ckv",
143+
profile_image_url: "https://robohash.org/4106878141532070549.png?size=48x48&set=set1",
144+
created_at: "2019-01-27T00:00:00+00:00"
145+
}
146+
]
147+
}
148+
}
149+
```
150+
151+
## Faker::X.screen_name
152+
153+
Produces a random screen_name:
154+
155+
```ruby
156+
Faker::Twitter.screen_name #=> "audreanne_hackett"
157+
```
158+
159+
# Faker::Twitter
160+
161+
This generator has been deprecated. Please use `Faker::X` instead. Note that some attributes have been deprecated by [X's API](https://docs.x.com/x-api/migrate/data-format-migration).
162+
163+
Available since version 1.7.3.
164+
165+
Generate realistic Twitter user and status objects similar to what you would get back from the API.
166+
167+
```json
168+
{
169+
"created_at": "Mon Dec 10 00:00:00 +0000 2012",
170+
"id": 8821452687517076614,
171+
"id_str": "8821452687517076614",
172+
"text": "Ea et laboriosam vel non.",
173+
// ...
174+
}
175+
```
176+
177+
```ruby
178+
# Keyword arguments: include_status, include_email
179+
Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
180+
Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
181+
Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission
182+
183+
# Keyword arguments: include_user, include_photo
184+
Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
185+
Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
186+
Faker::Twitter.status(include_photo: true) # Includes entities for an attached image
187+
188+
Faker::Twitter.screen_name #=> "audreanne_hackett"
189+
```

0 commit comments

Comments
 (0)