Skip to content

Commit 3cc41a7

Browse files
Remove deprecated Faker::Twitter
Please use Faker::X from now on. And note that the generator has been updated to match the new API response.
1 parent 9cadf41 commit 3cc41a7

3 files changed

Lines changed: 3 additions & 312 deletions

File tree

doc/default/x.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
`Faker::Twitter` has been deprecated in favor of `Faker::X`. While it's still maintained, its docs can be found at [Faker::Twitter](#fakertwitter).
2-
31
# Faker::X
42

53
Generates approximate X (previously Twitter) user and tweet objects, based on X's API v2 responses.
@@ -58,9 +56,9 @@ Produces a random X tweet with default attributes. Available extensions can be r
5856

5957
```ruby
6058
# Keyword arguments: include_user, include_media
61-
Faker::Twitter.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",...
62-
Faker::Twitter.tweet(include_user: true) # Includes user attributes
63-
Faker::Twitter.tweet(include_media: true) # Includes media (photo) attributes
59+
Faker::X.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",...
60+
Faker::X.tweet(include_user: true) # Includes user attributes
61+
Faker::X.tweet(include_media: true) # Includes media (photo) attributes
6462
```
6563

6664
Example outputs:
@@ -194,35 +192,3 @@ Produces a random screen_name:
194192
```ruby
195193
Faker::X.screen_name #=> "audreanne_hackett"
196194
```
197-
198-
# Faker::Twitter
199-
200-
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).
201-
202-
Available since version 1.7.3.
203-
204-
Generate realistic Twitter user and status objects similar to what you would get back from the API.
205-
206-
```json
207-
{
208-
"created_at": "Mon Dec 10 00:00:00 +0000 2012",
209-
"id": 8821452687517076614,
210-
"id_str": "8821452687517076614",
211-
"text": "Ea et laboriosam vel non.",
212-
// ...
213-
}
214-
```
215-
216-
```ruby
217-
# Keyword arguments: include_status, include_email
218-
Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
219-
Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
220-
Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission
221-
222-
# Keyword arguments: include_user, include_photo
223-
Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
224-
Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
225-
Faker::Twitter.status(include_photo: true) # Includes entities for an attached image
226-
227-
Faker::Twitter.screen_name #=> "audreanne_hackett"
228-
```

lib/faker/default/twitter.rb

Lines changed: 0 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -1,218 +1,6 @@
11
# frozen_string_literal: true
22

