⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions doc/default/x.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
`Faker::Twitter` has been deprecated in favor of `Faker::X`. While it's still maintained, its docs can be found at [Faker::Twitter](#fakertwitter).

# Faker::X

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

```ruby
# Keyword arguments: include_user, include_media
Faker::Twitter.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",...
Faker::Twitter.tweet(include_user: true) # Includes user attributes
Faker::Twitter.tweet(include_media: true) # Includes media (photo) attributes
Faker::X.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",...
Faker::X.tweet(include_user: true) # Includes user attributes
Faker::X.tweet(include_media: true) # Includes media (photo) attributes
```

Example outputs:
Expand Down Expand Up @@ -194,35 +192,3 @@ Produces a random screen_name:
```ruby
Faker::X.screen_name #=> "audreanne_hackett"
```

# Faker::Twitter

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).

Available since version 1.7.3.

Generate realistic Twitter user and status objects similar to what you would get back from the API.

```json
{
"created_at": "Mon Dec 10 00:00:00 +0000 2012",
"id": 8821452687517076614,
"id_str": "8821452687517076614",
"text": "Ea et laboriosam vel non.",
// ...
}
```

```ruby
# Keyword arguments: include_status, include_email
Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission

# Keyword arguments: include_user, include_photo
Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
Faker::Twitter.status(include_photo: true) # Includes entities for an attached image

Faker::Twitter.screen_name #=> "audreanne_hackett"
```
212 changes: 0 additions & 212 deletions lib/faker/default/twitter.rb
Original file line number Diff line number Diff line change
@@ -1,218 +1,6 @@
# frozen_string_literal: true

module Faker
class Twitter < Base
class << self
##
# Produces a random Twitter user.
#
# @param include_status [Boolean] Include or exclude user status details
# @param include_email [Boolean] Include or exclude user email details
# @return [Hash]
#
# @example
# Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
# Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
# Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission
#
# @faker.version 1.7.3
def user(include_status: true, include_email: false)
warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead. Some return attributes \
will be removed, check the docs for more details.')

user_id = id
background_image_url = Faker::LoremFlickr.image(size: '600x400')
profile_image_url = Faker::Avatar.image(slug: user_id, size: '48x48')
user = {
id: user_id,
id_str: user_id.to_s,
contributors_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
created_at: created_at,
default_profile_image: Faker::Boolean.boolean(true_ratio: 0.1),
default_profile: Faker::Boolean.boolean(true_ratio: 0.1),
description: Faker::Lorem.sentence,
entities: user_entities,
favourites_count: Faker::Number.between(to: 1, from: 100_000),
follow_request_sent: false,
followers_count: Faker::Number.between(to: 1, from: 10_000_000),
following: false,
friends_count: Faker::Number.between(to: 1, from: 100_000),
geo_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
is_translation_enabled: Faker::Boolean.boolean(true_ratio: 0.1),
is_translator: Faker::Boolean.boolean(true_ratio: 0.1),
lang: Faker::Address.country_code,
listed_count: Faker::Number.between(to: 1, from: 1000),
location: "#{Faker::Address.city}, #{Faker::Address.state_abbr}, #{Faker::Address.country_code}",
name: Faker::Name.name,
notifications: false,
profile_background_color: Faker::Color.hex_color,
profile_background_image_url_https: background_image_url,
profile_background_image_url: background_image_url.sub('https://', 'http://'),
profile_background_tile: Faker::Boolean.boolean(true_ratio: 0.1),
profile_banner_url: Faker::LoremFlickr.image(size: '1500x500'),
profile_image_url_https: profile_image_url,
profile_image_url: profile_image_url.sub('https://', 'http://'),
profile_link_color: Faker::Color.hex_color,
profile_sidebar_border_color: Faker::Color.hex_color,
profile_sidebar_fill_color: Faker::Color.hex_color,
profile_text_color: Faker::Color.hex_color,
profile_use_background_image: Faker::Boolean.boolean(true_ratio: 0.4),
protected: Faker::Boolean.boolean(true_ratio: 0.1),
screen_name: screen_name,
statuses_count: Faker::Number.between(to: 1, from: 100_000),
time_zone: Faker::Address.time_zone,
url: Faker::Internet.url(host: 'example.com'),
utc_offset: utc_offset,
verified: Faker::Boolean.boolean(true_ratio: 0.1)
}
user[:status] = Faker::Twitter.status(include_user: false) if include_status
user[:email] = Faker::Internet.email if include_email
user
end

##
# Produces a random Twitter user.
#
# @param include_user [Boolean] Include or exclude user details
# @param include_photo [Boolean] Include or exclude user photo
# @return [Hash]
#
# @example
# Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
# Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
# Faker::Twitter.status(include_photo: true) # Includes entities for an attached image
#
# @faker.version 1.7.3
def status(include_user: true, include_photo: false)
warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead. Some return attributes \
will be removed, check the docs for more details.')

