|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | 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 | | - |
216 | 4 | class X < Base |
217 | 5 | class << self |
218 | 6 | ## |
|
0 commit comments