33
module Faker
4-
class Twitter < Base
5-
class << self
6-
##
7-
# Produces a random Twitter user.
8-
#
9-
# @param include_status [Boolean] Include or exclude user status details
10-
# @param include_email [Boolean] Include or exclude user email details
11-
# @return [Hash]
12-
#
13-
# @example
14-
# Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
15-
# Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
16-
# Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission
17-
#
18-
# @faker.version 1.7.3
19-
def user(include_status: true, include_email: false)
20-
warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead. Some return attributes \
21-
will be removed, check the docs for more details.')
22-
23-
user_id = id
24-
background_image_url = Faker::LoremFlickr.image(size: '600x400')
25-
profile_image_url = Faker::Avatar.image(slug: user_id, size: '48x48')
26-
user = {
27-
id: user_id,
28-
id_str: user_id.to_s,
29-
contributors_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
30-
created_at: created_at,
31-
default_profile_image: Faker::Boolean.boolean(true_ratio: 0.1),
32-
default_profile: Faker::Boolean.boolean(true_ratio: 0.1),
33-
description: Faker::Lorem.sentence,
34-
entities: user_entities,
35-
favourites_count: Faker::Number.between(to: 1, from: 100_000),
36-
follow_request_sent: false,
37-
followers_count: Faker::Number.between(to: 1, from: 10_000_000),
38-
following: false,
39-
friends_count: Faker::Number.between(to: 1, from: 100_000),
40-
geo_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
41-
is_translation_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
42-
is_translator: Faker::Boolean.boolean(true_ratio: 0.1),
43-
lang: Faker::Address.country_code,
44-
listed_count: Faker::Number.between(to: 1, from: 1000),
45-
location: "#{Faker::Address.city}, #{Faker::Address.state_abbr}, #{Faker::Address.country_code}",
46-
name: Faker::Name.name,
47-
notifications: false,
48-
profile_background_color: Faker::Color.hex_color,
49-
profile_background_image_url_https: background_image_url,
50-
profile_background_image_url: background_image_url.sub('https://', 'http://'),
51-
profile_background_tile: Faker::Boolean.boolean(true_ratio: 0.1),
52-
profile_banner_url: Faker::LoremFlickr.image(size: '1500x500'),
53-
profile_image_url_https: profile_image_url,
54-
profile_image_url: profile_image_url.sub('https://', 'http://'),
55-
profile_link_color: Faker::Color.hex_color,
56-
profile_sidebar_border_color: Faker::Color.hex_color,
57-
profile_sidebar_fill_color: Faker::Color.hex_color,
58-
profile_text_color: Faker::Color.hex_color,
59-
profile_use_background_image: Faker::Boolean.boolean(true_ratio: 0.4),
60-
protected: Faker::Boolean.boolean(true_ratio: 0.1),
61-
screen_name: screen_name,
62-
statuses_count: Faker::Number.between(to: 1, from: 100_000),
63-
time_zone: Faker::Address.time_zone,
64-
url: Faker::Internet.url(host: 'example.com'),
65-
utc_offset: utc_offset,
66-
verified: Faker::Boolean.boolean(true_ratio: 0.1)
67-
}
68-
user[:status] = Faker::Twitter.status(include_user: false) if include_status
69-
user[:email] = Faker::Internet.email if include_email
70-
user
71-
end
72-
73-
##
74-
# Produces a random Twitter user.
75-
#
76-
# @param include_user [Boolean] Include or exclude user details
77-
# @param include_photo [Boolean] Include or exclude user photo
78-
# @return [Hash]
79-
#
80-
# @example
81-
# Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
82-
# Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
83-
# Faker::Twitter.status(include_photo: true) # Includes entities for an attached image
84-
#
85-
# @faker.version 1.7.3
86-
def status(include_user: true, include_photo: false)
87-
warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead. Some return attributes \
88-
will be removed, check the docs for more details.')
89-
90-
status_id = id
91-
status = {
92-
id: status_id,
93-
id_str: status_id.to_s,
94-
contributors: nil,
95-
coordinates: nil,
96-
created_at: created_at,
97-
entities: status_entities(include_photo: include_photo),
98-
favorite_count: Faker::Number.between(to: 1, from: 10_000),
99-
favorited: false,
100-
geo: nil,
101-
in_reply_to_screen_name: nil,
102-
in_reply_to_status_id: nil,
103-
in_reply_to_user_id_str: nil,
104-
in_reply_to_user_id: nil,
105-
is_quote_status: false,
106-
lang: Faker::Address.country_code,
107-
nil: nil,
108-
place: nil,
109-
possibly_sensitive: Faker::Boolean.boolean(true_ratio: 0.1),
110-
retweet_count: Faker::Number.between(to: 1, from: 10_000),
111-
retweeted_status: nil,
112-
retweeted: false,
113-
source: "<a href=\"#{Faker::Internet.url(host: 'example.com')}\" rel=\"nofollow\">#{Faker::Company.name}</a>",
114-
text: Faker::Lorem.sentence,
115-
truncated: false
116-
}
117-
status[:user] = Faker::Twitter.user(include_status: false) if include_user
118-
status[:text] = "#{status[:text]} #{status[:entities][:media].first[:url]}" if include_photo
119-
status
120-
end
121-
122-
##
123-
# Produces a random screen name.
124-
#
125-
# @return [String]
126-
#
127-
# @example
128-
# Faker::Twitter.screen_name #=> "audreanne_hackett"
129-
#
130-
# @faker.version 1.7.3
131-
def screen_name
132-
warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead.')
133-
134-
Faker::Internet.username(specifier: nil, separators: ['_'])[0...20]
135-
end
136-
137-
private
138-
139-
def id
140-
Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807)
141-
end
142-
143-
def created_at
144-
Faker::Date.between(from: '2006-03-21', to: ::Date.today).strftime('%a %b %d %H:%M:%S %z %Y')
145-
end
146-
147-
def utc_offset
148-
Faker::Number.between(to: -43_200, from: 50_400)
149-
end
150-
151-
def user_entities
152-
{
153-
url: {
154-
urls: []
155-
},
156-
description: {
157-
urls: []
158-
}
159-
}
160-
end
161-
162-
def status_entities(include_photo: false)
163-
entities = {
164-
hashtags: [],
165-
symbols: [],
166-
user_mentions: [],
167-
urls: []
168-
}
169-
entities[:media] = [photo_entity] if include_photo
170-
entities
171-
end
172-
173-
def photo_entity
174-
media_url = Faker::LoremFlickr.image(size: '1064x600')
175-
media_id = id
176-
{
177-
id: media_id,
178-
id_str: media_id.to_s,
179-
indices: [
180-
103,
181-
126
182-
],
183-
media_url: media_url.sub('https://', 'http://'),
184-
media_url_https: media_url,
185-
url: Faker::Internet.url(host: 'example.com'),
186-
display_url: 'example.com',
187-
expanded_url: Faker::Internet.url(host: 'example.com'),
188-
type: 'photo',
189-
sizes: {
190-
medium: {
191-
w: 1064,
192-
h: 600,
193-
resize: 'fit'
194-
},
195-
large: {
196-
w: 1064,
197-
h: 600,
198-
resize: 'fit'
199-
},
200-
small: {
201-
w: 680,
202-
h: 383,
203-
resize: 'fit'
204-
},
205-
thumb: {
206-
w: 150,
207-
h: 150,
208-
resize: 'crop'
209-
}
210-
}
211-
}
212-
end
213-
end
214-
end
215-
2164
class X < Base
2175
class << self
2186
##