status_id = id
status = {
id: status_id,
id_str: status_id.to_s,
contributors: nil,
coordinates: nil,
created_at: created_at,
entities: status_entities(include_photo: include_photo),
favorite_count: Faker::Number.between(to: 1, from: 10_000),
favorited: false,
geo: nil,
in_reply_to_screen_name: nil,
in_reply_to_status_id: nil,
in_reply_to_user_id_str: nil,
in_reply_to_user_id: nil,
is_quote_status: false,
lang: Faker::Address.country_code,
nil: nil,
place: nil,
possibly_sensitive: Faker::Boolean.boolean(true_ratio: 0.1),
retweet_count: Faker::Number.between(to: 1, from: 10_000),
retweeted_status: nil,
retweeted: false,
source: "<a href=\"#{Faker::Internet.url(host: 'example.com')}\" rel=\"nofollow\">#{Faker::Company.name}</a>",
text: Faker::Lorem.sentence,
truncated: false
}
status[:user] = Faker::Twitter.user(include_status: false) if include_user
status[:text] = "#{status[:text]} #{status[:entities][:media].first[:url]}" if include_photo
status
end

##
# Produces a random screen name.
#
# @return [String]
#
# @example
# Faker::Twitter.screen_name #=> "audreanne_hackett"
#
# @faker.version 1.7.3
def screen_name
warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead.')

Faker::Internet.username(specifier: nil, separators: ['_'])[0...20]
end

private

def id
Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807)
end

def created_at
Faker::Date.between(from: '2006-03-21', to: ::Date.today).strftime('%a %b %d %H:%M:%S %z %Y')
end

def utc_offset
Faker::Number.between(to: -43_200, from: 50_400)
end

def user_entities
{
url: {
urls: []
},
description: {
urls: []
}
}
end

def status_entities(include_photo: false)
entities = {
hashtags: [],
symbols: [],
user_mentions: [],
urls: []
}
entities[:media] = [photo_entity] if include_photo
entities
end

def photo_entity
media_url = Faker::LoremFlickr.image(size: '1064x600')
media_id = id
{
id: media_id,
id_str: media_id.to_s,
indices: [
103,
126
],
media_url: media_url.sub('https://', 'http://'),
media_url_https: media_url,
url: Faker::Internet.url(host: 'example.com'),
display_url: 'example.com',
expanded_url: Faker::Internet.url(host: 'example.com'),
type: 'photo',
sizes: {
medium: {
w: 1064,
h: 600,
resize: 'fit'
},
large: {
w: 1064,
h: 600,
resize: 'fit'
},
small: {
w: 680,
h: 383,
resize: 'fit'
},
thumb: {
w: 150,
h: 150,
resize: 'crop'
}
}
}
end
end
end

class X < Base
class << self
##
Expand Down
4 changes: 0 additions & 4 deletions lib/faker/music/bossa_nova.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ def song
end
end
end

include Faker::Deprecator

deprecate_generator('BossaNova', Music::BossaNova)
end
63 changes: 0 additions & 63 deletions test/faker/default/test_twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,6 @@

require_relative '../../test_helper'

class TestFakerTwitter < Test::Unit::TestCase
def setup
@tester = Faker::Twitter
end

def test_user
user = @tester.user

assert_kind_of Hash, user
assert_equal(41, user.keys.count)
assert_kind_of Hash, user[:status]
assert_nil user[:status][:user]
end

def test_user_with_email
user = @tester.user(include_email: true)

assert_kind_of Hash, user
assert_equal(42, user.keys.count)
assert_kind_of String, user[:email]
end

def test_user_without_status
user = @tester.user(include_status: false)

assert_kind_of Hash, user
assert_equal(40, user.keys.count)
assert_nil user[:status]
end

def test_status
status = @tester.status

assert_kind_of Hash, status
assert_equal(25, status.keys.count)
assert_kind_of Hash, status[:entities]
assert_kind_of Hash, status[:user]
assert_nil status[:user][:status]
end

def test_status_without_user
status = @tester.status(include_user: false)

assert_kind_of Hash, status
assert_equal(24, status.keys.count)
assert_nil status[:user]
end

def test_status_with_photo
status = @tester.status(include_photo: true)

assert_kind_of Hash, status
assert_equal(25, status.keys.count)
assert_kind_of Hash, status[:entities]
assert_equal(1, status[:entities][:media].count)
assert_equal(10, status[:entities][:media].first.keys.count)
end

def test_screen_name
assert_kind_of String, @tester.screen_name
end
end

class TestFakerX < Test::Unit::TestCase
def setup
@tester = Faker::X
Expand Down
13 changes: 0 additions & 13 deletions test/faker/music/test_faker_bossa_nova.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,4 @@ def test_artists
def test_songs
assert_match(/\w+/, @tester.song)
end

def test_deprecation
assert_deprecated do
Faker::BossaNova.artist
end

assert_deprecated do
Faker::BossaNova.song
end

assert_match(/\w+/, Faker::BossaNova.artist)
assert_match(/\w+/, Faker::BossaNova.song)
end
end