test/faker/default/test_twitter.rb

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,6 @@
22

33
require_relative '../../test_helper'
44

5-
class TestFakerTwitter < Test::Unit::TestCase
6-
def setup
7-
@tester = Faker::Twitter
8-
end
9-
10-
def test_user
11-
user = @tester.user
12-
13-
assert_kind_of Hash, user
14-
assert_equal(41, user.keys.count)
15-
assert_kind_of Hash, user[:status]
16-
assert_nil user[:status][:user]
17-
end
18-
19-
def test_user_with_email
20-
user = @tester.user(include_email: true)
21-
22-
assert_kind_of Hash, user
23-
assert_equal(42, user.keys.count)
24-
assert_kind_of String, user[:email]
25-
end
26-
27-
def test_user_without_status
28-
user = @tester.user(include_status: false)
29-
30-
assert_kind_of Hash, user
31-
assert_equal(40, user.keys.count)
32-
assert_nil user[:status]
33-
end
34-
35-
def test_status
36-
status = @tester.status
37-
38-
assert_kind_of Hash, status
39-
assert_equal(25, status.keys.count)
40-
assert_kind_of Hash, status[:entities]
41-
assert_kind_of Hash, status[:user]
42-
assert_nil status[:user][:status]
43-
end
44-
45-
def test_status_without_user
46-
status = @tester.status(include_user: false)
47-
48-
assert_kind_of Hash, status
49-
assert_equal(24, status.keys.count)
50-
assert_nil status[:user]
51-
end
52-
53-
def test_status_with_photo
54-
status = @tester.status(include_photo: true)
55-
56-
assert_kind_of Hash, status
57-
assert_equal(25, status.keys.count)
58-
assert_kind_of Hash, status[:entities]
59-
assert_equal(1, status[:entities][:media].count)
60-
assert_equal(10, status[:entities][:media].first.keys.count)
61-
end
62-
63-
def test_screen_name
64-
assert_kind_of String, @tester.screen_name
65-
end
66-
end
67-
685
class TestFakerX < Test::Unit::TestCase
696
def setup
707
@tester = Faker::X

0 commit comments

Comments
 (0)